Commit fb04c43b authored by Einar Uvsløkk's avatar Einar Uvsløkk
Browse files

Clean up workout-detail test case

Add more assert statements, and remove unused code.
parent ca4c23b6
Pipeline #129564 passed with stage
in 1 minute and 1 second
...@@ -192,6 +192,7 @@ class WorkoutDetailTest(APITestCase): ...@@ -192,6 +192,7 @@ class WorkoutDetailTest(APITestCase):
self.client.force_authenticate(self.user) self.client.force_authenticate(self.user)
workout = Workout.objects.get(pk=1) workout = Workout.objects.get(pk=1)
data = self.serialize(workout) data = self.serialize(workout)
self.assertEqual(len(data["files"]), 0)
file_path = data_dir / "test-file.txt" file_path = data_dir / "test-file.txt"
file_obj = SimpleUploadedFile( file_obj = SimpleUploadedFile(
...@@ -200,21 +201,9 @@ class WorkoutDetailTest(APITestCase): ...@@ -200,21 +201,9 @@ class WorkoutDetailTest(APITestCase):
content_type="multipart/form-data", content_type="multipart/form-data",
) )
data["files"].append(dict(file=file_obj)) data["files"].append(dict(file=file_obj))
self.assertEqual(len(data["files"]), 1)
dump_data(data, "Raw Payload Data")
response = self.put(1, data) response = self.put(1, data)
# XXX Alternative using the APIRequestFactory
# view = WorkoutDetail.as_view()
# request = self.factory.put(
# self.url(1), create_payload(data), format="multipart"
# )
# force_authenticate(request, self.user)
# response = view(request, pk=1)
dump_data(response.data, "Response data")
self.assertTrue(status.is_success(response.status_code)) self.assertTrue(status.is_success(response.status_code))
self.assertEqual(len(response.data["files"]), len(data["files"])) self.assertEqual(len(response.data["files"]), len(data["files"]))
...@@ -225,14 +214,3 @@ class WorkoutDetailTest(APITestCase): ...@@ -225,14 +214,3 @@ class WorkoutDetailTest(APITestCase):
self.assertTrue(status.is_success(response.status_code)) self.assertTrue(status.is_success(response.status_code))
workouts = Workout.objects.all() workouts = Workout.objects.all()
self.assertListEqual(list(workouts), list()) self.assertListEqual(list(workouts), list())
def dump_data(data, name=None):
from pprint import pprint
line = "-" * 50
print("\n" + line)
if name:
print(name)
pprint(data)
print(line + "\n")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment