def test_marshalling_and_unmarshalling_gateways(): nose.assert_equal(fixtures.raw_gateway_data(), map(util.deep_asdict, fixtures.stub_gateways())) nose.assert_equal(fixtures.stub_gateways(), map(json_marshalling.unmarshall_gateway, fixtures.raw_gateway_data()))
def test_all(): db = mock.MagicMock() repo = dal.GatewayRepository(db) gateways = fixtures.stub_gateways() repo.insert(gateways) db["gateways"].insert.assert_called_once_with(mock.ANY)
def _empty_recording(i): return domain.Recording( id=None, status=None, gateways=fixtures.stub_gateways(), end_time=None, start_time=i)
def test_retrieving_list_of_attached_gateways(): gateways = fixtures.stub_gateways() system_control_service = mock.Mock() system_control_service.attached_gateways.return_value = gateways app = api.app_factory(system_control_service).test_client() response = app.get('/system-control/attached-devices') nose.assert_equal(200, response.status_code) data = json.loads(response.data) nose.assert_equal(2, len(data['gateways'])) nose.assert_equal(len(data['gateways'][0]['devices']), 2) nose.assert_equal(len(data['gateways'][1]['devices']), 3)
def test_create(): def add_id_to_dict(d): d['_id'] = 'abcdefg' db = mock.MagicMock() db['recordings'].insert.side_effect = add_id_to_dict repo = dal.RecordingsRepository(db) recording = domain.Recording( id=None, status='running', gateways=fixtures.stub_gateways(), start_time=time.time(), end_time=None) updated_value = repo.create(recording) db['recordings'].insert.assert_called_once_with(mock.ANY) db.create_collection.assert_called_once_with('archive-abcdefg') nose.assert_equal(updated_value.id, 'abcdefg')
def test_updating_list_of_attached_gateways(): gateways = fixtures.stub_gateways() json_data = """\ [ { "host": "127.0.0.1", "port": 5020, "label": "Gateway 1", "devices": [ { "unit": 1, "label": null, "type": "diris.a40" }, { "unit": 2, "label": "Custom Label", "type": "diris.a40" } ] }, { "host": "192.168.0.101", "port": 502, "label": null, "devices": [ { "unit": 1, "label": null, "type": "diris.a40" }, { "unit": 2, "label": null, "type": "diris.a40" }, { "unit": 3, "label": null, "type": "diris.a40" } ] } ] """ import json json.loads(json_data) # sanity check system_control_service = mock.Mock() system_control_service.update_gateways.return_value = gateways app = api.app_factory(system_control_service).test_client() response = app.put('/system-control/attached-devices', data=json_data, content_type='application/json') nose.assert_equal(200, response.status_code) system_control_service.update_gateways.assert_called_once_with(fixtures.stub_gateways()) data = json.loads(response.data) nose.assert_equal(2, len(data['gateways'])) nose.assert_equal(len(data['gateways'][0]['devices']), 2) nose.assert_equal(len(data['gateways'][1]['devices']), 3)