| 1 |
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license |
| 2 |
|
| 3 |
import unittest |
| 4 |
|
| 5 |
import dns.ttl |
| 6 |
|
| 7 |
|
| 8 |
class TTLTestCase(unittest.TestCase): |
| 9 |
def test_bind_style_ok(self): |
| 10 |
ttl = dns.ttl.from_text("2w1d1h1m1s") |
| 11 |
self.assertEqual(ttl, 2 * 604800 + 86400 + 3600 + 60 + 1) |
| 12 |
|
| 13 |
def test_bind_style_ok2(self): |
| 14 |
# no one should do this, but it is legal! :) |
| 15 |
ttl = dns.ttl.from_text("1s2w1m1d1h") |
| 16 |
self.assertEqual(ttl, 2 * 604800 + 86400 + 3600 + 60 + 1) |
| 17 |
|
| 18 |
def test_bind_style_bad_unit(self): |
| 19 |
with self.assertRaises(dns.ttl.BadTTL): |
| 20 |
dns.ttl.from_text("5y") |
| 21 |
|
| 22 |
def test_bind_style_no_unit(self): |
| 23 |
with self.assertRaises(dns.ttl.BadTTL): |
| 24 |
dns.ttl.from_text("1d5") |
| 25 |
|
| 26 |
def test_bind_style_leading_unit(self): |
| 27 |
with self.assertRaises(dns.ttl.BadTTL): |
| 28 |
dns.ttl.from_text("s") |
| 29 |
|
| 30 |
def test_bind_style_unit_without_digits(self): |
| 31 |
with self.assertRaises(dns.ttl.BadTTL): |
| 32 |
dns.ttl.from_text("1mw") |
| 33 |
|
| 34 |
def test_ttl_technically_too_big_but_tolerated(self): |
| 35 |
ttl = dns.ttl.from_text("4294967295") |
| 36 |
assert ttl == 4294967295 |
| 37 |
|
| 38 |
def test_ttl_technically_too_big(self): |
| 39 |
with self.assertRaises(dns.ttl.BadTTL): |
| 40 |
dns.ttl.from_text("4294967296") |
| 41 |
|
| 42 |
def test_empty(self): |
| 43 |
with self.assertRaises(dns.ttl.BadTTL): |
| 44 |
dns.ttl.from_text("") |