File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ from django .test import SimpleTestCase
2
+ from demoproject import views
3
+ import json
4
+
5
+ from rest_framework .test import APIRequestFactory
6
+
7
+ factory = APIRequestFactory ()
8
+
9
+ class NumbersTestCase (SimpleTestCase ):
10
+ def setUp (self ):
11
+ pass
12
+
13
+ def test_numbers_have_ids (self ):
14
+ self .assertEqual (views .NUMBERS [1002 ]['id' ], 1002 )
15
+
16
+
17
+ class NumbersAPITestCase (SimpleTestCase ):
18
+ def test_all_nums_returned (self ):
19
+
20
+ # TODO there may be a better way.
21
+ # https://www.django-rest-framework.org/api-guide/testing/
22
+ view = views .NumberViewSet .as_view ({'get' : 'list' })
23
+ request = factory .get ('/numbers' )
24
+ response = view (request )
25
+ response .render ()
26
+ body = json .loads (response .content )
27
+
28
+ self .assertEqual (len (body ), len (views .NUMBERS ))
You can’t perform that action at this time.
0 commit comments