Exemplo n.º 1
0
 async def test_get_all_deployments(self, mut, db_session, populated_db):
     db_session_var.set(db_session)
     deployment_ids = await mut()
     assert set(deployment_ids) == {
         UUID("b4c68905-b1e4-4875-940e-69e5d27730fd"),
         UUID("6e887b81-57c3-4f3b-a7e7-bad159e05e78"),
     }
Exemplo n.º 2
0
 async def test_iterate_over_all_items(self, mut, db_session, filter,
                                       num_items_expected):
     db_session_var.set(db_session)
     num_items = 0
     num_deployments = 0
     async for deployment_id, items in mut(**filter):
         num_deployments += 1
         async for item in items:
             num_items += 1
     assert num_deployments == 2
     assert num_items == num_items_expected
Exemplo n.º 3
0
 async def test_skip_first_deployment(self, mut, db_session, filter,
                                      num_items_expected):
     db_session_var.set(db_session)
     num_items = 0
     num_deployments = 0
     async for deployment_id, items in mut(**filter):
         num_deployments += 1
         if num_deployments == 2:
             async for item in items:
                 num_items += 1
     assert num_deployments == 2
     assert num_items == num_items_expected
    async def test_datapoints_are_persisted(self, subject, migrated_db):
        db_session_var.set(migrated_db)

        wrapper = subject()
        await wrapper.start()

        data = [
            (datetime.datetime(2020, 4, 1, 12, 0, 0), 21.0),
        ]
        generated_datapoints = []
        async for datapoint in generate_datapoints(data):
            generated_datapoints.append(datapoint)
            await wrapper.handle(datapoint)

        stored_datapoints = [
            point async for point in get_data(sensor_name="TestSensor")
        ]
        assert stored_datapoints[0].data == generated_datapoints[0].data
        assert (stored_datapoints[0].deployment_id ==
                generated_datapoints[0].deployment_id)
Exemplo n.º 5
0
def db_session(db_uri):
    from sqlalchemy import create_engine
    from sqlalchemy.orm import sessionmaker

    engine = create_engine(db_uri, echo=False)
    sm = sessionmaker(engine)
    Session = sm()
    reset = db_session_var.set(Session)
    yield Session
    db_session_var.reset(reset)
    Session.close()
 def get_data(self, db_session):
     db_session_var.set(db_session)
     return analysis.get_all_data()
Exemplo n.º 7
0
 async def test_empty_db(self, mut, db_session, migrated_db):
     db_session_var.set(db_session)
     deployment_ids = await mut()
     assert deployment_ids == []
Exemplo n.º 8
0
 async def test_empty_db(self, mut, db_session, migrated_db):
     db_session_var.set(db_session)
     points = [dp async for dp in mut()]
     assert len(points) == 0
Exemplo n.º 9
0
 async def test_iterate_over_items(self, mut, db_session, populated_db,
                                   filter, num_items_expected):
     db_session_var.set(db_session)
     points = [dp async for dp in mut(**filter)]
     assert len(points) == num_items_expected