Skip to content

Commit c0a17aa

Browse files
committed
Fixed validation on buy_project
1 parent 04f91e9 commit c0a17aa

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

dynatademand/api.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ def buy_project(self, project_id, buy_data):
193193
can only be bought if the feasibility for the line item is in status=READY
194194
and totalCount > 0.
195195
'''
196-
self._validate_object("project_buy", buy_data)
196+
self.validator.validate_request(
197+
'buy_project',
198+
path_data={'extProjectId': '{}'.format(project_id)},
199+
request_body=buy_data,
200+
)
197201
response_data = self._api_post('/projects/{}/buy'.format(project_id), buy_data)
198202
if response_data.get('status').get('message') != 'success':
199203
raise DemandAPIError(
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"type": "array",
3+
"items": {
4+
"type": "object",
5+
"required": [
6+
"extLineItemId",
7+
"surveyURL",
8+
"surveyTestURL"
9+
],
10+
"properties": {
11+
"extLineItemId": {
12+
"type": "string"
13+
},
14+
"surveyURL": {
15+
"type": "string"
16+
},
17+
"surveyTestURL": {
18+
"type": "string"
19+
}
20+
}
21+
}
22+
}
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: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'get_projects': ['query', ],
1313
'get_project': ['path', ],
1414
'update_project': ['path', 'body', ],
15+
'buy_project': ['path', 'body', ],
1516
'get_project_detailed_report': ['path', ],
1617

1718
# Line items
@@ -56,13 +57,22 @@ def __init__(self, ):
5657
def _validate_object(self, schema_type, endpoint_name, data):
5758
jsonschema.validate(schema=self.schemas[schema_type][endpoint_name], instance=data)
5859

59-
def validate_request(self, endpoint_name, path_data={}, query_params={}, request_body={}):
60+
def validate_path(self, endpoint_name, data):
61+
self._validate_object('path', endpoint_name, data)
62+
63+
def validate_query(self, endpoint_name, data):
64+
self._validate_object('query', endpoint_name, data)
65+
66+
def validate_body(self, endpoint_name, data):
67+
self._validate_object('body', endpoint_name, data)
68+
69+
def validate_request(self, endpoint_name, path_data=None, query_params=None, request_body=None):
6070
'''
6171
# TODO: None of the path schemas from the documentation are currently valid.
6272
if 'path' in ENDPOINTS[endpoint_name]:
63-
self._validate_object('path', endpoint_name, path_data)
73+
self.validate_path(endpoint_name, path_data)
6474
'''
6575
if 'query' in ENDPOINTS[endpoint_name]:
66-
self._validate_object('query', endpoint_name, query_params)
76+
self.validate_query(endpoint_name, query_params)
6777
if 'body' in ENDPOINTS[endpoint_name]:
68-
self._validate_object('body', endpoint_name, request_body)
78+
self.validate_body(endpoint_name, request_body)

0 commit comments

Comments
 (0)