From e1b89efe8ef1753f3b7d0396ec08c8d148918ffd Mon Sep 17 00:00:00 2001 From: Hicham DAKHLI Date: Wed, 25 Sep 2024 14:36:09 +0100 Subject: [PATCH 1/6] Recalcule area --- 5_unit_test/rectangle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/5_unit_test/rectangle.py b/5_unit_test/rectangle.py index 47ba42d..1dd507c 100644 --- a/5_unit_test/rectangle.py +++ b/5_unit_test/rectangle.py @@ -4,7 +4,7 @@ def __init__(self, width, height): self.height = height def area(self): - return self.width * self.height + return self.width + self.height def perimeter(self): return 2 * (self.width + self.height) From 88bf90578247e3e930801717f894fa15ce9f919b Mon Sep 17 00:00:00 2001 From: Hicham DAKHLI Date: Wed, 25 Sep 2024 14:52:10 +0100 Subject: [PATCH 2/6] RECTANGLE unit tests --- 5_unit_test/rectangle.py | 2 +- 5_unit_test/test_rectangle.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 5_unit_test/test_rectangle.py diff --git a/5_unit_test/rectangle.py b/5_unit_test/rectangle.py index 1dd507c..47ba42d 100644 --- a/5_unit_test/rectangle.py +++ b/5_unit_test/rectangle.py @@ -4,7 +4,7 @@ def __init__(self, width, height): self.height = height def area(self): - return self.width + self.height + return self.width * self.height def perimeter(self): return 2 * (self.width + self.height) diff --git a/5_unit_test/test_rectangle.py b/5_unit_test/test_rectangle.py new file mode 100644 index 0000000..8856f38 --- /dev/null +++ b/5_unit_test/test_rectangle.py @@ -0,0 +1,14 @@ +from unittest import TestCase +from rectangle import Rectangle + + +class TestRectangle(TestCase): + def test_area(self): + rectangle1 = Rectangle(2, 4) + area = rectangle1.area() + self.assertEqual(8, area) + + def test_perimetre(self): + rectangle2 = Rectangle(2,4) + perimetre = rectangle2.perimeter() + self.assertEqual(12, perimetre) \ No newline at end of file From fa1420cc732863c2e28fbffee37aa73065aed597 Mon Sep 17 00:00:00 2001 From: Hicham DAKHLI Date: Wed, 25 Sep 2024 14:55:31 +0100 Subject: [PATCH 3/6] fix format issues --- 6_architecture/api/quiz_dao.py | 5 +++-- 6_architecture/async_call/async_call.py | 12 ++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/6_architecture/api/quiz_dao.py b/6_architecture/api/quiz_dao.py index aedcff1..810633f 100644 --- a/6_architecture/api/quiz_dao.py +++ b/6_architecture/api/quiz_dao.py @@ -27,7 +27,7 @@ def _create_connection(self): return conn def create_answer(self, question_id, user_name, answer_id): - sql = ''' INSERT INTO QUIZ (question_id, user_name, answer_id) + sql = ''' INSERT INTO QUIZ (question_id, user_name, answer_id) VALUES(?,?,?) ''' with self._create_connection() as conn: cur = conn.cursor() @@ -44,7 +44,8 @@ def count_answers_by_id(self, question_id: int): return len(rows) def update_answer(self, question_id: int, user_name, answer_id): - sql = ''' UPDATE QUIZ SET answer_id=? WHERE question_id=? AND user_name=?''' + sql = ''' UPDATE QUIZ SET answer_id=? WHERE + question_id=? AND user_name=?''' with self._create_connection() as conn: cur = conn.cursor() cur.execute(sql, (answer_id, question_id, user_name)) diff --git a/6_architecture/async_call/async_call.py b/6_architecture/async_call/async_call.py index c15290e..18c744e 100644 --- a/6_architecture/async_call/async_call.py +++ b/6_architecture/async_call/async_call.py @@ -14,12 +14,16 @@ def get_a_random_data() -> list: dog_response = call_api('https://dog.ceo/api/breeds/image/random') cat_response = call_api('https://catfact.ninja/fact') - pokemon_response = call_api(f'https://pokeapi.co/api/v2/pokemon/{random.randint(0, 100)}') + pokemon_response = call_api(f'https://pokeapi.co/api/v2/pokemon/' + f'{random.randint(0, 100)}') user_response = call_api('https://randomuser.me/api/') - joke_response = call_api('https://official-joke-api.appspot.com/random_joke') - products_response = call_api('https://hub.dummyapis.com/products?noofRecords=10&idStarts=1001¤cy=usd') + joke_response = call_api('https://official-joke-api.appspot.com' + '/random_joke') + products_response = call_api('https://hub.dummyapis.com/products?' + 'noofRecords=10&idStarts=1001¤cy=usd') - responses = [dog_response, cat_response, pokemon_response, joke_response, user_response, products_response] + responses = [dog_response, cat_response, pokemon_response, + joke_response, user_response, products_response] end = datetime.now() print(f"duration = {end - start}") From 933b8fa40f2ab97c6174e51666fde0de4722e0f7 Mon Sep 17 00:00:00 2001 From: Hicham DAKHLI Date: Wed, 25 Sep 2024 14:57:34 +0100 Subject: [PATCH 4/6] fix issues --- 5_unit_test/test_rectangle.py | 4 ++-- 6_architecture/api/quiz_dao.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/5_unit_test/test_rectangle.py b/5_unit_test/test_rectangle.py index 8856f38..72fa424 100644 --- a/5_unit_test/test_rectangle.py +++ b/5_unit_test/test_rectangle.py @@ -9,6 +9,6 @@ def test_area(self): self.assertEqual(8, area) def test_perimetre(self): - rectangle2 = Rectangle(2,4) + rectangle2 = Rectangle(2, 4) perimetre = rectangle2.perimeter() - self.assertEqual(12, perimetre) \ No newline at end of file + self.assertEqual(12, perimetre) diff --git a/6_architecture/api/quiz_dao.py b/6_architecture/api/quiz_dao.py index 810633f..d654240 100644 --- a/6_architecture/api/quiz_dao.py +++ b/6_architecture/api/quiz_dao.py @@ -44,7 +44,7 @@ def count_answers_by_id(self, question_id: int): return len(rows) def update_answer(self, question_id: int, user_name, answer_id): - sql = ''' UPDATE QUIZ SET answer_id=? WHERE + sql = ''' UPDATE QUIZ SET answer_id=? WHERE question_id=? AND user_name=?''' with self._create_connection() as conn: cur = conn.cursor() From 63ca106549332d4bc935edc798c87f20a0628dbf Mon Sep 17 00:00:00 2001 From: Hicham DAKHLI Date: Wed, 25 Sep 2024 14:58:56 +0100 Subject: [PATCH 5/6] Update rectangle --- 5_unit_test/rectangle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/5_unit_test/rectangle.py b/5_unit_test/rectangle.py index 47ba42d..07eb4de 100644 --- a/5_unit_test/rectangle.py +++ b/5_unit_test/rectangle.py @@ -7,4 +7,4 @@ def area(self): return self.width * self.height def perimeter(self): - return 2 * (self.width + self.height) + return 2 + (self.width + self.height) From 99afb9761326d3ad206857d114a382732379960f Mon Sep 17 00:00:00 2001 From: Hicham DAKHLI Date: Wed, 25 Sep 2024 15:00:18 +0100 Subject: [PATCH 6/6] fix rectangle --- 5_unit_test/rectangle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/5_unit_test/rectangle.py b/5_unit_test/rectangle.py index 07eb4de..47ba42d 100644 --- a/5_unit_test/rectangle.py +++ b/5_unit_test/rectangle.py @@ -7,4 +7,4 @@ def area(self): return self.width * self.height def perimeter(self): - return 2 + (self.width + self.height) + return 2 * (self.width + self.height)