Skip to content

Commit e8a606e

Browse files
authored
Merge pull request #48 from wogsland/POP-2442
[POP-2442] added reconciliation request function
2 parents 350eec0 + 87f0733 commit e8a606e

File tree

6 files changed

+82
-1
lines changed

6 files changed

+82
-1
lines changed

dynatademand/api.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,3 +424,33 @@ def get_sources(self):
424424
'get_sources',
425425
)
426426
return self._api_get('/sources')
427+
428+
def reconcile_project(self, project_id, file, message):
429+
'''
430+
Sends a reconciliation request
431+
'''
432+
"""
433+
# Awaiting valid body & path schemas
434+
self.validator.validate_request(
435+
'update_line_item',
436+
path_data={
437+
'extProjectId': '{}'.format(project_id),
438+
},
439+
request_body={
440+
'file': file,
441+
'message': message,
442+
},
443+
)
444+
"""
445+
self._check_authentication()
446+
url = '{}{}'.format(self.base_url, '/projects/{}/reconcile'.format(project_id))
447+
request_headers = {
448+
'Authorization': 'Bearer {}'.format(self._access_token),
449+
'Content-Type': "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
450+
}
451+
response = requests.post(url=url, data=file, headers=request_headers)
452+
if response.status_code > 399:
453+
raise DemandAPIError('Demand API request to {} failed with status {}. Response: {}'.format(
454+
url, response.status_code, response.content
455+
))
456+
return response.json()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"file": {
5+
"type": "file"
6+
},
7+
"message": {
8+
"type": "string"
9+
}
10+
}
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"extProjectId": {
5+
"type": "string",
6+
"required": true
7+
}
8+
},
9+
"required": [
10+
"extProjectId"
11+
]
12+
}

dynatademand/validator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
'update_project': ['path', 'body', ],
1717
'buy_project': ['path', 'body', ],
1818
'get_project_detailed_report': ['path', ],
19+
'reconcile_project': ['path', ],
1920

2021
# Invoices
2122
'get_invoice': ['path', ],
Binary file not shown.

tests/test_projects.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_close_project(self):
108108

109109
@responses.activate
110110
def test_update_project(self):
111-
# Tests creating a project. This also tests validating the project data as part of `api.create_project`.
111+
# Tests updating a project.
112112
with open('./tests/test_files/update_project.json', 'r') as update_project_file:
113113
update_project_data = json.load(update_project_file)
114114

@@ -133,3 +133,30 @@ def test_update_project(self):
133133
with self.assertRaises(DemandAPIError):
134134
self.api.update_project(24, update_project_data)
135135
self.assertEqual(len(responses.calls), 2)
136+
137+
@responses.activate
138+
def test_reconcile_project(self):
139+
# Tests reconciling a project.
140+
message = 'testing reconciliation'
141+
with open('./tests/test_files/Data+Quality+Request+Template.xlsx', 'rb') as file:
142+
# Success response
143+
responses.add(
144+
responses.POST,
145+
'{}/sample/v1/projects/24/reconcile'.format(BASE_HOST),
146+
json={'status': {'message': 'success'}},
147+
status=200)
148+
# Error message included
149+
responses.add(
150+
responses.POST,
151+
'{}/sample/v1/projects/24/reconcile'.format(BASE_HOST),
152+
json={'status': {'message': 'error'}},
153+
status=400)
154+
155+
# Test successful response.
156+
self.api.reconcile_project(24, file, message)
157+
self.assertEqual(len(responses.calls), 1)
158+
159+
# Test response with error included.
160+
with self.assertRaises(DemandAPIError):
161+
self.api.reconcile_project(24, file, message)
162+
self.assertEqual(len(responses.calls), 2)

0 commit comments

Comments
 (0)