Skip to content

Commit

Permalink
fixup! ✨(models) issue-196: add models and endpoints to user wishlist
Browse files Browse the repository at this point in the history
  • Loading branch information
MorganeAD committed Mar 7, 2023
1 parent c840443 commit 6417199
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to

- Allow on-demand page size on the order and enrollment endpoints
- Add yarn cli to generate joanie api client in TypeScript
- Add model and endpoints for wishlist feature

### Removed

Expand All @@ -36,7 +37,6 @@ and this project adheres to

- Add synchronization for course runs
- Add make dbshell cmd to access database in cli
- Add model and endpoints for wishlist feature

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions src/backend/joanie/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ class CourseWishViewSet(
permission_classes = [permissions.IsAuthenticated]

def get_queryset(self):
"""Custom queryset to get user addresses"""
"""Custom queryset to get user wishlist"""
user = User.update_or_create_from_request_user(request_user=self.request.user)
queryset = user.wishlists.all()
course_code = self.request.query_params.get("course_code")
Expand All @@ -460,6 +460,6 @@ def get_queryset(self):
return queryset

def perform_create(self, serializer):
"""Create a new address for user authenticated"""
"""Create a new wish for user authenticated"""
user = User.update_or_create_from_request_user(request_user=self.request.user)
serializer.save(owner=user)
2 changes: 1 addition & 1 deletion src/backend/joanie/core/models/wishlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CourseWish(BaseModel):
owner = models.ForeignKey(
to=User,
verbose_name=_("Owner"),
related_name="wishlists",
related_name="wishlist",
on_delete=models.PROTECT,
)

Expand Down
14 changes: 5 additions & 9 deletions src/backend/joanie/tests/core/test_api_wishlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_api_wish_get_wish_for_new_user(self):
self.assertTrue(models.User.objects.filter(username=username).exists())

def test_api_wish_get_wishes(self):
"""Get wish for a user in db with two wish linked to him"""
"""Get wish for a user in db with two wishes linked to him"""
user = factories.UserFactory()
course1 = factories.CourseFactory()
course2 = factories.CourseFactory()
Expand All @@ -96,17 +96,15 @@ def test_api_wish_get_wishes(self):
self.assertEqual(results[1]["id"], str(wish2.id))

def test_api_wish_get_wishes_filter_by_code(self):
"""Get wish for a user in db with two wish linked to him"""
"""Get wish for a user in db with two wishes linked to him"""
user = factories.UserFactory()
course = factories.CourseFactory()
token = self.get_user_token(user.username)
wish = factories.CourseWishFactory.create(owner=user, course=course)
factories.CourseWishFactory.create(owner=user)

get_url = f"/api/v1.0/wishlist/?course_code={course.code}"
response = self.client.get(
get_url, HTTP_AUTHORIZATION=f"Bearer {token}"
)
response = self.client.get(get_url, HTTP_AUTHORIZATION=f"Bearer {token}")
self.assertEqual(response.status_code, 200)

results = response.data["results"]
Expand All @@ -115,16 +113,14 @@ def test_api_wish_get_wishes_filter_by_code(self):
self.assertEqual(results[0]["id"], str(wish.id))

def test_api_wish_get_wish(self):
"""Get wish for a user in db with two wish linked to him"""
"""Get wish for a user in db with two wishes linked to him"""
user = factories.UserFactory()
token = self.get_user_token(user.username)
wish = factories.CourseWishFactory.create(owner=user)
factories.CourseWishFactory.create(owner=user)

get_url = f"/api/v1.0/wishlist/{wish.id}/"
response = self.client.get(
get_url, HTTP_AUTHORIZATION=f"Bearer {token}"
)
response = self.client.get(get_url, HTTP_AUTHORIZATION=f"Bearer {token}")
self.assertEqual(response.status_code, 200)

data = response.data
Expand Down

0 comments on commit 6417199

Please sign in to comment.