Ejemplo n.º 1
0
class ProximityClientTestCase(TestCase):

    def setUp(self):
        self.old_setting = settings.PROXIMITY_SERVER['default']
        settings.PROXIMITY_SERVER['default'] = settings.PROXIMITY_SERVER['test']
        self.proximity_client = ProximityClient()
        self.proximity_client.flush()

    def tearDown(self):
        settings.PROXIMITY_SERVER['default'] = self.old_setting
    
    def test_good_add_set_get_flush(self):
        self.proximity_client.add_device('aa:aa:aa:aa:aa:aa')
        group = self.proximity_client.get_group('aa:aa:aa:aa:aa:aa')
        self.assertEqual(group, [])
        
        self.proximity_client.add_device('bb:bb:bb:bb:bb:bb')
        group = self.proximity_client.get_group('aa:aa:aa:aa:aa:aa')
        self.assertEqual(group, [])
        
        self.proximity_client.add_device('cc:cc:cc:cc:cc:cc')
        group = self.proximity_client.get_group('cc:cc:cc:cc:cc:cc')
        self.assertEqual(group, [])
        
        
        self.proximity_client.set_group('aa:aa:aa:aa:aa:aa', ['bb:bb:bb:bb:bb:bb'])
        group = self.proximity_client.get_group('aa:aa:aa:aa:aa:aa')
        self.assertEqual(group, ['bb:bb:bb:bb:bb:bb'])
        group = self.proximity_client.get_group('bb:bb:bb:bb:bb:bb')
        self.assertEqual(group, ['aa:aa:aa:aa:aa:aa'])
        group = self.proximity_client.get_group('cc:cc:cc:cc:cc:cc')
        self.assertEqual(group, [])
        
        self.proximity_client.set_group('cc:cc:cc:cc:cc:cc', ['bb:bb:bb:bb:bb:bb'])
        group = self.proximity_client.get_group('aa:aa:aa:aa:aa:aa')
        self.assertEqual(group, ['bb:bb:bb:bb:bb:bb', 'cc:cc:cc:cc:cc:cc'])
        group = self.proximity_client.get_group('bb:bb:bb:bb:bb:bb')
        self.assertEqual(group, ['aa:aa:aa:aa:aa:aa', 'cc:cc:cc:cc:cc:cc'])
        group = self.proximity_client.get_group('cc:cc:cc:cc:cc:cc')
        self.assertEqual(group, ['aa:aa:aa:aa:aa:aa', 'bb:bb:bb:bb:bb:bb'])
        
        self.proximity_client.flush()
        group = self.proximity_client.get_group('aa:aa:aa:aa:aa:aa')
        self.assertEqual(group, [])
        group = self.proximity_client.get_group('bb:bb:bb:bb:bb:bb')
        self.assertEqual(group, [])
        group = self.proximity_client.get_group('cc:cc:cc:cc:cc:cc')
        self.assertEqual(group, [])
        
Ejemplo n.º 2
0
    def set_proximity_devices(self, neighbours):
        """Set the proximity devices of the device.

        This method sets the proximity devices, i.e., the neighbouring
        devices as it's proximity devices.

        Args:
            * neighbours: A list of mac_addresses as strings, e.g.,
              ['aa:aa:aa:aa:aa:aa', 'bb:bb:bb:bb:bb:bb']

        """
        client = ProximityClient()
        try:
            client.set_group(self.mac_address, neighbours)
        except ProximityClientConnectionError, e:
            logger.error(e)
            event_handler.add_event(e)