File: test_ttl.py

package info (click to toggle)
dnspython 2.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,448 kB
  • sloc: python: 34,885; sh: 7; makefile: 4
file content (44 lines) | stat: -rw-r--r-- 1,395 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license

import unittest

import dns.ttl


class TTLTestCase(unittest.TestCase):
    def test_bind_style_ok(self):
        ttl = dns.ttl.from_text("2w1d1h1m1s")
        self.assertEqual(ttl, 2 * 604800 + 86400 + 3600 + 60 + 1)

    def test_bind_style_ok2(self):
        # no one should do this, but it is legal! :)
        ttl = dns.ttl.from_text("1s2w1m1d1h")
        self.assertEqual(ttl, 2 * 604800 + 86400 + 3600 + 60 + 1)

    def test_bind_style_bad_unit(self):
        with self.assertRaises(dns.ttl.BadTTL):
            dns.ttl.from_text("5y")

    def test_bind_style_no_unit(self):
        with self.assertRaises(dns.ttl.BadTTL):
            dns.ttl.from_text("1d5")

    def test_bind_style_leading_unit(self):
        with self.assertRaises(dns.ttl.BadTTL):
            dns.ttl.from_text("s")

    def test_bind_style_unit_without_digits(self):
        with self.assertRaises(dns.ttl.BadTTL):
            dns.ttl.from_text("1mw")

    def test_ttl_technically_too_big_but_tolerated(self):
        ttl = dns.ttl.from_text("4294967295")
        assert ttl == 4294967295

    def test_ttl_technically_too_big(self):
        with self.assertRaises(dns.ttl.BadTTL):
            dns.ttl.from_text("4294967296")

    def test_empty(self):
        with self.assertRaises(dns.ttl.BadTTL):
            dns.ttl.from_text("")