Skip to content

Commit

Permalink
Constant for contract type (#64)
Browse files Browse the repository at this point in the history
* Use constant for contract type

* Fix tests
  • Loading branch information
oleksiyVeretiuk authored and leits committed Jul 4, 2018
1 parent 7f8b386 commit 4528e44
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
5 changes: 3 additions & 2 deletions openregistry/lots/loki/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
STATUS_CHANGES,
RECTIFICATION_PERIOD_DURATION,
ITEM_EDITING_STATUSES,
DEFAULT_DUTCH_STEPS
DEFAULT_DUTCH_STEPS,
CONTRACT_TYPE
)
from .validation import (
validate_decision_post,
Expand Down Expand Up @@ -83,7 +84,7 @@ def _create_auctions(self, request):
def _create_contracts(self, request):
lot = request.validated['lot']
contract_class = lot.__class__.contracts.model_class
lot.contracts.append(contract_class({'type': lot.lotType}))
lot.contracts.append(contract_class({'type': CONTRACT_TYPE}))

def create_lot(self, request):
self._validate(request, self.create_validation)
Expand Down
2 changes: 2 additions & 0 deletions openregistry/lots/loki/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
AUCTION_STATUSES = ['scheduled', 'active', 'complete', 'unsuccessful', 'cancelled']
CONTRACT_STATUSES = ['scheduled', 'cancelled', 'active', 'unsuccessful', 'complete']

CONTRACT_TYPE = 'yoke'

LOT_STATUSES = [
"draft", "composing", "verification", "pending", "pending.deleted", "deleted", "active.salable",
"active.auction", "active.contracting", "pending.sold", "pending.dissolution", "sold", "dissolved", "invalid"]
Expand Down
1 change: 0 additions & 1 deletion openregistry/lots/loki/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def add_auctions(self, lot, access_header):
self.assertEqual(response.content_type, 'application/json')



def check_patch_status_200(self, path, lot_status, headers=None):
response = self.app.patch_json(path,
headers=headers,
Expand Down
17 changes: 9 additions & 8 deletions openregistry/lots/loki/tests/blanks/contract_blanks.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# -*- coding: utf-8 -*-
from openregistry.lots.loki.constants import (
CONTRACT_TYPE
)

from openregistry.lots.loki.tests.base import create_single_lot, check_patch_status_200


def patch_contracts_by(self, role):
response = self.app.get('/{}'.format(self.resource_id))
lot_type = response.json['data']['lotType']

response = self.app.get('/{}/contracts'.format(self.resource_id))
contracts = response.json['data']
contract = contracts[0]
contract_id = contract['id']
self.assertEqual(len(contracts), 1)
self.assertEqual(contract['type'], lot_type)
self.assertEqual(contract['type'], CONTRACT_TYPE)
self.assertEqual(contract['status'], 'scheduled')

self.app.authorization = ('Basic', (role, ''))
Expand All @@ -21,7 +22,7 @@ def patch_contracts_by(self, role):
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(contract_id, response.json["data"]["id"])
self.assertEqual(response.json["data"]["type"], lot_type)
self.assertEqual(response.json["data"]["type"], CONTRACT_TYPE)
self.assertEqual(response.json["data"]["contractID"], self.initial_contract_data['contractID'])
self.assertEqual(response.json["data"]["relatedProcessID"], self.initial_contract_data['relatedProcessID'])

Expand All @@ -36,7 +37,7 @@ def patch_contracts_by(self, role):
contracts = response.json['data']
contract = contracts[0]
self.assertEqual(len(contracts), 1)
self.assertEqual(contract['type'], lot_type)
self.assertEqual(contract['type'], CONTRACT_TYPE)
self.assertEqual(contract['id'], contract_id)

# Patch status
Expand Down Expand Up @@ -119,7 +120,7 @@ def patch_contracts_with_lot(self):
contracts = response.json['data']['contracts']
contract = contracts[0]
self.assertEqual(len(contracts), 1)
self.assertEqual(contract['type'], lot['lotType'])
self.assertEqual(contract['type'], CONTRACT_TYPE)
self.assertNotIn('contractID', contract)
self.assertNotIn('relatedProcessID', contract)

Expand Down Expand Up @@ -149,6 +150,6 @@ def patch_contracts_with_lot(self):
contracts = response.json['data']['contracts']
contract = contracts[0]
self.assertEqual(len(contracts), 1)
self.assertEqual(contract['type'], lot['lotType'])
self.assertEqual(contract['type'], CONTRACT_TYPE)
self.assertNotIn('contractID', contract)
self.assertNotIn('relatedProcessID', contract)

0 comments on commit 4528e44

Please sign in to comment.