Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
DanteOnline committed May 23, 2024
1 parent 61ee872 commit 7690161
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
49 changes: 49 additions & 0 deletions api/tests.py
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,
)

# Параметризировать одинаковые
# Динамически передавать атрибуты запроса для проверки
13 changes: 13 additions & 0 deletions otus_open_lesson/cases.py
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)
2 changes: 1 addition & 1 deletion otus_open_lesson/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
Package info
"""
name = 'otus-open-lesson'
version = '0.1.2'
version = '0.2.0'
status = '3 - Alpha'
7 changes: 0 additions & 7 deletions otus_open_lesson/tests.py

This file was deleted.

0 comments on commit 7690161

Please sign in to comment.