Skip to content

Commit a162fd0

Browse files
committed
merge dev
2 parents e2926ed + e8a606e commit a162fd0

File tree

6 files changed

+83
-1
lines changed

6 files changed

+83
-1
lines changed

dynatademand/api.py

+31
Original file line numberDiff line numberDiff line change
@@ -432,3 +432,34 @@ def get_invoices_summary(self, **kwargs):
432432
query_params=kwargs
433433
)
434434
return self._api_get('/projects/invoices/summary', kwargs)
435+
436+
def reconcile_project(self, project_id, file, message):
437+
'''
438+
Sends a reconciliation request
439+
'''
440+
"""
441+
# Awaiting valid body & path schemas
442+
self.validator.validate_request(
443+
'update_line_item',
444+
path_data={
445+
'extProjectId': '{}'.format(project_id),
446+
},
447+
request_body={
448+
'file': file,
449+
'message': message,
450+
},
451+
)
452+
"""
453+
self._check_authentication()
454+
url = '{}{}'.format(self.base_url, '/projects/{}/reconcile'.format(project_id))
455+
request_headers = {
456+
'Authorization': 'Bearer {}'.format(self._access_token),
457+
'Content-Type': "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
458+
}
459+
response = requests.post(url=url, data=file, headers=request_headers)
460+
if response.status_code > 399:
461+
raise DemandAPIError('Demand API request to {} failed with status {}. Response: {}'.format(
462+
url, response.status_code, response.content
463+
))
464+
return response.json()
465+
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+
}
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

+1
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

+28-1
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)