def test_add_geofence_success(self): policy = AuthPolicy() latitude = MagicMock(spec=int) longitude = MagicMock(spec=int) radius = MagicMock(spec=int) policy.add_geofence(latitude, longitude, radius) retrieved = policy.get_policy() self.assertEqual(len(retrieved['factors']), 2) factor = retrieved['factors'][1] if retrieved['factors'][1][ 'factor'] == 'geofence' else retrieved['factors'][0] self.assertEqual(factor['factor'], 'geofence') self.assertEqual(len(factor['attributes']['locations']), 1) location = factor['attributes']['locations'][0] self.assertEqual(location['latitude'], float(latitude)) self.assertEqual(location['longitude'], float(longitude)) self.assertEqual(location['radius'], float(radius)) # Add a second geofence latitude2 = MagicMock(spec=int) longitude2 = MagicMock(spec=int) radius2 = MagicMock(spec=int) policy.add_geofence(latitude2, longitude2, radius2) retrieved = policy.get_policy() self.assertEqual(len(retrieved['factors']), 2) factor = retrieved['factors'][1] if retrieved['factors'][1][ 'factor'] == 'geofence' else retrieved['factors'][0] self.assertEqual(factor['factor'], 'geofence') self.assertEqual(len(factor['attributes']['locations']), 2) location = factor['attributes']['locations'][1] self.assertEqual(location['latitude'], float(latitude2)) self.assertEqual(location['longitude'], float(longitude2)) self.assertEqual(location['radius'], float(radius2))
def test_eq_mismatch(self): policy = AuthPolicy() policy.add_geofence(1, 2, 3, '123') policy2 = AuthPolicy() self.assertNotEqual(policy, policy2) policy2.add_geofence(1, 2, 2, '122') self.assertNotEqual(policy, policy2)
def test_add_geofence_success(self): policy = AuthPolicy() latitude = MagicMock(spec=int) longitude = MagicMock(spec=int) radius = MagicMock(spec=int) policy.add_geofence(latitude, longitude, radius) retrieved = policy.get_policy() self.assertEqual(len(retrieved['factors']), 2) factor = retrieved['factors'][1] if retrieved['factors'][1]['factor'] == 'geofence' else retrieved['factors'][0] self.assertEqual(factor['factor'], 'geofence') self.assertEqual(len(factor['attributes']['locations']), 1) location = factor['attributes']['locations'][0] self.assertEqual(location['latitude'], float(latitude)) self.assertEqual(location['longitude'], float(longitude)) self.assertEqual(location['radius'], float(radius)) # Add a second geofence latitude2 = MagicMock(spec=int) longitude2 = MagicMock(spec=int) radius2 = MagicMock(spec=int) policy.add_geofence(latitude2, longitude2, radius2) retrieved = policy.get_policy() self.assertEqual(len(retrieved['factors']), 2) factor = retrieved['factors'][1] if retrieved['factors'][1]['factor'] == 'geofence' else retrieved['factors'][0] self.assertEqual(factor['factor'], 'geofence') self.assertEqual(len(factor['attributes']['locations']), 2) location = factor['attributes']['locations'][1] self.assertEqual(location['latitude'], float(latitude2)) self.assertEqual(location['longitude'], float(longitude2)) self.assertEqual(location['radius'], float(radius2))
def test_eq_mismatch(self): policy = AuthPolicy() policy.add_geofence(1, 2, 3, '123') policy2 = AuthPolicy() self.assertNotEqual(policy, policy2) policy2.add_geofence(1, 2, 2, '122') self.assertFalse(policy == policy2)
def test_remove_geofence(self, name): policy = AuthPolicy() retrieved = policy.get_policy() self.assertEqual(len(retrieved['factors']), 1) self.assertEqual(policy.geofences, []) policy.add_geofence(MagicMock(spec=int), MagicMock(spec=int), MagicMock(spec=int), name) self.assertEqual(len(policy.geofences), 1) retrieved = policy.get_policy() self.assertEqual(len(retrieved['factors']), 2) self.assertEqual(len(retrieved['factors'][1]['attributes']['locations']), 1) policy.remove_geofence(name) self.assertEqual(policy.geofences, []) retrieved = policy.get_policy() self.assertEqual(len(retrieved['factors'][1]['attributes']['locations']), 0)
def test_remove_geofence(self, name): policy = AuthPolicy() retrieved = policy.get_policy() self.assertEqual(len(retrieved['factors']), 1) self.assertEqual(policy.geofences, []) policy.add_geofence(MagicMock(spec=int), MagicMock(spec=int), MagicMock(spec=int), name) self.assertEqual(len(policy.geofences), 1) retrieved = policy.get_policy() self.assertEqual(len(retrieved['factors']), 2) self.assertEqual( len(retrieved['factors'][1]['attributes']['locations']), 1) policy.remove_geofence(name) self.assertEqual(policy.geofences, []) retrieved = policy.get_policy() self.assertEqual( len(retrieved['factors'][1]['attributes']['locations']), 0)
def test_eq_match(self): policy = AuthPolicy() policy.add_geofence(1, 2, 3, '123') policy2 = AuthPolicy() policy2.set_policy(policy.get_policy()) self.assertEqual(policy, policy2)
def test_remove_invalid_geofence(self): policy = AuthPolicy() policy.add_geofence(1, 1, 2) with self.assertRaises(InvalidGeoFenceName): policy.remove_geofence(MagicMock(spec=str))
def test_add_geofence_invalid_input(self): policy = AuthPolicy() with self.assertRaises(InvalidParameters): policy.add_geofence(ANY, ANY, ANY)
def test_remove_partially_invalid_geofence(self): policy = AuthPolicy() policy.add_geofence(1, 1, 2, 'name') policy.geofences.pop() with self.assertRaises(InvalidGeoFenceName): policy.remove_geofence('name')
def test_add_geofence_invalid_radius_input(self, value): policy = AuthPolicy() with self.assertRaises(InvalidParameters): policy.add_geofence(0, 0, value)
def test_eq_match(self): policy = AuthPolicy() policy.add_geofence(1, 2, 3, '123') policy2 = AuthPolicy() policy2.set_policy(policy.get_policy()) self.assertTrue(policy == policy2)