Skip to content

Commit 8a1abc8

Browse files
committed
created failing test for challenges
1 parent 04b629c commit 8a1abc8

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from django.test import TestCase
2+
from rest_framework.test import APIClient, APITestCase
3+
from accounts.models import User
4+
from challenges.models import Challenge
5+
import sure
6+
import json
7+
8+
class ChallengeApiTests(APITestCase):
9+
def setUp(self):
10+
self.client = APIClient()
11+
self.content_type = 'application/vnd.api+json'
12+
13+
def test_challenge_create(self):
14+
"""
15+
Ensure we get the correct challenge
16+
"""
17+
user = User.objects.filter(username="codecorgi").first()
18+
19+
challenge = Challenge.objects.create(user=user,
20+
title = 'Test Challenge',
21+
short_title = 'Test Challenge',
22+
owner = 'Gandalf',
23+
difficulty = '5',
24+
challenge_type = 'feature',
25+
priority = 'High',
26+
description = 'This is a description',
27+
short_description = 'This is shorter',
28+
extra_points = 'Put it on github',
29+
technical_notes = 'Use Django',
30+
procedure = 'Clone the code, and then run it locally',
31+
code_tips = 'Use a linter',
32+
)
33+
34+
response = self.client.get(f'/services/api/challenges?pk={ challenge.id }',
35+
content_type=self.content_type)
36+
37+
response.status_code.should.equal(200)
38+
39+
response_data = json.loads(response.content)
40+
attributes = response_data['data'][0]['attributes']
41+
relationships = response_data['data'][0]['relationships']
42+
attributes['title'].should.equal(challenge.title)

0 commit comments

Comments
 (0)