Esempio n. 1
0
class EthernetTest(RalphTestCase):
    def setUp(self):
        self.ip1 = IPAddressFactory()
        self.eth1 = EthernetFactory()

    def test_clear_mac_address_without_ip_should_pass(self):
        self.eth1.mac = None
        self.eth1.clean()
        self.eth1.save()

    def test_clear_mac_address_with_ip_without_dhcp_exposition_should_pass(
            self):  # noqa
        self.ip1.ethernet.mac = None
        self.ip1.ethernet.clean()
        self.ip1.ethernet.save()

    def test_clear_mac_address_with_ip_with_dhcp_exposition_should_not_pass(
            self):  # noqa
        self.ip1.dhcp_expose = True
        self.ip1.save()
        self.ip1.ethernet.mac = None
        with self.assertRaises(
                ValidationError,
                msg='MAC cannot be empty if record is exposed in DHCP'):
            self.ip1.ethernet.clean()

    def test_change_mac_address_with_ip_with_dhcp_exposition_should_not_pass(
            self):  # noqa
        self.ip1.dhcp_expose = True
        self.ip1.save()
        self.ip1.ethernet.mac = '11:12:13:14:15:16'
        with self.assertRaises(ValidationError,
                               msg='Cannot change MAC when exposing in DHCP'):
            self.ip1.ethernet.clean()
Esempio n. 2
0
 def test_get_last_modified_should_return_ethernet_modified(self):
     network = NetworkFactory(address='192.168.1.0/24')
     ethernet = EthernetFactory()
     ip = IPAddressFactory(address='192.168.1.2', ethernet=ethernet)
     ethernet.save()
     returned = self.view.get_last_modified(
         Network.objects.filter(id__in=[network.id]))
     self.assertEqual(returned.strftime("%Y-%m-%d %H:%M:%S"),
                      ethernet.modified.strftime("%Y-%m-%d %H:%M:%S"))
Esempio n. 3
0
 def test_filter_duplicated_hostnames(self):
     network = NetworkFactory(address='192.168.1.0/24')
     asset = DataCenterAssetFactory()
     ethernet = EthernetFactory(base_object=asset)
     ethernet.save()
     IPAddressFactory(hostname='host1.mydc.net',
                      address='192.168.1.2',
                      ethernet=ethernet,
                      dhcp_expose=True)
     ethernet2 = EthernetFactory()
     ethernet2.save()
     IPAddressFactory(hostname='host1.mydc.net',
                      address='192.168.1.3',
                      ethernet=ethernet2,
                      dhcp_expose=True)
     ethernet3 = EthernetFactory()
     ethernet3.save()
     ip = IPAddressFactory(hostname='host2.mydc.net',
                           address='192.168.1.4',
                           ethernet=ethernet3,
                           dhcp_expose=True)
     entries = self.view._get_dhcp_entries(
         Network.objects.filter(id__in=[network.id]))
     self.assertEqual(DHCPEntry.objects.count(), 3)
     self.assertEqual(len(entries), 1)
     self.assertEqual(entries[0].pk, ip.pk)