def test_partial_update_with_invalid_id_should_fail( cosmos_db_repository: CosmosDBRepository, event_context: EventContext ): changes = { 'name': fake.name(), 'email': fake.safe_email(), } try: cosmos_db_repository.partial_update( fake.uuid4(), changes, event_context ) fail('It should have failed') except Exception as e: assert type(e) is CosmosResourceNotFoundError assert e.status_code == 404
def test_partial_update_with_new_partition_key_value_should_fail( cosmos_db_repository: CosmosDBRepository, another_event_context: EventContext, sample_item: dict, ): changes = { 'name': fake.name(), 'email': fake.safe_email(), } try: cosmos_db_repository.partial_update( sample_item['id'], changes, another_event_context ) fail('It should have failed') except Exception as e: assert type(e) is CosmosResourceNotFoundError assert e.status_code == 404
def test_partial_update_should_not_find_element_that_is_already_deleted( 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 try: changes = { 'name': fake.name(), 'email': fake.safe_email(), } cosmos_db_repository.partial_update( deleted_item['id'], changes, event_context ) fail('It should have not found the deleted item') except Exception as e: assert type(e) is CosmosResourceNotFoundError assert e.status_code == 404
def test_partial_update_with_mapper( cosmos_db_repository: CosmosDBRepository, mapper: Callable, sample_item: dict, event_context: EventContext, expected_type: Callable, ): changes = { 'name': fake.name(), 'email': fake.safe_email(), } updated_item = cosmos_db_repository.partial_update( sample_item['id'], changes, event_context, mapper=mapper ) assert updated_item is not None assert type(updated_item) is expected_type
def test_partial_update_should_only_update_fields_in_changes( cosmos_db_repository: CosmosDBRepository, sample_item: dict, event_context: EventContext, ): changes = { 'name': fake.name(), 'email': fake.safe_email(), } updated_item = cosmos_db_repository.partial_update( sample_item['id'], changes, event_context ) assert updated_item is not None assert updated_item['name'] == changes["name"] != sample_item["name"] assert updated_item['email'] == changes["email"] != sample_item["email"] assert updated_item['id'] == sample_item["id"] assert updated_item['tenant_id'] == sample_item["tenant_id"] assert updated_item['age'] == sample_item["age"]