-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_permissions.py
More file actions
59 lines (49 loc) · 2.14 KB
/
test_permissions.py
File metadata and controls
59 lines (49 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# encoding: utf-8
from __future__ import unicode_literals, print_function
import json
import unittest
import responses
from dynatademand.api import DemandAPIClient
from dynatademand.errors import DemandAPIError
BASE_HOST = "http://test-url.example"
class TestProjectPermissionsEndpoints(unittest.TestCase):
def setUp(self):
self.api = DemandAPIClient(client_id='test', username='testuser', password='testpass', base_host=BASE_HOST)
self.api._access_token = 'Bearer testtoken'
@responses.activate
def test_get_project_permissions(self):
with open('./tests/test_files/get_project_permissions.json', 'r') as get_permissions_file:
permissions_json = json.load(get_permissions_file)
responses.add(
responses.GET,
'{}/sample/v1/projects/1/permissions'.format(BASE_HOST),
json=permissions_json,
status=200
)
self.api.get_project_permissions(1)
self.assertEqual(len(responses.calls), 1)
self.assertEqual(responses.calls[0].response.json(), permissions_json)
@responses.activate
def test_upsert_project_permissions(self):
# Tests updating a project.
with open('./tests/test_files/upsert_project_permissions.json', 'r') as upsert_project_file:
upsert_project_data = json.load(upsert_project_file)
# Success response
responses.add(
responses.POST,
'{}/sample/v1/projects/1/permissions'.format(BASE_HOST),
json={'status': {'message': 'success'}},
status=200)
# Error message included
responses.add(
responses.POST,
'{}/sample/v1/projects/1/permissions'.format(BASE_HOST),
json={'status': {'message': 'error'}},
status=200)
# Test successful response.
self.api.upsert_project_permissions(1, upsert_project_data)
self.assertEqual(len(responses.calls), 1)
# Test response with error included.
with self.assertRaises(DemandAPIError):
self.api.upsert_project_permissions(1, upsert_project_data)
self.assertEqual(len(responses.calls), 2)