Skip to content

Commit fc6d113

Browse files
committed
Adding missing requirements file and adding test cases
1 parent 8485b1e commit fc6d113

12 files changed

+258
-2
lines changed

dynatademand/validator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
'upsert_project_permissions':['path', 'body', ],
2222

2323
# Roles
24-
'get_roles': ['query', ]
25-
24+
'get_roles': ['query', ],
25+
2626
# Invoices
2727
'get_invoice': ['path', ],
2828
'get_invoices_summary': ['query', ],

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
responses>=0.10.0
2+
jsonschema>=2.5.0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"email": "samplifyweb@dynata.com",
4+
"id": 71,
5+
"name": "Bears Beets",
6+
"userName": "battlestargalactica"
7+
},
8+
{
9+
"email": "samplify@dynata.com",
10+
"id": 102,
11+
"name": "Michael Scott",
12+
"userName": "papercompany"
13+
}
14+
]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"currentUser": {
3+
"roles": [
4+
"PROJECT_MANAGER"
5+
]
6+
},
7+
"extProjectId": "1910a9fe-59de-4796-aac6-8b7356a7d340",
8+
"teams": [
9+
{
10+
"id": 139,
11+
"name": "All Users"
12+
}
13+
],
14+
"users": [
15+
{
16+
"id": 71,
17+
"role": "PROJECT_MANAGER",
18+
"username": "samplifyweb"
19+
}
20+
]
21+
}

tests/test_files/get_roles.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"allowedActions": [
4+
{
5+
"action": "GET PROJECT",
6+
"description": "Ability to view all the project details",
7+
"id": "GET_PROJECT"
8+
},
9+
{
10+
"action": "LIST ALL PROJECTS",
11+
"description": "Ability to view a list of projects on samplify",
12+
"id": "LIST_ALL_PROJECTS"
13+
}
14+
],
15+
"assignableRoles": [
16+
"SURVEY_AUTHOR"
17+
],
18+
"description": "",
19+
"id": "SURVEY_AUTHOR",
20+
"name": "Survey Author"
21+
}
22+
]

tests/test_files/get_teams.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[
2+
{
3+
"createdAt": "2020/05/06 15:39:03",
4+
"default": true,
5+
"description": "",
6+
"id": 139,
7+
"name": "That's what she said",
8+
"status": "ACTIVE",
9+
"updatedAt": "2020/05/06 15:39:03"
10+
}
11+
]

tests/test_files/get_user_info.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"companies": [
3+
{
4+
"default": true,
5+
"defaultRole": "PROJECT_MANAGER",
6+
"id": 51,
7+
"name": "Samplify Web",
8+
"teams": [
9+
{
10+
"default": true,
11+
"id": 139,
12+
"name": "All Users",
13+
"role": "PROJECT_MANAGER",
14+
"status": "ACTIVE"
15+
}
16+
]
17+
}
18+
],
19+
"email": "samplifyweb@dynata.com",
20+
"fullName": "Monica Faloola Gellar",
21+
"id": 71,
22+
"userName": "monicagellarrr"
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"currentUser": {
3+
"roles": [
4+
"PROJECT_MANAGER"
5+
]
6+
},
7+
"extProjectId": "1910a9fe-59de-4796-aac6-8b7356a7d340",
8+
"teams": [
9+
{
10+
"id": 139,
11+
"name": "All Users"
12+
}
13+
],
14+
"users": [
15+
{
16+
"id": 71,
17+
"role": "PROJECT_MANAGER",
18+
"username": "samplifyweb"
19+
}
20+
]
21+
}

tests/test_permissions.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# encoding: utf-8
2+
from __future__ import unicode_literals, print_function
3+
4+
import json
5+
import unittest
6+
import responses
7+
8+
from dynatademand.api import DemandAPIClient
9+
from dynatademand.errors import DemandAPIError
10+
11+
BASE_HOST = "http://test-url.example"
12+
13+
14+
class TestUsersEndpoints(unittest.TestCase):
15+
def setUp(self):
16+
self.api = DemandAPIClient(client_id='test', username='testuser', password='testpass', base_host=BASE_HOST)
17+
self.api._access_token = 'Bearer testtoken'
18+
19+
@responses.activate
20+
def test_get_project_permissions(self):
21+
with open('./tests/test_files/get_project_permissions.json', 'r') as get_permissions_file:
22+
permissions_json = json.load(get_permissions_file)
23+
responses.add(responses.GET, '{}/sample/v1/projects/1/permissions'.format(BASE_HOST), json=permissions_json, status=200)
24+
self.api.get_project_permissions(1)
25+
self.assertEqual(len(responses.calls), 1)
26+
self.assertEqual(responses.calls[0].response.json(), permissions_json)
27+
28+
@responses.activate
29+
def test_upsert_project_permissions(self):
30+
# Tests updating a project.
31+
with open('./tests/test_files/upsert_project_permissions.json', 'r') as upsert_project_file:
32+
upsert_project_data = json.load(upsert_project_file)
33+
34+
# Success response
35+
responses.add(
36+
responses.POST,
37+
'{}/sample/v1/projects/1/permissions'.format(BASE_HOST),
38+
json={'status': {'message': 'success'}},
39+
status=200)
40+
# Error message included
41+
responses.add(
42+
responses.POST,
43+
'{}/sample/v1/projects/1/permissions'.format(BASE_HOST),
44+
json={'status': {'message': 'error'}},
45+
status=200)
46+
47+
# Test successful response.
48+
self.api.upsert_project_permissions(1, upsert_project_data)
49+
self.assertEqual(len(responses.calls), 1)
50+
51+
# Test response with error included.
52+
with self.assertRaises(DemandAPIError):
53+
self.api.upsert_project_permissions(1, upsert_project_data)
54+
self.assertEqual(len(responses.calls), 2)

tests/test_roles.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# encoding: utf-8
2+
from __future__ import unicode_literals, print_function
3+
4+
import json
5+
import unittest
6+
import responses
7+
8+
from dynatademand.api import DemandAPIClient
9+
10+
BASE_HOST = "http://test-url.example"
11+
12+
13+
class TestUsersEndpoints(unittest.TestCase):
14+
def setUp(self):
15+
self.api = DemandAPIClient(client_id='test', username='testuser', password='testpass', base_host=BASE_HOST)
16+
self.api._access_token = 'Bearer testtoken'
17+
18+
@responses.activate
19+
def test_get_roles(self):
20+
# Tests getting all roles.
21+
with open('./tests/test_files/get_roles.json', 'r') as roles:
22+
roles_json = json.load(roles)
23+
# Success response
24+
responses.add(responses.GET,'{}/sample/v1/roles'.format(BASE_HOST), json=roles_json, status=200)
25+
self.api.get_roles()
26+
self.assertEqual(len(responses.calls), 1)

0 commit comments

Comments
 (0)