def test_get_locations_all(api_client, orm_client, test_input, test_input_2):
    assert orm_client.session.query(Location).count() == 0
    location_1 = LocationFactory2DB(name=test_input[0], latlng=test_input[1])
    assert orm_client.session.query(Location).count() == 1
    location_2 = LocationFactory2DB(name=test_input_2[0],
                                    latlng=test_input_2[1])
    assert orm_client.session.query(Location).count() == 2

    rv = api_client.get(f"/locations/")
    assert rv.status_code == 200
    response_content_1 = json.loads(rv.data)['data'][0]
    response_content_2 = json.loads(rv.data)['data'][1]
    assert_locations(response_content_1, location_1.__dict__)
    assert_locations(response_content_2, location_2.__dict__)
def orm_client(api_client):
    client = database
    client.init_db()
    print("ORM_CLIENT START")
    yield client
    DeviceFactory2DB.reset_sequence(value=0, force=True)
    DeviceCategoryFactory2DB.reset_sequence(value=0, force=True)
    EventFactory2DB.reset_sequence(value=0, force=True)
    EventAFactory2DB.reset_sequence(value=0, force=True)
    EventBFactory2DB.reset_sequence(value=0, force=True)
    BusinessRuleFactory2DB.reset_sequence(value=0, force=True)
    LocationFactory2DB.reset_sequence(value=0, force=True)
    print("ORM_CLIENT END")
    client.close()
def test_delete_device(api_client, orm_client, test_input):
    assert orm_client.session.query(Location).count() == 0
    location_1 = LocationFactory2DB(name=test_input[0], latlng=test_input[1])
    assert orm_client.session.query(Location).count() == 1

    rv = api_client.delete(f"/locations/{location_1.name}")
    assert rv.status_code == 200

    assert orm_client.session.query(Location).count() == 0
def test_get_location(api_client, orm_client, test_input):
    assert orm_client.session.query(Location).count() == 0
    location_1 = LocationFactory2DB(name=test_input[0], latlng=test_input[1])
    assert orm_client.session.query(Location).count() == 1

    rv = api_client.get(f"/locations/{location_1.name}")
    assert rv.status_code == 200
    response_content = json.loads(rv.data)['data']
    assert_locations(response_content, location_1.__dict__)
def test_update_device(api_client, orm_client, test_input, test_modify):
    assert orm_client.session.query(Location).count() == 0
    location_1 = LocationFactory2DB(name=test_input[0], latlng=test_input[1])
    assert orm_client.session.query(Location).count() == 1

    location_to_modify = LocationDictFactory(name=test_modify[0],
                                             latlng=test_modify[1])

    rv = api_client.put(f"/locations/{location_1.name}",
                        json=location_to_modify)
    assert rv.status_code == 200
    assert orm_client.session.query(Location).count() == 1

    rv = api_client.get(f"/locations/{location_1.name}")
    assert rv.status_code == 200
    response_content = json.loads(rv.data)['data']
    assert_locations(response_content, location_to_modify)
Esempio n. 6
0
def create_location():
    return LocationFactory2DB(name="MyLocation1")