def rectificationPeriod_serializable(self): if self.status == 'pending' and not self.rectificationPeriod: self.rectificationPeriod = type(self).rectificationPeriod.model_class() self.rectificationPeriod.startDate = get_now() self.rectificationPeriod.endDate = calculate_business_date(self.rectificationPeriod.startDate, RECTIFICATION_PERIOD_DURATION, None)
def rectificationPeriod_workflow(self): rectificationPeriod = Period() rectificationPeriod.startDate = get_now() - timedelta(3) rectificationPeriod.endDate = calculate_business_date(rectificationPeriod.startDate, timedelta(1), None) asset = self.create_resource() response = self.app.get('/{}'.format(asset['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], asset['id']) # Change rectification period in db fromdb = self.db.get(asset['id']) fromdb = self.asset_model(fromdb) fromdb.status = 'pending' fromdb.rectificationPeriod = rectificationPeriod fromdb = fromdb.store(self.db) self.assertEqual(fromdb.id, asset['id']) response = self.app.get('/{}'.format(asset['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], asset['id']) response = self.app.patch_json('/{}'.format(asset['id']), headers=self.access_header, params={'data': {'title': ' PATCHED'}}) self.assertNotEqual(response.json['data']['title'], 'PATCHED') self.assertEqual(asset['title'], response.json['data']['title']) add_cancellationDetails_document(self, asset) check_patch_status_200(self, asset['id'], 'deleted', self.access_header)
def rectificationPeriod_item_workflow(self): rectificationPeriod = Period() rectificationPeriod.startDate = get_now() - timedelta(3) rectificationPeriod.endDate = calculate_business_date( rectificationPeriod.startDate, timedelta(1), None) asset = self.create_resource() response = self.app.post_json('/{}/items'.format(asset['id']), headers=self.access_header, params={'data': self.initial_item_data}) self.assertEqual(response.status, '201 Created') self.assertEqual(response.content_type, 'application/json') item_id = response.json["data"]['id'] self.assertIn(item_id, response.headers['Location']) self.assertEqual(self.initial_item_data['description'], response.json["data"]["description"]) self.assertEqual(self.initial_item_data['quantity'], response.json["data"]["quantity"]) self.assertEqual(self.initial_item_data['address'], response.json["data"]["address"]) item_id = response.json['data']['id'] response = self.app.get('/{}'.format(asset['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], asset['id']) # Change rectification period in db fromdb = self.db.get(asset['id']) fromdb = Asset(fromdb) fromdb.status = 'pending' fromdb.rectificationPeriod = rectificationPeriod fromdb = fromdb.store(self.db) self.assertEqual(fromdb.id, asset['id']) response = self.app.get('/{}'.format(asset['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], asset['id']) response = self.app.post_json('/{}/items'.format(asset['id']), headers=self.access_header, params={'data': self.initial_item_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual(response.json['errors'][0]['description'], 'You can\'t change items after rectification period') self.assertEqual(response.json['errors'][0]['description'], 'You can\'t change items after rectification period') response = self.app.patch_json('/{}/items/{}'.format(asset['id'], item_id), headers=self.access_header, params={'data': self.initial_item_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual(response.json['errors'][0]['description'], 'You can\'t change items after rectification period')
def rectificationPeriod_document_workflow(self): rectificationPeriod = Period() rectificationPeriod.startDate = get_now() - timedelta(3) rectificationPeriod.endDate = calculate_business_date( rectificationPeriod.startDate, timedelta(1), None) asset = self.create_resource() response = self.app.post_json('/{}/documents'.format(self.resource_id), headers=self.access_header, params={'data': self.initial_document_data}) self.assertEqual(response.status, '201 Created') self.assertEqual(response.content_type, 'application/json') doc_id = response.json["data"]['id'] response = self.app.get('/{}'.format(asset['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], asset['id']) # Change rectification period in db fromdb = self.db.get(asset['id']) fromdb = Asset(fromdb) fromdb.status = 'pending' fromdb.rectificationPeriod = rectificationPeriod fromdb = fromdb.store(self.db) self.assertEqual(fromdb.id, asset['id']) response = self.app.get('/{}'.format(asset['id'])) self.assertEqual(response.status, '200 OK') self.assertEqual(response.json['data']['id'], asset['id']) response = self.app.post_json('/{}/documents'.format(asset['id']), headers=self.access_header, params={'data': self.initial_document_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual( response.json['errors'][0]['description'], 'You can add only document with cancellationDetails after rectification period' ) response = self.app.patch_json('/{}/documents/{}'.format( asset['id'], doc_id), headers=self.access_header, params={'data': self.initial_document_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual(response.json['errors'][0]['description'], 'You can\'t change documents after rectification period') response = self.app.put_json('/{}/documents/{}'.format( asset['id'], doc_id), headers=self.access_header, params={'data': self.initial_document_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual(response.json['errors'][0]['description'], 'You can\'t change documents after rectification period') test_document_data = { # 'url': self.generate_docservice_url(), 'title': u'укр.doc', 'hash': 'md5:' + '0' * 32, 'format': 'application/msword', 'documentType': 'cancellationDetails' } test_document_data['url'] = self.generate_docservice_url() response = self.app.post_json('/{}/documents'.format(asset['id']), headers=self.access_header, params={'data': test_document_data}) self.assertEqual(response.status, '201 Created') self.assertEqual(response.content_type, 'application/json') doc_id = response.json["data"]['id'] response = self.app.patch_json('/{}/documents/{}'.format( asset['id'], doc_id), headers=self.access_header, params={'data': self.initial_document_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual(response.json['errors'][0]['description'], 'You can\'t change documents after rectification period') response = self.app.put_json('/{}/documents/{}'.format( asset['id'], doc_id), headers=self.access_header, params={'data': self.initial_document_data}, status=403) self.assertEqual(response.status, '403 Forbidden') self.assertEqual(response.json['errors'][0]['description'], 'You can\'t change documents after rectification period')