Пример #1
0
 def test_device_middleman(self):
     device = Device(device_id="95",
                     central_server_id="99",
                     nodes=["98"],
                     middlemen=["95"])
     self.assertTrue(device.device_role == MIDDLEMAN)
     self.assertTrue(device.is_middleman_server)
Пример #2
0
 def test_device_client2(self):
     device = Device(device_id="10",
                     central_server_id="99",
                     nodes=["98"],
                     middlemen=["95"])
     self.assertTrue(device.device_role == CLIENT)
     self.assertTrue(device.is_client)
Пример #3
0
 def test_device_central_server_or_defaults_to_central(self):
     """Asserts all permutations between settings and app_config
     assuming default is central.
     """
     opts_settings = [
         ("99", CENTRAL_SERVER),
         ("99", None),
         (None, CENTRAL_SERVER),
         (None, None),
     ]
     opts_config = [
         ("99", CENTRAL_SERVER),
         ("99", None),
         (None, CENTRAL_SERVER),
         (None, None),
     ]
     for DEVICE_ID, DEVICE_ROLE in opts_settings:
         with self.subTest(DEVICE_ID=DEVICE_ID, DEVICE_ROLE=DEVICE_ROLE):
             with override_settings(DEVICE_ID=DEVICE_ID,
                                    DEVICE_ROLE=DEVICE_ROLE):
                 for device_id, device_role in opts_config:
                     with self.subTest(device_id=device_id,
                                       device_role=device_role):
                         device = Device(device_id=device_id,
                                         device_role=device_role)
                         self.assertTrue(
                             device.device_role == CENTRAL_SERVER)
                         self.assertTrue(device.is_central_server)
Пример #4
0
 def test_device_client(self):
     device = Device(device_id="33", central_server_id="99")
     self.assertTrue(device.device_role == CLIENT)
     self.assertTrue(device.is_client)
     self.assertFalse(device.is_server)
     self.assertFalse(device.is_central_server)
     self.assertFalse(device.is_node_server)
     self.assertFalse(device.is_middleman_server)
Пример #5
0
 def save(self, *args, **kwargs):
     if self.is_consumed_server and not self.consumed_datetime:
         self.consumed_datetime = datetime.today()
     if not Device().is_middleman:
         raise TypeError(
             '\'{0}\' is not configured to be a MiddleMan, so you cannot '
             'save MiddleMan transanctions here.'.format(
                 settings.DEVICE_ID))
     super(MiddleManTransaction, self).save(*args, **kwargs)
Пример #6
0
 def test_device_node_server(self):
     device = Device(device_id="98", central_server_id="99", nodes=["98"])
     self.assertTrue(device.device_role == NODE_SERVER)
     self.assertTrue(device.is_node_server)
Пример #7
0
 def test_device_central_server_from_settings_only(self):
     with override_settings(DEVICE_ID="98"):
         device = Device(device_id=None, central_server="99", nodes=["98"])
     self.assertEqual(device.device_id, "98")
     self.assertTrue(device.is_node_server)
Пример #8
0
 def test_device_central_server_from_settings_raises(self):
     with override_settings(DEVICE_ID="98"):
         with self.assertRaises(DeviceIdError) as cm:
             Device(device_id="99", central_server_id="99")
         self.assertEqual(cm.exception.code, "device_id_conflict")
Пример #9
0
 def test_device_from_settings_only(self):
     with override_settings(DEVICE_ID="10", DEVICE_ROLE=CLIENT):
         device = Device()
     self.assertEqual(device.device_id, "10")
     self.assertEqual(device.device_role, CLIENT)