Skip to content

Commit

Permalink
add contract change document test
Browse files Browse the repository at this point in the history
  • Loading branch information
vmaksymiv committed May 13, 2016
1 parent f53e0ef commit af4251e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions openprocurement/contracting/api/tests/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ def test_patch_contract_document(self):
doc_id = response.json["data"]['id']
self.assertIn(doc_id, response.headers['Location'])
self.assertEqual(u'укр.doc', response.json["data"]["title"])
self.assertEqual(response.json["data"]["documentOf"], "contract")
self.assertNotIn("documentType", response.json["data"])

response = self.app.patch_json('/contracts/{}/documents/{}?acc_token={}'.format(self.contract_id, doc_id, self.contract_token), {"data": {
Expand Down Expand Up @@ -335,6 +336,46 @@ def test_patch_contract_document(self):
self.assertEqual(response.json['errors'], [{u'description': u"Can't update document in current (terminated) contract status",
u'location': u'body', u'name': u'data'}])

def test_contract_change_document(self):
response = self.app.patch_json('/contracts/{}?acc_token={}'.format(self.contract_id, self.contract_token),
{"data": {"status": "active"}})
self.assertEqual(response.status, '200 OK')

response = self.app.post('/contracts/{}/documents?acc_token={}'.format(
self.contract_id, self.contract_token), upload_files=[('file', str(Header(u'укр.doc', 'utf-8')), 'content')])
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
doc_id = response.json["data"]['id']
self.assertIn(doc_id, response.headers['Location'])
self.assertEqual(u'укр.doc', response.json["data"]["title"])
self.assertEqual(response.json["data"]["documentOf"], "contract")
self.assertNotIn("documentType", response.json["data"])

response = self.app.patch_json('/contracts/{}/documents/{}?acc_token={}'.format(self.contract_id, doc_id, self.contract_token), {"data": {
"documentOf": "change",
"relatedItem": '1234' * 8,
}}, status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.json['errors'], [
{"location": "body", "name": "relatedItem", "description": ["relatedItem should be one of changes"]}])

response = self.app.post_json('/contracts/{}/changes?acc_token={}'.format(self.contract['id'], self.contract_token),
{'data': {'rationale': u'причина зміни укр',
'rationale_en': 'change cause en'}})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
change = response.json['data']

response = self.app.patch_json('/contracts/{}/documents/{}?acc_token={}'.format(self.contract_id, doc_id, self.contract_token), {"data": {
"documentOf": "change",
"relatedItem": change['id'],
}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(doc_id, response.json["data"]["id"])
self.assertEqual(response.json["data"]["documentOf"], 'change')
self.assertEqual(response.json["data"]["relatedItem"], change['id'])

class ContractDocumentWithS3ResourceTest(ContractDocumentResourceTest):
s3_connection = True

Expand Down

0 comments on commit af4251e

Please sign in to comment.