Skip to content
Snippets Groups Projects
test_city_finder.py 1.22 KiB

import pytest
from tdd_exo_2 import CityFinder


@pytest.mark.usefixtures('city_finder')
class TestCityFinder:

    @pytest.mark.smoke
    def should_raise_type_error_exception_when_not_a_string(self, city_finder: CityFinder):
        with pytest.raises(TypeError):
            city_finder.search_city(1)

    def test_should_return_none_when_search_length_lt_2(self, city_finder: CityFinder):
        assert city_finder.search_city('a') is None

    def test_should_return_none_when_city_does_not_exist(self, city_finder: CityFinder):
        assert city_finder.search_city('Miami') is None

    def test_should_return_2_cities_when_va_passed(self, city_finder: CityFinder):
        assert city_finder.search_city('va') == ['Valence', 'Vancouver']

    @pytest.mark.parametrize('search, city_expected',
                             [('istan', ['Istanbul']), ('lond', ['Londres']), ('syd', ['Sydney'])])
    def test_should_return_one_city_when_string_passed(self, city_finder: CityFinder, search, city_expected):
        assert city_finder.search_city(search) == city_expected

    def test_should_return_all_cities_when_asterisk_passed(self, city_finder: CityFinder):
        assert city_finder.search_city('*') == city_finder.get_all_cities()