Esempio n. 1
0
def test_find_all_can_find_deleted_items_only_if_visibile_only_is_true(
    cosmos_db_repository: CosmosDBRepository,
    event_context: EventContext,
    sample_item: dict,
):
    deleted_item = cosmos_db_repository.delete(
        sample_item['id'], event_context
    )
    assert deleted_item is not None
    assert deleted_item['deleted'] is not None

    visible_items = cosmos_db_repository.find_all(event_context)

    assert visible_items is not None
    assert (
        any(item['id'] == sample_item['id'] for item in visible_items) == False
    ), 'The deleted item should not be visible'

    all_items = cosmos_db_repository.find_all(
        event_context, visible_only=False
    )

    assert all_items is not None
    assert any(
        item['id'] == sample_item['id'] for item in all_items
    ), 'Deleted item should be visible'
Esempio n. 2
0
def test_find_all_should_return_items_from_specified_partition_key_value(
    cosmos_db_repository: CosmosDBRepository,
    event_context: EventContext,
    another_event_context: EventContext,
):
    result_tenant_id = cosmos_db_repository.find_all(event_context)

    assert len(result_tenant_id) > 1
    assert all(
        (i["tenant_id"] == event_context.tenant_id for i in result_tenant_id)
    )

    result_another_tenant_id = cosmos_db_repository.find_all(
        another_event_context
    )

    assert len(result_another_tenant_id) > 0
    assert all(
        (
            i["tenant_id"] == another_event_context.tenant_id
            for i in result_another_tenant_id
        )
    )

    assert not any(
        item in result_another_tenant_id for item in result_tenant_id
    ), "There should be no interceptions"
Esempio n. 3
0
def test_find_all_with_max_count(
    cosmos_db_repository: CosmosDBRepository, event_context: EventContext
):
    all_items = cosmos_db_repository.find_all(event_context)

    assert len(all_items) > 2

    first_two_items = cosmos_db_repository.find_all(event_context, max_count=2)
    assert len(first_two_items) == 2, "The result should be limited to 2"
Esempio n. 4
0
def test_find_all_with_offset(
    cosmos_db_repository: CosmosDBRepository, event_context: EventContext
):
    result_all_items = cosmos_db_repository.find_all(event_context)

    assert len(result_all_items) >= 3

    result_after_the_first_item = cosmos_db_repository.find_all(
        event_context, offset=1
    )

    assert result_after_the_first_item == result_all_items[1:]

    result_after_the_second_item = cosmos_db_repository.find_all(
        event_context, offset=2
    )

    assert result_after_the_second_item == result_all_items[2:]
Esempio n. 5
0
def test_find_all_should_succeed_with_partition_key_value_with_no_items(
    cosmos_db_repository: CosmosDBRepository,
):
    invalid_event_context = EventContext("test", "any", tenant_id=fake.uuid4())

    no_items = cosmos_db_repository.find_all(invalid_event_context)

    assert no_items is not None
    assert len(no_items) == 0, "No items are expected"
Esempio n. 6
0
def test_find_all_with_mapper(
    cosmos_db_repository: CosmosDBRepository,
    event_context: EventContext,
    mapper: Callable,
    expected_type: Callable,
):
    result = cosmos_db_repository.find_all(event_context, mapper=mapper)

    assert result is not None
    assert len(result) > 0
    assert (
        type(result[0]) is expected_type
    ), "The result type is not the expected"
Esempio n. 7
0
    def find_all_entries(
        self,
        event_context: EventContext,
        conditions: dict = None,
        date_range: dict = None,
        **kwargs,
    ):
        conditions = conditions if conditions else {}
        date_range = date_range if date_range else {}

        time_entries = CosmosDBRepository.find_all(
            self,
            event_context=event_context,
            conditions=conditions,
            date_range=date_range,
            max_count=kwargs.get("max_count", None),
            offset=kwargs.get("offset", 0),
        )
        return time_entries