File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ from django .test import TestCase
2
+ from rest_framework .test import APIClient , APITestCase
3
+ from accounts .models import User
4
+ from profile .models import Profile
5
+ import sure
6
+ import json
7
+
8
+ class ProfileApiTests (APITestCase ):
9
+ def setUp (self ):
10
+ self .client = APIClient ()
11
+ self .content_type = 'application/vnd.api+json'
12
+
13
+ def test_profile_create_with_user (self ):
14
+ """
15
+ Ensure we get the correct profile
16
+ """
17
+ user = User .objects .create (username = "husky" )
18
+
19
+ profile = Profile .objects .create (user = user , bio = "Woof!" )
20
+
21
+ response = self .client .get ("/services/api/profiles" ,
22
+ content_type = self .content_type )
23
+
24
+ response .status_code .should .equal (200 )
25
+
26
+ response_data = json .loads (response .content )
27
+ attributes = response_data ['data' ][0 ]['attributes' ]
28
+ relationships = response_data ['data' ][0 ]['relationships' ]
29
+ attributes ['bio' ].should .equal (profile .bio )
30
+ relationships ['user' ]['data' ]['id' ].should .equal (str (user .id ))
You can’t perform that action at this time.
0 commit comments