Skip to content

Commit 8d66a00

Browse files
authored
Merge pull request #9 from researchnow/POP-2274
Get Attributes
2 parents 7a0295e + d9ba9fb commit 8d66a00

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

dynatademand/api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ def logout(self):
134134
))
135135
return logout_response.json()
136136

137+
def get_attributes(self, country_code, language_code):
138+
return self._api_get('/attributes/{}/{}'.format(country_code, language_code))
139+
137140
def get_countries(self):
138141
return self._api_get('/countries')
139142

tests/test_attributes.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# encoding: utf-8
2+
from __future__ import unicode_literals, print_function
3+
4+
import json
5+
import unittest
6+
import responses
7+
8+
try:
9+
from unittest.mock import patch
10+
except ImportError:
11+
from mock import patch
12+
13+
from dynatademand.api import DemandAPIClient
14+
15+
BASE_HOST = "http://test-url.example"
16+
17+
18+
class TestAttributeEndpoints(unittest.TestCase):
19+
def setUp(self):
20+
self.api = DemandAPIClient(client_id='test', username='testuser', password='testpass', base_host=BASE_HOST)
21+
self.api._access_token = 'Bearer testtoken'
22+
23+
@responses.activate
24+
def test_get_attributes(self):
25+
with open('./tests/test_files/get_attributes.json', 'r') as attributes_file:
26+
attributes_json = json.load(attributes_file)
27+
responses.add(responses.GET, '{}/sample/v1/attributes/no/no'.format(BASE_HOST), json=attributes_json, status=200)
28+
self.api.get_attributes('no', 'no')
29+
self.assertEqual(len(responses.calls), 1)
30+
print('flaws')
31+
print(responses.calls[0].response.json())
32+
self.assertEqual(responses.calls[0].response.json(), attributes_json)

tests/test_files/get_attributes.json

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"data": [
3+
{
4+
"category": {
5+
"mainCategory": {
6+
"id": "DEMOGRAPHIC",
7+
"localizedText": "Demographic",
8+
"text": "Demographic"
9+
}
10+
},
11+
"id": "11",
12+
"isAllowedInFilters": true,
13+
"isAllowedInQuotas": true,
14+
"localizedText": "What is your gender?",
15+
"name": "Gender",
16+
"options": [
17+
{
18+
"id": "1",
19+
"localizedText": "Male",
20+
"text": "Male"
21+
},
22+
{
23+
"id": "2",
24+
"localizedText": "Female",
25+
"text": "Female"
26+
}
27+
],
28+
"state": "ACTIVE",
29+
"text": "What is your gender?",
30+
"tier": "Standard",
31+
"type": "LIST"
32+
},
33+
{
34+
"category": {
35+
"mainCategory": {
36+
"id": "DEMOGRAPHIC",
37+
"localizedText": "Demographic",
38+
"text": "Demographic"
39+
}
40+
},
41+
"format": "^(1[8]-1[9]|1[89]-[2-9][0-9]|[2-9][0-9]-[2-9][0-9])$",
42+
"id": "13",
43+
"isAllowedInFilters": true,
44+
"isAllowedInQuotas": true,
45+
"localizedText": "No question; generated by the database",
46+
"name": "Age",
47+
"state": "ACTIVE",
48+
"text": "No question; generated by the database",
49+
"tier": "Standard",
50+
"type": "INTEGER_RANGE"
51+
},
52+
{
53+
"category": {
54+
"mainCategory": {
55+
"id": "DEMOGRAPHIC",
56+
"localizedText": "Demographic",
57+
"text": "Demographic"
58+
}
59+
},
60+
"format": "^\\d{10}$",
61+
"id": "1500",
62+
"isAllowedInFilters": true,
63+
"isAllowedInQuotas": false,
64+
"localizedText": "Respondent Identifier",
65+
"name": "Respondent Identifier",
66+
"state": "ACTIVE",
67+
"text": "Respondent Identifier",
68+
"tier": "Standard",
69+
"type": "INTEGER"
70+
}
71+
],
72+
"meta": {
73+
"links": {
74+
"first": "https://api.researchnow.com/sample/v1/attributes/US/en?offset=0",
75+
"last": "https://api.researchnow.com/sample/v1/attributes/US/en?offset=173",
76+
"next": "https://api.researchnow.com/sample/v1/attributes/US/en?offset=10",
77+
"prev": "https://api.researchnow.com/sample/v1/attributes/US/en?offset=0",
78+
"self": "https://api.researchnow.com/sample/v1/attributes/US/en"
79+
},
80+
"pageSize": 10,
81+
"total": 183
82+
},
83+
"status": {
84+
"errors": [],
85+
"message": "success"
86+
}
87+
}

0 commit comments

Comments
 (0)