diff --git a/flashcards/tests/test_api.py b/flashcards/tests/test_api.py index ae00b98..57339c5 100644 --- a/flashcards/tests/test_api.py +++ b/flashcards/tests/test_api.py @@ -1,5 +1,5 @@ from django.core import mail -from flashcards.models import User, Section, Flashcard, WhitelistedAddress +from flashcards.models import * from rest_framework.status import HTTP_204_NO_CONTENT, HTTP_201_CREATED, HTTP_200_OK, HTTP_403_FORBIDDEN from rest_framework.test import APITestCase from re import search @@ -200,8 +200,8 @@ class SectionViewSetTest(APITestCase): def setUp(self): self.client.login(email='none@none.com', password='1234') self.user = User.objects.get(email='none@none.com') - flashcard = Flashcard(text="jason", section=Section.objects.get(pk=1), material_date=now(), author=self.user) - flashcard.save() + self.flashcard = Flashcard(text="jason", section=Section.objects.get(pk=1), material_date=now(), author=self.user) + self.flashcard.save() def test_list_sections(self): response = self.client.get("/api/sections/", format="json") @@ -247,8 +247,16 @@ class SectionViewSetTest(APITestCase): self.assertFalse(self.user.sections.filter(pk=section.pk).exists()) def test_section_flashcards(self): + # test to get flashcards for section 1 + response = self.client.get('/api/sections/1/flashcards/') + self.assertEqual(response.status_code, HTTP_200_OK) + + # test: Making FlashcardHide object, so no card should be seen. + flashcard_hide = FlashcardHide(user=self.user, flashcard=self.flashcard) + flashcard_hide.save() response = self.client.get('/api/sections/1/flashcards/') self.assertEqual(response.status_code, HTTP_200_OK) + self.assertEqual(response.content, '[]') def test_section_search(self): response = self.client.get('/api/sections/search/?q=Kramer') diff --git a/flashcards/views.py b/flashcards/views.py index 9a2e8b2..0da3fc8 100644 --- a/flashcards/views.py +++ b/flashcards/views.py @@ -32,7 +32,7 @@ class SectionViewSet(ReadOnlyModelViewSet): Returned in strictly chronological order (material date). """ flashcards = Flashcard.cards_visible_to(request.user).filter( \ - section=self.get_object(), is_hidden=False).all() + section=self.get_object()).all() return Response(FlashcardSerializer(flashcards, many=True).data) @@ -332,4 +332,4 @@ class FlashcardViewSet(GenericViewSet, CreateModelMixin, RetrieveModelMixin): if 'mask' in new_flashcard or created: user_card.save() - return Response(status=HTTP_204_NO_CONTENT) \ No newline at end of file + return Response(status=HTTP_204_NO_CONTENT)