示例#1
0
    def test_all_mock(self, client, mocker):
        # arrange
        test_countries = [CountryMother.one().build(), CountryMother.two().build()]
        mocker.patch('modules.DBRepo.CountryDBRepo.CountryDBRepo.get_all', return_value=test_countries)
        expected_resp = [countryToDict(test_countries[i]) for i in range(len(test_countries))]
        view = CountriesListView()

        # act
        resp = view.get(HttpRequest())

        # assert
        assert expected_resp == resp.data
    def test_get_all_my_mock(self):
        # arrange
        expected_countries = [
            CountryMother.one().build(),
            CountryMother.two().build()
        ]
        usecase = CountryUsecases(CountryDBRepoMock())

        # 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 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 test_get_one_my_mock(self):
        # arrange
        test_id = 1
        expected_country = CountryMother.one().build()
        usecase = CountryUsecases(CountryDBRepoMock())

        # act
        result_countries = usecase.get_country(test_id)

        # assert
        assert result_countries.name == expected_country.name
示例#5
0
    def test_get_mock(self, client, mocker):
        # arrange
        test_country = CountryMother.one().build()
        test_id = 1
        mocker.patch('modules.DBRepo.CountryDBRepo.CountryDBRepo.get', return_value=test_country)
        view = CountryView()

        # act
        resp = view.get(HttpRequest(), test_id)

        # assert
        assert countryToDict(test_country) == resp.data
    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
示例#7
0
 def get(country_id) -> Country:
     return CountryMother.one().build()
示例#8
0
 def get_all() -> List[Country]:
     return [CountryMother.one().build(), CountryMother.two().build()]