Commit fca017a2b496c64c755b5e6c3aae4ded02d5398d
1 parent
f8a100b8dc
Exists in
master
Tests and code for sections/{pk}/flashcards
Showing 2 changed files with 13 additions and 5 deletions Side-by-side Diff
flashcards/tests/test_api.py
View file @
fca017a
1 | 1 | from django.core import mail |
2 | -from flashcards.models import User, Section, Flashcard, WhitelistedAddress | |
2 | +from flashcards.models import * | |
3 | 3 | from rest_framework.status import HTTP_204_NO_CONTENT, HTTP_201_CREATED, HTTP_200_OK, HTTP_403_FORBIDDEN |
4 | 4 | from rest_framework.test import APITestCase |
5 | 5 | from re import search |
... | ... | @@ -200,8 +200,8 @@ |
200 | 200 | def setUp(self): |
201 | 201 | self.client.login(email='none@none.com', password='1234') |
202 | 202 | self.user = User.objects.get(email='none@none.com') |
203 | - flashcard = Flashcard(text="jason", section=Section.objects.get(pk=1), material_date=now(), author=self.user) | |
204 | - flashcard.save() | |
203 | + self.flashcard = Flashcard(text="jason", section=Section.objects.get(pk=1), material_date=now(), author=self.user) | |
204 | + self.flashcard.save() | |
205 | 205 | |
206 | 206 | def test_list_sections(self): |
207 | 207 | response = self.client.get("/api/sections/", format="json") |
208 | 208 | |
... | ... | @@ -247,8 +247,16 @@ |
247 | 247 | self.assertFalse(self.user.sections.filter(pk=section.pk).exists()) |
248 | 248 | |
249 | 249 | def test_section_flashcards(self): |
250 | + # test to get flashcards for section 1 | |
250 | 251 | response = self.client.get('/api/sections/1/flashcards/') |
251 | 252 | self.assertEqual(response.status_code, HTTP_200_OK) |
253 | + | |
254 | + # test: Making FlashcardHide object, so no card should be seen. | |
255 | + flashcard_hide = FlashcardHide(user=self.user, flashcard=self.flashcard) | |
256 | + flashcard_hide.save() | |
257 | + response = self.client.get('/api/sections/1/flashcards/') | |
258 | + self.assertEqual(response.status_code, HTTP_200_OK) | |
259 | + self.assertEqual(response.content, '[]') | |
252 | 260 | |
253 | 261 | def test_section_search(self): |
254 | 262 | response = self.client.get('/api/sections/search/?q=Kramer') |
flashcards/views.py
View file @
fca017a
... | ... | @@ -32,7 +32,7 @@ |
32 | 32 | Returned in strictly chronological order (material date). |
33 | 33 | """ |
34 | 34 | flashcards = Flashcard.cards_visible_to(request.user).filter( \ |
35 | - section=self.get_object(), is_hidden=False).all() | |
35 | + section=self.get_object()).all() | |
36 | 36 | |
37 | 37 | return Response(FlashcardSerializer(flashcards, many=True).data) |
38 | 38 |