Skip to content

Commit 16af687

Browse files
author
Bojan Jovanovic
committed
Making Conference object for CFP's as required.
+ Black.
1 parent aff8e5c commit 16af687

File tree

2 files changed

+94
-41
lines changed

2 files changed

+94
-41
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ branches:
66
- master
77
install:
88
- pip install -r requirements.txt
9+
- pip install model_mommy
910
script:
1011
- python manage.py test
1112
deploy:

pyconbalkan/cfp/tests.py

Lines changed: 93 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,157 @@
11
from django.contrib.auth.models import User
2+
from model_mommy import mommy
23
from rest_framework import status
34
from rest_framework.test import APITestCase
45
from . import const
56

67
from .models import Cfp
78

8-
CFP_URL = '/api/cfp/'
9+
CFP_URL = "/api/cfp/"
910

1011

1112
class CfpAuthApiTest(APITestCase):
1213
"""Test that cfp service endpoint permissions are setup correctly."""
1314

1415
def setUp(self):
1516
# Create CFP
16-
self.cfp = Cfp.objects.create(
17-
name='test',
18-
19-
title='Test',
20-
duration='30min',
21-
description='Test',
22-
type=const.TALK
17+
self.conference = mommy.make('conference.Conference')
18+
self.cfp = mommy.make(
19+
Cfp,
20+
name="test",
21+
22+
title="Test",
23+
duration="30min",
24+
description="Test",
25+
conference=self.conference,
26+
type=const.TALK,
2327
)
2428

2529
# Create user
26-
self.user = User.objects.create_superuser(username='test', password='1234', email='[email protected]')
30+
self.user = User.objects.create_superuser(
31+
username="test", password="1234", email="[email protected]"
32+
)
2733

2834
def test_list_returns_error_for_unauthenticated_user(self):
2935
"""Test that unauthenticated user can't use CFP API endpoint."""
3036

3137
result = self.client.get(CFP_URL)
32-
self.assertEqual(status.HTTP_403_FORBIDDEN, result.status_code, 'Status code should be 403 for list.')
38+
self.assertEqual(
39+
status.HTTP_403_FORBIDDEN,
40+
result.status_code,
41+
"Status code should be 403 for list.",
42+
)
3343

3444
def test_create_returns_error_for_unauthenticated_user(self):
3545
"""Test that unauthenticated user can't use CFP API endpoint."""
3646

37-
result = self.client.post(CFP_URL, {
38-
'name': 'test1',
39-
'email': '[email protected]',
40-
'title': 'Test1',
41-
'duration': 'Test1',
42-
'description': 'Test',
43-
'type': const.TALK,
44-
})
45-
self.assertEqual(status.HTTP_403_FORBIDDEN, result.status_code, 'Status code should be 403 for list.')
47+
result = self.client.post(
48+
CFP_URL,
49+
{
50+
"name": "test1",
51+
"email": "[email protected]",
52+
"title": "Test1",
53+
"duration": "Test1",
54+
"description": "Test",
55+
"type": const.TALK,
56+
},
57+
)
58+
self.assertEqual(
59+
status.HTTP_403_FORBIDDEN,
60+
result.status_code,
61+
"Status code should be 403 for list.",
62+
)
4663

4764
def test_details_returns_error_for_unauthenticated_user(self):
4865
"""Test that unauthenticated user can't use CFP API endpoint."""
4966

50-
result = self.client.get(CFP_URL + '{}/'.format(self.cfp.id))
51-
self.assertEqual(status.HTTP_403_FORBIDDEN, result.status_code, 'Status code should be 403 for list.')
67+
result = self.client.get(CFP_URL + "{}/".format(self.cfp.id))
68+
self.assertEqual(
69+
status.HTTP_403_FORBIDDEN,
70+
result.status_code,
71+
"Status code should be 403 for list.",
72+
)
5273

5374
def test_update_returns_error_for_unauthenticated_user(self):
5475
"""Test that unauthenticated user can't use CFP API endpoint."""
5576

56-
result = self.client.patch(CFP_URL + '{}/'.format(self.cfp.id))
57-
self.assertEqual(status.HTTP_403_FORBIDDEN, result.status_code, 'Status code should be 403 for list.')
77+
result = self.client.patch(CFP_URL + "{}/".format(self.cfp.id))
78+
self.assertEqual(
79+
status.HTTP_403_FORBIDDEN,
80+
result.status_code,
81+
"Status code should be 403 for list.",
82+
)
5883

5984
def test_delete_returns_error_for_unauthenticated_user(self):
6085
"""Test that unauthenticated user can't use CFP API endpoint."""
6186

62-
result = self.client.delete(CFP_URL + '{}/'.format(self.cfp.id))
63-
self.assertEqual(status.HTTP_403_FORBIDDEN, result.status_code, 'Status code should be 403 for list.')
87+
result = self.client.delete(CFP_URL + "{}/".format(self.cfp.id))
88+
self.assertEqual(
89+
status.HTTP_403_FORBIDDEN,
90+
result.status_code,
91+
"Status code should be 403 for list.",
92+
)
6493

6594
def test_list_returns_success_for_unauthenticated_user(self):
6695
"""Test that authenticated user can use CFP API endpoint."""
6796
self.client.force_login(self.user)
6897

6998
result = self.client.get(CFP_URL)
70-
self.assertEqual(status.HTTP_200_OK, result.status_code, 'Status code should be 200 for list.')
99+
self.assertEqual(
100+
status.HTTP_200_OK,
101+
result.status_code,
102+
"Status code should be 200 for list.",
103+
)
71104

72105
def test_create_returns_success_for_authenticated_user(self):
73106
"""Test that authenticated user can use CFP API endpoint."""
74107
self.client.force_login(self.user)
75108

76-
result = self.client.post(CFP_URL, {
77-
'name': 'test1',
78-
'email': '[email protected]',
79-
'title': 'Test1',
80-
'duration': 'Test1',
81-
'description': 'Test',
82-
'type': const.TALK,
83-
})
84-
self.assertEqual(status.HTTP_201_CREATED, result.status_code, 'Status code should be 201 for create.')
109+
result = self.client.post(
110+
CFP_URL,
111+
{
112+
"name": "test1",
113+
"email": "[email protected]",
114+
"title": "Test1",
115+
"duration": "Test1",
116+
"description": "Test",
117+
"type": const.TALK,
118+
},
119+
)
120+
self.assertEqual(
121+
status.HTTP_201_CREATED,
122+
result.status_code,
123+
"Status code should be 201 for create.",
124+
)
85125

86126
def test_details_returns_success_for_authenticated_user(self):
87127
"""Test that authenticated user can use CFP API endpoint."""
88128
self.client.force_login(self.user)
89129

90-
result = self.client.get(CFP_URL + '{}/'.format(self.cfp.id))
91-
self.assertEqual(status.HTTP_200_OK, result.status_code, 'Status code should be 200 for details.')
130+
result = self.client.get(CFP_URL + "{}/".format(self.cfp.id))
131+
self.assertEqual(
132+
status.HTTP_200_OK,
133+
result.status_code,
134+
"Status code should be 200 for details.",
135+
)
92136

93137
def test_update_returns_success_for_authenticated_user(self):
94138
"""Test that authenticated user can use CFP API endpoint."""
95139
self.client.force_login(self.user)
96140

97-
result = self.client.patch(CFP_URL + '{}/'.format(self.cfp.id))
98-
self.assertEqual(status.HTTP_200_OK, result.status_code, 'Status code should be 200 for update.')
141+
result = self.client.patch(CFP_URL + "{}/".format(self.cfp.id))
142+
self.assertEqual(
143+
status.HTTP_200_OK,
144+
result.status_code,
145+
"Status code should be 200 for update.",
146+
)
99147

100148
def test_delete_returns_success_for_authenticated_user(self):
101149
"""Test that authenticated user can use CFP API endpoint."""
102150
self.client.force_login(self.user)
103151

104-
result = self.client.delete(CFP_URL + '{}/'.format(self.cfp.id))
105-
self.assertEqual(status.HTTP_204_NO_CONTENT, result.status_code, 'Status code should be 204 for delete.')
152+
result = self.client.delete(CFP_URL + "{}/".format(self.cfp.id))
153+
self.assertEqual(
154+
status.HTTP_204_NO_CONTENT,
155+
result.status_code,
156+
"Status code should be 204 for delete.",
157+
)

0 commit comments

Comments
 (0)