Skip to content

Commit 7651057

Browse files
committed
Minor test changes and replaced legacy code
1 parent b6b4bac commit 7651057

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

backend/flaskr/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def retrieve_categories():
5454
try:
5555
selection = Category.query.order_by(Category.id).all()
5656
print(f'selection:{selection}' )
57-
57+
#current_categories = paginate_questions(request, selection)
5858
formatted_category = [category.format() for category in selection]
5959
print(f'formatted_category:{formatted_category}' )
6060
if len(formatted_category) == 0:
@@ -330,7 +330,7 @@ def play_quiz():
330330
response = {"question":None}
331331
else:
332332
new_question_id = random.choice(filtered_questions_in_category)
333-
question=Question.query.get(new_question_id)
333+
question = db.session.get(Question,new_question_id)
334334
response = {"question":question.format()}
335335
return jsonify(response)
336336

backend/test_flaskr.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,16 @@ def tearDown(self):
3838
TODO
3939
Write at least one test for each test for successful operation and for expected errors.
4040
"""
41-
# def test_get_categories(self):
42-
# res = self.client().get("/api/v1.0/categories")
43-
# data = json.loads(res.data)
44-
# print(f'Data:{res.data}')
45-
# self.assertEqual(res.status_code, 200)
46-
# self.assertEqual(data["success"], True)
47-
# self.assertTrue(data["total_category"])
48-
# self.assertTrue(len(data["categories"]))
41+
def test_get_categories(self):
42+
res = self.client().get("/categories")
43+
data = json.loads(res.data)
44+
print(f'Data:{res.data}')
45+
self.assertEqual(res.status_code, 200)
46+
self.assertTrue(data["categories"])
47+
self.assertTrue(len(data["categories"]))
4948

5049
# def test_404_sent_requesting_beyond_valid_page(self):
51-
# res = self.client().get("/api/v1.0/categories?page=1000", json={"category": 1})
50+
# res = self.client().get("/categories?page=1000", json={"category": 1})
5251
# data = json.loads(res.data)
5352

5453
# self.assertEqual(res.status_code, 404)
@@ -76,7 +75,7 @@ def tearDown(self):
7675
# self.assertTrue(len(data["questions"]))
7776

7877
def test_quiz(self):
79-
res = self.client().get("/play",json={"previous_question": [1],"quiz_category":{ "id":1}})
78+
res = self.client().get("/quizzes",json={"previous_question": [1],"quiz_category":{ "id":1}})
8079
print(f'Data:{res.data}')
8180
data = json.loads(res.data)
8281
print(f'Data:{data}')

0 commit comments

Comments
 (0)