Esempio n. 1
0
    def test_get_device(self):
        """Test that adding and then getting a device works."""

        add_room('bedroom', "Jake's Bedroom")

        device = {
            'identifier': 'test',
            'name': 'Test',
            'device_type': 'switch',
            'depends_on': None,
            'controller_name': 'controller-1',
            'room': {
                'identifier': 'bedroom',
                'name': "Jake's Bedroom",
            },
            'state_providers': None,
        }

        # Add the device to the registry
        add_device(device['identifier'], device['name'], device['device_type'],
                   device['controller_name'], device['room']['identifier'])

        # Ask the registry for the device's details
        response = self.app.get('/device/test')

        # Assert that we got an OK response code
        self.assertEqual(200, response.status_code)

        # Decode the json
        decoded_response = decode_response(response)

        self.assertEqual(device, decoded_response)
Esempio n. 2
0
    def setUp(self):
        # Create an instance of the test client
        self.app = app.test_client()

        # Use a temporary file as the database file
        app.config['DATABASE'] = '/tmp/test'

        add_room('room', 'Room')
    def test_add_duplicate_room(self):
        """Test that adding a room with an identifier that is already used replaces the room."""

        # Add the same room twice
        add_room('room1', "room")
        response = add_room('room1', "room new")

        # Assert that we get a 201 response code the second time
        self.assertEqual(201, response.status_code)

        response = self.app.get('/room/room1')
        decoded_response = decode_response(response)

        self.assertEqual('room new', decoded_response['name'])
Esempio n. 4
0
    def test_get_room(self):
        """Test that getting a room with devices works."""

        device1 = {
            'identifier': 'device1',
            'name': 'Test Device 1',
            'device_type': 'switch',
            'depends_on': None,
            'controller_name': 'controller-1',
            'state_providers': None,
        }

        device2 = {
            'identifier': 'device2',
            'name': 'Test Device 2',
            'device_type': 'switch',
            'depends_on': None,
            'controller_name': 'controller-1',
            'state_providers': None,
        }

        room = {
            'identifier': 'bedroom',
            'name': "Jake's Bedroom",
            'devices': [device1, device2],
        }

        add_room(room['identifier'], room['name'])
        add_device(
            device1['identifier'],
            device1['name'],
            device1['device_type'],
            device1['controller_name'],
            room['identifier'],
        )

        add_device(
            device2['identifier'],
            device2['name'],
            device2['device_type'],
            device2['controller_name'],
            room['identifier'],
        )

        response = self.app.get('/room/bedroom')
        decoded_response = decode_response(response)

        self.assertEqual(room, decoded_response)
Esempio n. 5
0
    def test_delete_room(self):
        """Test that a room is not longer available after deleting it."""

        # Add a room
        add_room('test-del', 'name')

        # Try to get the room
        response = self.app.get('/room/test-del')
        self.assertEqual(200, response.status_code)

        # Delete the room
        response = self.app.delete('/room/test-del')
        self.assertEqual(204, response.status_code)

        # Try to get the room again
        response = self.app.get('/room/test-del')
        self.assertEqual(404, response.status_code)

        # Try to delete the room again
        response = self.app.delete('/room/test-del')
        self.assertEqual(404, response.status_code)
Esempio n. 6
0
    def test_delete_device(self):
        """Test that a device is no longer available after deleting it"""

        # Add a device
        add_room('bedroom', "Jake's Bedroom")
        add_device('test-del', 'name', 'type', 'controller', 'bedroom')

        # Try to get the device
        response = self.app.get('/device/test-del')
        self.assertEqual(200, response.status_code)

        # Delete the device
        response = self.app.delete('/device/test-del')
        self.assertEqual(204, response.status_code)

        # Try to get the device again
        response = self.app.get('/device/test-del')
        self.assertEqual(404, response.status_code)

        # Try to delete the device again
        response = self.app.delete('/device/test-del')
        self.assertEqual(404, response.status_code)
    def test_add_room(self):
        """Test that a new room can be added to the registry."""

        room = {
            'identifier': 'bedroom',
            'name': "Jake's Bedroom",
            'devices': [],
        }

        # Add a new room and get the response
        response = add_room(room['identifier'], room['name'])
        decoded_response = decode_response(response)

        self.assertEqual(201, response.status_code)
        self.assertEqual(room, decoded_response)