def test_list_client_industries(session, fake_lorem): """Test list_client_industries""" # Arrange fake_model = ClientIndustry(name=fake_lorem.word(), name_slug=fake_lorem.word()) ClientIndustryRepository.create(fake_model) # Act result = ClientIndustryRepository.list_client_industries() # Assert assert isinstance(result, list)
def test_get_one_by_id(session, fake_lorem): """Test get_one_by_id""" # Arrange fake_model = ClientIndustryRepository.add( ClientIndustry(name=fake_lorem.word())) # Act result = ClientIndustryRepository.get_one_by_id(model_id=fake_model.id) # Assert assert result is not None assert isinstance(result, ClientIndustry) assert result == fake_model
def list_client_industries() -> list: """ List client industries. Returns: List of client industries. """ return ClientIndustryRepository.list_client_industries()
def get_client_industry(client_industry_id: str) -> ClientIndustry: """ Get client industry. Args: client_industry_id (str): Client industry ID. Returns: Client industry ID. """ return ClientIndustryRepository.get_one_by_id(client_industry_id)
def create_client_industry(name: str) -> ClientIndustry: """ Creates client industry. Args: name (str): Name of client industry to be added. Returns: ClientIndustry: Client industry that has been added. Raises: ValueError if client industry name already exists. """ new_client_industry = ClientIndustry(name=name) return ClientIndustryRepository.add(new_client_industry)
def test_create(session, fake_lorem, fake_profile): """Test creating a client industry.""" # Arrange fake_org = create_organization(organization_name=fake_lorem.word(), address=fake_profile.profile()['address']) test_model = ClientIndustry(name=fake_lorem.word(), organization_id=fake_org.id) # Act result = ClientIndustryRepository.add(model=test_model) # Assert assert isinstance(result, ClientIndustry) assert isinstance(UUID(result.id), UUID)
def test_update_raises_value_error_exception(session, fake_lorem): """Test update raises ValueError exception when invalid data is supplied""" # Arrange test_model = ClientIndustryRepository.add( ClientIndustry(name=fake_lorem.word())) updates = {'name': 'Existing name', 'name_slug': 'existing-name'} update_fields = ( 'name', 'name_slug', ) # Assert with pytest.raises(ValueError): ClientIndustryRepository\ .update(test_model.id, update_fields, **updates)
def test_update(session, fake_lorem): """Test updating a client industry""" # Arrange test_model = ClientIndustryRepository.add( ClientIndustry(name=fake_lorem.word())) updates = {'name': 'Changed name', 'name_slug': 'changed-name'} update_fields = ( 'name', 'name_slug', ) # Act result = ClientIndustryRepository\ .update(test_model.id, update_fields, **updates) # Assert assert isinstance(result, ClientIndustry) assert test_model.id == result.id
def update_client_industry(client_industry_id: str, **updates): """ Update client industry. Args: client_industry_id (str): Client industry ID. Returns: Updated client industry. Raises: ValueError if client industry update name already exists. """ update_fields = ( 'name', 'name_slug', ) return ClientIndustryRepository.update( client_industry_id=client_industry_id, update_fields=update_fields, **updates)