Commit a06c7fa68916860d93a21f7d2addf6325e54153a

Authored by Andrew Buss
Exists in master

Merge branch 'master' of git.ucsd.edu:110swag/flashy-backend

Showing 2 changed files Side-by-side Diff

flashcards/tests/test_api.py View file @ a06c7fa
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
6 6  
... ... @@ -200,9 +200,9 @@
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 + self.flashcard = Flashcard(text="jason", section=Section.objects.get(pk=1), material_date=now(), author=self.user)
  204 + self.flashcard.save()
203 205 self.section = Section.objects.get(pk=1)
204   - flashcard = Flashcard(text="jason", section=self.section, material_date=now(), author=self.user)
205   - flashcard.save()
206 206  
207 207 def test_list_sections(self):
208 208 response = self.client.get("/api/sections/", format="json")
209 209  
... ... @@ -248,9 +248,17 @@
248 248 self.assertFalse(self.user.sections.filter(pk=section.pk).exists())
249 249  
250 250 def test_section_flashcards(self):
  251 + # test to get flashcards for section 1
251 252 response = self.client.get('/api/sections/1/flashcards/')
252 253 self.assertEqual(response.status_code, HTTP_200_OK)
253 254  
  255 + # test: Making FlashcardHide object, so no card should be seen.
  256 + flashcard_hide = FlashcardHide(user=self.user, flashcard=self.flashcard)
  257 + flashcard_hide.save()
  258 + response = self.client.get('/api/sections/1/flashcards/')
  259 + self.assertEqual(response.status_code, HTTP_200_OK)
  260 + self.assertEqual(response.content, '[]')
  261 +
254 262 def test_section_search(self):
255 263 response = self.client.get('/api/sections/search/?q=Kramer')
256 264 self.assertEqual(response.status_code, HTTP_200_OK)
... ... @@ -268,6 +276,8 @@
268 276 self.assertEqual(response.data, {})
269 277  
270 278 def test_section_ordered_deck(self):
  279 + self.user.sections.add(self.section)
  280 + self.user.save()
271 281 response = self.client.get('/api/sections/1/ordered_deck/')
272 282 self.assertEqual(response.status_code, HTTP_200_OK)
flashcards/views.py View file @ a06c7fa
... ... @@ -30,7 +30,8 @@
30 30 Gets flashcards for a section, excluding hidden cards.
31 31 Returned in strictly chronological order (material date).
32 32 """
33   - flashcards = Flashcard.cards_visible_to(request.user).filter(section=self.get_object())
  33 + flashcards = Flashcard.cards_visible_to(request.user).filter( \
  34 + section=self.get_object()).all()
34 35 return Response(FlashcardSerializer(flashcards, many=True).data)
35 36  
36 37 @detail_route(methods=['post'])