def test_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.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_update_with_partial_changes_with_required_fields_should_delete_the_missing_ones( cosmos_db_repository: CosmosDBRepository, event_context: EventContext, sample_item: dict, ): changes = { 'id': fake.uuid4(), 'email': fake.safe_email(), 'tenant_id': event_context.tenant_id, } updated_item = cosmos_db_repository.update( sample_item['id'], changes, event_context ) assert updated_item is not None assert updated_item['id'] == changes["id"] != sample_item["id"] assert updated_item['email'] == changes["email"] != sample_item["email"] assert updated_item['tenant_id'] == changes["tenant_id"] assert updated_item.get('name') is None assert updated_item.get('age') is None try: cosmos_db_repository.find(sample_item['id'], event_context) fail('The previous version should not exist') except Exception as e: assert type(e) is CosmosResourceNotFoundError assert e.status_code == 404
def test_update_with_partial_changes_without_required_fields_it_should_fail( cosmos_db_repository: CosmosDBRepository, event_context: EventContext, sample_item: dict, ): changes = { 'id': sample_item['id'], 'email': fake.safe_email(), 'tenant_id': fake.uuid4(), } try: cosmos_db_repository.update(sample_item['id'], changes, event_context) fail('It should have failed') except Exception as e: assert type(e) is CosmosResourceNotFoundError assert e.status_code == 404
def test_update_with_mapper( cosmos_db_repository: CosmosDBRepository, mapper: Callable, sample_item: dict, event_context: EventContext, expected_type: Callable, ): changed_item = sample_item.copy() changed_item.update( { 'name': fake.name(), 'email': fake.safe_email(), } ) updated_item = cosmos_db_repository.update( sample_item['id'], changed_item, event_context, mapper=mapper ) assert updated_item is not None assert type(updated_item) is expected_type