Skip to content

Commit

Permalink
Update test_api.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nemouet authored May 24, 2024
1 parent 5cec2f3 commit 8ad3acd
Showing 1 changed file with 1 addition and 89 deletions.
90 changes: 1 addition & 89 deletions API/unit_test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,95 +4,6 @@

URL_TEST = "http://localhost:5000/api/students"


# class TestAPI(unittest.TestCase):
# def setUp(self):
# # Create a sample student for testing purposes
# data = {
# "no": 22,
# "fullName": "Nguyen Van CDE",
# "doB": "2001",
# "gender": "Nam",
# "school": "NEUST"
# }
# res = requests.post(URL_TEST, json=data)
# if res.status_code != 200:
# print(f"Error creating student: {res.text}")

# self.assertEqual((res.json())['message'], 'Student created successfully')
# self._id = (res.json())['id']

# def tearDown(self):
# # Delete the sample student created in setUp
# res = requests.delete(f"{URL_TEST}/{self._id}").json()
# self.assertEqual(res['message'], 'Student deleted successfully')

# def test_get_students(self):
# # GET /api/students
# res = requests.get(URL_TEST)
# self.assertEqual(res.status_code, 200)
# self.assertGreater(len(res.json()), 0)

# def test_create_student(self):
# data = {
# "no": 44,
# "fullName": "Nguyen Van A",
# "doB": "2000",
# "gender": "Nam",
# "school": "HUST"
# }
# res = requests.post(URL_TEST, json=data)
# self.assertEqual(res.status_code, 200)
# self.created_id = res.json()['id']
# self.assertEqual(res.json()['message'], 'Student created successfully')

# def test_get_student_by_id(self):
# res = requests.get(f"{URL_TEST}/{self._id}")
# self.assertEqual(res.status_code, 200)
# self.assertEqual(res.json()['_id'], self._id)
# self.assertGreater(len(res.json()), 0)

# def test_update_student(self):
# updated_data = {
# "no": 55,
# "fullName": "Nguyen Van CDF",
# "doB": "2001",
# "gender": "gioi tinh thu 3",
# "school": "NEUST"
# }
# res = requests.put(f"{URL_TEST}/{self._id}", json=updated_data)
# self.assertEqual(res.status_code, 200)
# self.assertEqual(res.json()['message'], 'Student updated successfully')

# def test_delete_student(self):
# # Ensure we create a student to delete
# data = {
# "no": 44,
# "fullName": "Nguyen Van A",
# "doB": "2000",
# "gender": "Nam",
# "school": "HUST"
# }
# res = requests.post(URL_TEST, json=data)
# self.assertEqual(res.status_code, 200)
# created_id = res.json()['id']
# self.assertEqual(res.json()['message'], 'Student created successfully')

# # Delete the newly created student
# response = requests.delete(f'{URL_TEST}/{created_id}')
# self.assertEqual(response.status_code, 200)
# self.assertEqual(response.json()['message'], 'Student deleted successfully')

# # Check if the student is really deleted
# response = requests.get(f'{URL_TEST}/{created_id}')
# self.assertEqual(response.status_code, 404)

# if __name__ == "__main__":
# test_order = ["setUp", "test_get_students", "test_create_student", "test_get_student_by_id", "test_update_student", "test_delete_student", "tearDown"]
# test_loader = unittest.TestLoader()
# test_loader.sortTestMethodsUsing = lambda x, y: test_order.index(x) - test_order.index(y)
# unittest.main(testLoader=test_loader)

class TestAPI(unittest.TestCase):
def setUp(self):
data = {
Expand All @@ -102,6 +13,7 @@ def setUp(self):
"gender": "Nam",
"school": "NEUST"
}
print(URL_TEST)
res = requests.post(URL_TEST, json=data)
if res.status_code != 200:
print(f"Error creating student: {res.text}")
Expand Down

0 comments on commit 8ad3acd

Please sign in to comment.