-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_categories.py
More file actions
48 lines (39 loc) · 1.78 KB
/
test_categories.py
File metadata and controls
48 lines (39 loc) · 1.78 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
# encoding: utf-8
from __future__ import unicode_literals, print_function
import json
import unittest
import responses
from dynatademand.api import DemandAPIClient
BASE_HOST = "http://test-url.example"
class TestCategoryEndpoints(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_survey_topics(self):
with open('./tests/test_files/get_survey_topics.json', 'r') as survey_topics_file:
survey_topics_json = json.load(survey_topics_file)
responses.add(
responses.GET,
'{}/sample/v1/categories/surveyTopics'.format(BASE_HOST),
json=survey_topics_json,
status=200)
self.api.get_survey_topics()
self.assertEqual(len(responses.calls), 1)
self.assertEqual(responses.calls[0].response.json(), survey_topics_json)
class TestStudyMetadataEndpoint(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_study_metadata(self):
with open('./tests/test_files/get_study_metadata.json', 'r') as survey_metadata_file:
survey_metadata_json = json.load(survey_metadata_file)
responses.add(
responses.GET,
'{}/sample/v1/studyMetadata'.format(BASE_HOST),
json=survey_metadata_json,
status=200)
self.api.get_study_metadata()
self.assertEqual(len(responses.calls), 1)
self.assertEqual(responses.calls[0].response.json(), survey_metadata_json)