diff --git a/flashcards/tests/test_api.py b/flashcards/tests/test_api.py index 2901f56..4fa9002 100644 --- a/flashcards/tests/test_api.py +++ b/flashcards/tests/test_api.py @@ -1,6 +1,6 @@ from django.core import mail 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.status import HTTP_204_NO_CONTENT, HTTP_201_CREATED, HTTP_200_OK, HTTP_403_FORBIDDEN, HTTP_404_NOT_FOUND from rest_framework.test import APITestCase from re import search from django.utils.timezone import now @@ -187,6 +187,27 @@ class FlashcardDetailTest(APITestCase): self.flashcard = Flashcard(text="jason", section=section, material_date=now(), author=user) self.flashcard.save() + def test_edit_flashcard(self): + self.client.login(email='none@none.com', password='1234') + user = User.objects.get(email='none@none.com') + user.sections.add(Section.objects.get(pk=1)) + user.save() + + def test_create_flashcard(self): + self.client.login(email='none@none.com', password='1234') + user = User.objects.get(email='none@none.com') + user.sections.add(Section.objects.get(pk=1)) + user.save() + data = {'text': 'this is a flashcard', + 'material_date': str(datetime.now()), + 'mask': '[]', + 'section': '1', + 'previous': None} + response = self.client.post("/api/flashcards/", data, format="json") + self.assertEqual(response.status_code, HTTP_201_CREATED) + self.assertEqual(response.data['text'], data['text']) + self.assertTrue(Flashcard.objects.filter(section__pk=1, text=data['text']).exists()) + def test_get_flashcard(self): self.client.login(email='none@none.com', password='1234') response = self.client.get("/api/flashcards/%d/" % self.flashcard.id, format="json") @@ -278,6 +299,4 @@ class SectionViewSetTest(APITestCase): self.user.sections.add(self.section) self.user.save() response = self.client.get('/api/sections/1/ordered_deck/') - self.assertEqual(response.status_code, HTTP_200_OK) - - def test_hide_card(self): + self.assertEqual(response.status_code, HTTP_200_OK) \ No newline at end of file