Ejemplo n.º 1
0
 def test_populates_on_demand(self):
     value = factory.make_name("value")
     value_dict = lazydict(lambda key: value)
     key = factory.make_name("key")
     retrieved_value = value_dict[key]
     self.assertEqual(value, retrieved_value)
     self.assertEqual({key: value}, value_dict)
Ejemplo n.º 2
0
    def test_holds_one_value_per_key(self):
        value_dict = lazydict(lambda key: key)
        key1 = factory.make_name("key")
        key2 = factory.make_name("key")

        value1 = value_dict[key1]
        value2 = value_dict[key2]

        self.assertEqual((key1, key2), (value1, value2))
        self.assertEqual({key1: key1, key2: key2}, value_dict)
Ejemplo n.º 3
0
 def test_add_delegations_allows_dots(self):
     parent = factory.make_Domain()
     name = "%s.%s" % (factory.make_name(), factory.make_name())
     factory.make_Domain(name="%s.%s" % (name, parent.name))
     default_name = Domain.objects.get_default_domain().name
     mappings = lazydict(get_hostname_dnsdata_mapping)
     mapping = mappings[parent]
     parent.add_delegations(mapping, default_name, [IPAddress("::1")], 30)
     expected_map = HostnameRRsetMapping(rrset={(30, 'NS', default_name)})
     self.assertEqual(expected_map, mapping[name])
Ejemplo n.º 4
0
 def test_add_delegations_does_not_list_region_for_non_auth(self):
     parent = factory.make_Domain()
     name = factory.make_name()
     child = factory.make_Domain(
         name="%s.%s" % (name, parent.name), authoritative=False)
     default_name = Domain.objects.get_default_domain().name
     ns_name = "%s.%s." % (factory.make_name('h'), factory.make_name('d'))
     factory.make_DNSData(
         name='@', domain=child, rrtype='NS', rrdata=ns_name)
     mappings = lazydict(get_hostname_dnsdata_mapping)
     mapping = mappings[parent]
     parent.add_delegations(mapping, default_name, [IPAddress("::1")], 30)
     expected_map = HostnameRRsetMapping(
         rrset={(30, 'NS', ns_name)})
     self.assertEqual(expected_map, mapping[name])
Ejemplo n.º 5
0
 def test_add_delegations_adds_nsrrset_and_glue_in_depth(self):
     parent = factory.make_Domain()
     name = factory.make_name()
     child = factory.make_Domain(name="%s.%s" % (name, parent.name))
     default_name = Domain.objects.get_default_domain().name
     g_name = factory.make_name()
     grandchild = factory.make_Domain(name="%s.%s" % (g_name, child.name))
     dnsrr = factory.make_DNSResource(name="@", domain=child)
     nsname = factory.make_name()
     factory.make_DNSData(
         dnsresource=dnsrr,
         rrtype="NS",
         rrdata="%s.%s." % (nsname, grandchild.name),
     )
     nsrr = factory.make_DNSResource(name=nsname, domain=grandchild)
     other_name = factory.make_name()
     factory.make_DNSResource(name=other_name, domain=parent)
     factory.make_DNSData(
         dnsresource=dnsrr,
         rrtype="NS",
         rrdata="%s.%s." % (other_name, parent.name),
     )
     mappings = lazydict(get_hostname_dnsdata_mapping)
     mapping = mappings[parent]
     expected_map = {
         name: HostnameRRsetMapping(
             rrset={
                 (30, "NS", default_name),
                 (30, "NS", "%s.%s." % (nsname, grandchild.name)),
                 (30, "NS", "%s.%s." % (other_name, parent.name)),
             }
         )
     }
     ns_part = "%s.%s" % (nsname, g_name)
     for sip in nsrr.ip_addresses.all():
         if IPAddress(sip.ip).version == 6:
             expected_map[ns_part] = HostnameRRsetMapping(
                 rrset={(30, "AAAA", sip.ip)}
             )
         else:
             expected_map[ns_part] = HostnameRRsetMapping(
                 rrset={(30, "A", sip.ip)}
             )
     parent.add_delegations(mapping, default_name, [IPAddress("::1")], 30)
     self.assertEqual(expected_map, mapping)
Ejemplo n.º 6
0
 def test_add_delegations_adds_nsrrset_and_glue(self):
     parent = factory.make_Domain()
     name = factory.make_name()
     child = factory.make_Domain(name="%s.%s" % (name, parent.name))
     default_name = Domain.objects.get_default_domain().name
     dnsrr = factory.make_DNSResource(name='@', domain=child)
     nsname = factory.make_name()
     factory.make_DNSData(dnsresource=dnsrr,
                          rrtype='NS',
                          rrdata="%s.%s." % (nsname, child.name))
     nsrr = factory.make_DNSResource(name=nsname, domain=child)
     other_name = factory.make_name()
     factory.make_DNSResource(name=other_name, domain=parent)
     factory.make_DNSData(dnsresource=dnsrr,
                          rrtype='NS',
                          rrdata="%s.%s." % (other_name, parent.name))
     mappings = lazydict(get_hostname_dnsdata_mapping)
     mapping = mappings[parent]
     parent.add_delegations(mapping, default_name, [IPAddress("::1")], 30)
     expected_map = {
         name:
         HostnameRRsetMapping(
             rrset={
                 (30, 'NS', default_name),
                 (30, 'NS', "%s.%s." % (nsname, child.name)),
                 (30, 'NS', "%s.%s." % (other_name, parent.name)),
             }),
     }
     for sip in nsrr.ip_addresses.all():
         if IPAddress(sip.ip).version == 6:
             expected_map[nsname] = HostnameRRsetMapping(rrset={(30, 'AAAA',
                                                                 sip.ip)})
         else:
             expected_map[nsname] = HostnameRRsetMapping(rrset={(30, 'A',
                                                                 sip.ip)})
     self.assertEqual(expected_map, mapping)
Ejemplo n.º 7
0
 def test_remembers_elements(self):
     value_dict = lazydict(lambda key: factory.make_name("value"))
     key = factory.make_name("key")
     self.assertEqual(value_dict[key], value_dict[key])
Ejemplo n.º 8
0
 def test_empty_initially(self):
     self.assertEqual({}, lazydict(Mock()))