def test_get_success(self, simple_country): # arrange expected_country = CountryDBRepo.decode_orm_country(simple_country) test_id = simple_country.id # act result_country = CountryDBRepo.get(country_id=test_id) # assert assert result_country.name == expected_country.name
def test_get_all_success(self, countries_20): # arrange expected_countries = [] for g in countries_20: expected_countries.append(CountryDBRepo.decode_orm_country(g)) # act result_countries = CountryDBRepo.get_all() # assert for i in range(len(expected_countries)): assert result_countries[i].name == expected_countries[i].name
def test_get_all_no_results(self): # arrange expected_countries = [] # act result_countries = CountryDBRepo.get_all() # assert assert result_countries == expected_countries
def test_get_fail_not_normal(self): # arrange test_id = 1 # act result_country = CountryDBRepo.get(country_id=test_id) # assert assert result_country is None
def test_get_one_success(self, simple_country): # arrange usecase = CountryUsecases(CountryDBRepo()) test_id = simple_country.id expected_country = simple_country # act result_countries = usecase.get_country(test_id) # assert assert result_countries.name == expected_country.name
def test_get_one_success_london(self, mocker): # arrange test_id = 1 expected_country = CountryMother.one().build() mocker.patch('modules.DBRepo.CountryDBRepo.CountryDBRepo.get', return_value=expected_country) usecase = CountryUsecases(CountryDBRepo()) # act result_countries = usecase.get_country(test_id) # assert assert result_countries.name == expected_country.name
def test_get_success(self, mocker): # arrange expected_countries = [ CountryMother.one().build(), CountryMother.two().build() ] mocker.patch('modules.DBRepo.CountryDBRepo.CountryDBRepo.get_all', return_value=expected_countries) usecase = CountryUsecases(CountryDBRepo()) # act result_countries = usecase.get_all_countries() # assert for i in range(len(expected_countries)): assert result_countries[i].name == expected_countries[i].name
def decode_orm_film(orm_film) -> Film: genres = [] for g in orm_film.genres.all(): genres.append(GenreDBRepo.decode_orm_genre(g)) actors = [] for a in orm_film.actors.all(): actors.append(ActorDBRepo.decode_orm_actor(a)) countries = [] for g in orm_film.countries.all(): countries.append(CountryDBRepo.decode_orm_country(g)) return Film(title=orm_film.title, year=orm_film.year, description=orm_film.description, id=orm_film.id, genres=genres, actors=actors, countries=countries, image=orm_film.image, created=orm_film.created_at, rating=orm_film.rating, )
def get_country_usecase() -> CountryUsecases: return CountryUsecases(CountryDBRepo())
def test_get_one_wrong_params(self): usecase = CountryUsecases(CountryDBRepo()) result_countries = usecase.get_country(-100) assert result_countries is None
def test_get_one_no_result(self): usecase = CountryUsecases(CountryDBRepo()) result_countries = usecase.get_country(1) assert result_countries is None