Exemplo n.º 1
0
 def test_download_process(self):
     full = Policy.objects.get(name = "full")
     blocked = Policy.objects.get(name = 'blocked')
     self.device_1.policy = full
     self.device_1.save()
     self.device_2.policy = full
     self.device_2.save()
     self.device_3.policy = blocked
     self.device_3.save()
     self.device_4.policy = blocked
     self.device_4.save()
     response = iptables_download({})
     response_dict = json.loads(response._get_content()[5:])
     allowed_expected = [
                      {"mac_address": "58:94:6B:A4:DA:BC", "ip_address": "192.168.10.2"},
                      {"mac_address": "48:5B:39:F8:5D:F9", "ip_address": "192.168.10.3"},
                    ]
     blocked_expected = [
                      {"mac_address": "58:94:6B:A4:D7:BC", "ip_address": "192.168.10.4"},
                      {"mac_address": "8C:58:77:02:8E:5D", "ip_address": "192.168.11.125"},
                    ]
     for item in allowed_expected:
         self.assertIn(item, response_dict['allowed'])
     for item in blocked_expected:
         self.assertIn(item, response_dict['blocked'])
Exemplo n.º 2
0
    def test_enable_device(self):
        response = iptables_download({})
        response_dict = json.loads(response._get_content()[5:])

        expected_blocked = [{u'ip_address': u'192.168.10.4',
               u'mac_address': u'58:94:6B:A4:D7:BC'},
              {u'ip_address': u'192.168.11.125',
               u'mac_address': u'8C:58:77:02:8E:5D'}]
        self.assertEqual(expected_blocked, response_dict['blocked'])

        request = Mock()
        request.POST = { "mac_address": '58:94:6b:a4:da:bc', "duration": 30 }
        request.method = "POST"
        response = enable_device(request)
        response_dict = json.loads(response._get_content()[5:])
        self.assertEqual(response_dict['success'], True)
        self.assertEqual(response_dict['message'], 'Saved')