-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
32 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,34 @@ | ||
from django.test import TestCase | ||
from django import urls | ||
from rest_framework import test | ||
|
||
from recipes import models | ||
|
||
|
||
# Create your tests here. | ||
class ApiTestCase(TestCase): | ||
class ApiTestCase(test.APITestCase): | ||
fixtures = ["categories.json", "programs.json", "recipes.json", "comments.json"] | ||
pass | ||
|
||
def test_recipe_comments_get(self): | ||
url = urls.reverse("api:recipe-comments-list", kwargs={"pk": 1}) | ||
response = self.client.get(url) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
|
||
data = response.json() | ||
self.assertIsInstance(data, dict) | ||
self.assertEqual(len(data["results"]), 1) | ||
self.assertEqual(data["results"][0]["text"], "Опубликованный комментарий") | ||
|
||
def test_recipe_comments_post(self): | ||
url = urls.reverse("api:recipe-comments-list", kwargs={"pk": 1}) | ||
count_before = models.Comment.objects.count() | ||
|
||
response = self.client.post(url, {"text": "test"}) | ||
|
||
self.assertEqual(response.status_code, 201) | ||
self.assertEqual(response.json()["text"], "test") | ||
|
||
self.assertEqual(models.Comment.objects.count(), count_before + 1) | ||
self.assertEqual( | ||
models.Comment.objects.get(text="test").state, models.Comment.STATE_NEW | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters