Skip to content

Commit 0ba220e

Browse files
committed
created the tests for profile creation
1 parent 08b5a93 commit 0ba220e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

profile/tests/__init__.py

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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))

0 commit comments

Comments
 (0)