Skip to content
Snippets Groups Projects
Commit 209ff7b7 authored by Martin Emeric's avatar Martin Emeric
Browse files

[Added] Exo 2 - CityFinder class and its tests [Fixed] Test function names

parent bbc07db1
No related branches found
No related tags found
No related merge requests found
import pytest
from tdd_exo_2 import CityFinder
@pytest.fixture(autouse=True)
def change_test_dir(request, monkeypatch):
monkeypatch.chdir(request.fspath.dirname)
# Initializing function for CityFinder functions
@pytest.fixture(name='city_finder')
def fixture_init_city_finder():
return CityFinder()
[pytest]
markers =
smoke: Mandatory pass tests
\ No newline at end of file
......@@ -2,7 +2,7 @@
def fizz_buzz(number: int):
if isinstance(number, int) is False:
raise TypeError('The paramter "number" must be an integer')
raise TypeError('The parameter "number" must be an integer')
if number % 3 == 0 and number % 5 == 0:
return 'FizzBuzz'
......
class CityFinder:
__cities = ['Paris', 'Budapest', 'Skopje', 'Rotterdam', 'Valence', 'Vancouver', 'Amsterdam', 'Vienne', 'Sydney',
'New York', 'Londres', 'Bangkok', 'Hong Kong', 'Dubaï', 'Rome', 'Istanbul']
def get_all_cities(self):
return self.__cities
def search_city(self, search: str):
if isinstance(search, str) is False:
raise TypeError('The parameter "search" must be a string')
if search == '*':
return self.__cities
if len(search) < 2:
return
results = list()
for city in self.__cities:
if search.lower() in city.lower():
results.append(city)
if len(results) >= 1:
return results
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()
......@@ -4,24 +4,26 @@ from tdd_exo_1 import fizz_buzz
class TestFizzBuzz:
def test_number_not_int(self):
"""
fizz_buzz function tests class
"""
@pytest.mark.smoke
def test_should_raise_type_error_exception_when_not_an_int(self):
with pytest.raises(TypeError):
fizz_buzz('not_an_int')
def test_3_multiple(self):
assert fizz_buzz(6) == 'Fizz'
def test_5_multiple(self):
assert fizz_buzz(20) == 'Buzz'
def test_3_and_5_multiple(self):
@pytest.mark.parametrize('number', [3, 6, 9, 12])
def test_should_return_fizz_when_multiple_of_3(self, number: int):
assert fizz_buzz(number) == 'Fizz'
assert fizz_buzz(15) == 'FizzBuzz'
@pytest.mark.parametrize('number', [5, 10, 20, 50])
def test_should_return_buzz_when_multiple_of_5(self, number):
assert fizz_buzz(number) == 'Buzz'
def test_no_multiple(self):
@pytest.mark.parametrize('number', [15, 30, 45, 60])
def test_should_return_fizzbuzz_when_multiple_of_3_and_5(self, number):
assert fizz_buzz(number) == 'FizzBuzz'
assert fizz_buzz(7) == 7
@pytest.mark.parametrize('number', [1, 7, 8, 22])
def test_should_return_the_number_when_no_multiple(self, number):
assert fizz_buzz(number) == number
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment