generated from libresource/pygenesis-django
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
61ee872
commit 7690161
Showing
4 changed files
with
63 additions
and
8 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,9 +1,58 @@ | ||
from django.test import TestCase | ||
from rest_framework.test import APIClient | ||
from rest_framework.test import APITestCase | ||
from otus_open_lesson.models import mock | ||
from otus_open_lesson.cases import OtusOpenLessonTestCase | ||
|
||
|
||
class SomeTest(TestCase): | ||
|
||
def test_mock(self): | ||
mock() | ||
self.assertTrue(True) | ||
|
||
|
||
class TestHelloWorldAPI(OtusOpenLessonTestCase): | ||
|
||
def setUp(self): | ||
self.url = '/hello/' | ||
self.guest_client = self.client | ||
# self.auth_client = self.client | ||
|
||
def test_hello_status_code(self): | ||
response = self.guest_client.get(self.url) | ||
self.assertStatusCode(response, 200) | ||
|
||
def test_hello_status_content(self): | ||
response = self.guest_client.get(self.url) | ||
self.assertTrue('hello' in response.json()) | ||
self.assertIn('hello', response.json()) | ||
self.assertEqual(response.json(), {'hello': 'world'}) | ||
self.assertDictEqual(response.json(), {'hello': 'world'}) | ||
|
||
|
||
class TestByWorldAPI(OtusOpenLessonTestCase): | ||
|
||
def setUp(self): | ||
self.url = '/by/' | ||
self.guest_client = self.client | ||
# self.auth_client = self.client | ||
|
||
def test_hello_status_code(self): | ||
response = self.guest_client.get(self.url) | ||
self.assertStatusCode(response, 200) | ||
|
||
def test_hello_status_content(self): | ||
response = self.guest_client.get(self.url) | ||
self.assertTrue('by' in response.json()) | ||
self.assertIn('by', response.json()) | ||
self.assertEqual(response.json(), {'by': 'by world'}) | ||
|
||
def test_response(self): | ||
response = self.guest_client.get(self.url) | ||
self.assertResponse(response, | ||
status_code=200, | ||
) | ||
|
||
# Параметризировать одинаковые | ||
# Динамически передавать атрибуты запроса для проверки |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from rest_framework.test import APITestCase | ||
|
||
|
||
class OtusOpenLessonTestCase(APITestCase): | ||
|
||
def assertStatusCode(self, response, code): | ||
self.assertEqual(response.status_code, code) | ||
|
||
def assertResponse(self, response, **kwargs): | ||
for k,v in kwargs.items(): | ||
result = getattr(response, k) | ||
expected = v | ||
self.assertEqual(result, expected) |
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 |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
Package info | ||
""" | ||
name = 'otus-open-lesson' | ||
version = '0.1.2' | ||
version = '0.2.0' | ||
status = '3 - Alpha' |
This file was deleted.
Oops, something went wrong.