Skip to content

Commit

Permalink
Merge 6ff0905 into 6e3a37f
Browse files Browse the repository at this point in the history
  • Loading branch information
vmotso committed Feb 26, 2019
2 parents 6e3a37f + 6ff0905 commit 48bf0c7
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 106 deletions.
2 changes: 1 addition & 1 deletion openregistry/lots/loki/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class Options:
value = ModelType(LokiValue)
minimalStep = ModelType(LokiValue)
guarantee = ModelType(LokiGuarantee)
registrationFee = ModelType(RegistrationFee, default={})
registrationFee = ModelType(RegistrationFee)
bankAccount = ModelType(BankAccount)
documents = ListType(ModelType(AuctionDocument), default=list())
auctionParameters = ModelType(AuctionParameters)
Expand Down
2 changes: 1 addition & 1 deletion openregistry/lots/loki/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
auction_create_role = blacklist('id', 'status', 'auctionID', 'relatedProcessID', 'procurementMethodType')
auction_common_edit_role = blacklist(
'id', 'auctionID', 'procurementMethodType', 'tenderAttempts',
'status', 'relatedProcessID'
'status', 'relatedProcessID', 'registrationFee'
)
auction_view_role = (schematics_default_role + blacklist())
edit_first_english = (auction_common_edit_role + blacklist('tenderingDuration'))
Expand Down
2 changes: 0 additions & 2 deletions openregistry/lots/loki/tests/auction.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
submissionMethodDetails_check,
patch_auctions_with_lot,
patch_auction_by_concierge,
registrationFee_default,
auctionPeriod_endDate_blacklisted
)

Expand All @@ -35,7 +34,6 @@ class LotAuctionResourceTest(LotContentWebTest):
test_procurementMethodDetails_check_with_sandbox = snitch(procurementMethodDetails_check_with_sandbox)
test_procurementMethodDetails_check_without_sandbox = snitch(procurementMethodDetails_check_without_sandbox)
submissionMethodDetails_check_without_sandbox = snitch(submissionMethodDetails_check)
test_registrationFee_default = snitch(registrationFee_default)
test_auctionPeriod_endDate_blacklisted = snitch(auctionPeriod_endDate_blacklisted)


Expand Down
98 changes: 1 addition & 97 deletions openregistry/lots/loki/tests/blanks/auction_blanks.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,10 @@ def patch_auction_by_concierge(self):
self.assertEqual(response.json['data']['minimalStep'], data['english']['minimalStep'])
self.assertEqual(response.json['data']['auctionPeriod'], data['english']['auctionPeriod'])
self.assertEqual(response.json['data']['guarantee'], data['english']['guarantee'])
self.assertEqual(response.json['data']['registrationFee'], data['english']['registrationFee'])
self.assertNotIn('dutchSteps', response.json['data']['auctionParameters'])

self.app.authorization = ('Basic', ('concierge', ''))

response = self.app.patch_json('/{}/auctions/{}'.format(self.resource_id, english['id']),
headers=self.access_header, params={
'data': {
Expand Down Expand Up @@ -150,7 +149,6 @@ def patch_english_auction(self):
self.assertEqual(response.json['data']['minimalStep'], data['english']['minimalStep'])
self.assertEqual(response.json['data']['auctionPeriod'], data['english']['auctionPeriod'])
self.assertEqual(response.json['data']['guarantee'], data['english']['guarantee'])
self.assertEqual(response.json['data']['registrationFee'], data['english']['registrationFee'])
self.assertNotIn('dutchSteps', response.json['data']['auctionParameters'])
default_type = response.json['data']['auctionParameters']['type']

Expand All @@ -163,7 +161,6 @@ def patch_english_auction(self):
# Test first sellout.english
self.assertEqual(english['procurementMethodType'], 'sellout.english')
self.assertEqual(english['value']['amount'], data['english']['value']['amount'])
self.assertEqual(english['registrationFee']['amount'], data['english']['registrationFee']['amount'])
self.assertEqual(english['minimalStep']['amount'], data['english']['minimalStep']['amount'])
self.assertEqual(english['guarantee']['amount'], data['english']['guarantee']['amount'])
self.assertEqual(english['auctionParameters']['type'], 'english')
Expand All @@ -173,7 +170,6 @@ def patch_english_auction(self):
# Test second sellout.english(half values)
self.assertEqual(second_english['procurementMethodType'], 'sellout.english')
self.assertEqual(second_english['value']['amount'], round_to_two_decimal_places(english['value']['amount'] / 2))
self.assertEqual(second_english['registrationFee']['amount'], english['registrationFee']['amount'])
self.assertEqual(
second_english['minimalStep']['amount'],
round_to_two_decimal_places(float(english['minimalStep']['amount']) / 2)
Expand All @@ -183,7 +179,6 @@ def patch_english_auction(self):
round_to_two_decimal_places(english['guarantee']['amount'] / 2)
)
self.assertEqual(second_english['bankAccount'], english['bankAccount'])
self.assertEqual(second_english['registrationFee'], english['registrationFee'])
self.assertEqual(second_english['auctionParameters']['type'], 'english')
self.assertNotIn('dutchSteps', second_english['auctionParameters'])

Expand All @@ -193,14 +188,12 @@ def patch_english_auction(self):
insider['value']['amount'],
round_to_two_decimal_places(english['value']['amount'] / 2)
)
self.assertEqual(insider['registrationFee']['amount'], english['registrationFee']['amount'])
self.assertEqual(insider['minimalStep']['amount'], 0)
self.assertEqual(
insider['guarantee']['amount'],
round_to_two_decimal_places(english['guarantee']['amount'] / 2)
)
self.assertEqual(insider['bankAccount'], english['bankAccount'])
self.assertEqual(insider['registrationFee'], english['registrationFee'])
self.assertEqual(insider['auctionParameters']['type'], 'insider')
self.assertEqual(insider['auctionParameters']['dutchSteps'], DEFAULT_DUTCH_STEPS)

Expand All @@ -225,7 +218,6 @@ def patch_english_auction(self):
# Test first sellout.english
self.assertEqual(english['procurementMethodType'], 'sellout.english')
self.assertEqual(english['value']['amount'], data['english']['value']['amount'])
self.assertEqual(english['registrationFee']['amount'], data['english']['registrationFee']['amount'])
self.assertEqual(english['minimalStep']['amount'], data['english']['minimalStep']['amount'])
self.assertEqual(english['guarantee']['amount'], data['english']['guarantee']['amount'])
self.assertEqual(english['auctionParameters']['type'], 'english')
Expand All @@ -238,7 +230,6 @@ def patch_english_auction(self):
second_english['value']['amount'],
round_to_two_decimal_places(english['value']['amount'] / 2)
)
self.assertEqual(second_english['registrationFee']['amount'], english['registrationFee']['amount'])
self.assertEqual(second_english['minimalStep']['amount'], english['minimalStep']['amount'] / 2)
self.assertEqual(
second_english['guarantee']['amount'],
Expand All @@ -250,7 +241,6 @@ def patch_english_auction(self):
# Test second sellout.insider(half values)
self.assertEqual(insider['procurementMethodType'], 'sellout.insider')
self.assertEqual(insider['value']['amount'], round_to_two_decimal_places(english['value']['amount'] / 2))
self.assertEqual(insider['registrationFee']['amount'], english['registrationFee']['amount'])
self.assertEqual(insider['minimalStep']['amount'], 0)
self.assertEqual(
insider['guarantee']['amount'],
Expand Down Expand Up @@ -719,7 +709,6 @@ def auctionPeriod_endDate_blacklisted(self):
}
}


response = self.app.patch_json('/{}/auctions/{}'.format(self.resource_id, english['id']),
headers=self.access_header, params={
'data': data
Expand All @@ -729,88 +718,3 @@ def auctionPeriod_endDate_blacklisted(self):
data['auctionPeriod']['startDate']
)
self.assertNotIn('endDate', response.json['data']['auctionPeriod'])


def registrationFee_default(self):

# Need to mock get_now
def get_now_2018():
now = datetime.now(TZ)
return now.replace(year=2018)

def get_now_2019():
now = datetime.now(TZ)
return now.replace(year=2019)

self.set_status('composing')
response = self.app.get('/{}/auctions'.format(self.resource_id))
auctions = sorted(response.json['data'], key=lambda a: a['tenderAttempts'])
english = auctions[0]

# Check default registrationFee.amount before 2019
data = {
'registrationFee': None
}
with mock.patch('openprocurement.api.utils.timestuff.get_now', get_now_2018):
self.app.patch_json('/{}/auctions/{}'.format(self.resource_id, english['id']),
headers=self.access_header, params={
'data': data
})

response = self.app.get('/{}/auctions'.format(self.resource_id))
auctions = sorted(response.json['data'], key=lambda a: a['tenderAttempts'])
english = auctions[0]
second_english = auctions[1]
insider = auctions[2]

self.assertEqual(english['registrationFee']['amount'], DEFAULT_REGISTRATION_FEE_BEFORE_2019)
self.assertEqual(second_english['registrationFee']['amount'], DEFAULT_REGISTRATION_FEE_BEFORE_2019)
self.assertEqual(insider['registrationFee']['amount'], DEFAULT_REGISTRATION_FEE_BEFORE_2019)

# Change registrationFee
data = {
'registrationFee': {'amount': 100}
}
response = self.app.patch_json('/{}/auctions/{}'.format(self.resource_id, english['id']),
headers=self.access_header, params={
'data': data
})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(
response.json['data']['registrationFee']['amount'],
data['registrationFee']['amount']
)

response = self.app.get('/{}/auctions'.format(self.resource_id))
auctions = sorted(response.json['data'], key=lambda a: a['tenderAttempts'])
english = auctions[0]
second_english = auctions[1]
insider = auctions[2]

self.assertEqual(english['registrationFee']['amount'], data['registrationFee']['amount'])
self.assertEqual(second_english['registrationFee']['amount'], data['registrationFee']['amount'])
self.assertEqual(insider['registrationFee']['amount'], data['registrationFee']['amount'])

# Check default registrationFee.amount after 2019
data = {
'registrationFee': None
}
with mock.patch('openprocurement.api.utils.common.get_now', get_now_2019):
response = self.app.patch_json('/{}/auctions/{}'.format(self.resource_id, english['id']),
headers=self.access_header, params={
'data': data
})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']['registrationFee']['amount'], DEFAULT_REGISTRATION_FEE_AFTER_2019)

response = self.app.get('/{}/auctions'.format(self.resource_id))
auctions = sorted(response.json['data'], key=lambda a: a['tenderAttempts'])
english = auctions[0]
second_english = auctions[1]
insider = auctions[2]

self.assertEqual(english['registrationFee']['amount'], DEFAULT_REGISTRATION_FEE_AFTER_2019)
self.assertEqual(second_english['registrationFee']['amount'], DEFAULT_REGISTRATION_FEE_AFTER_2019)
self.assertEqual(insider['registrationFee']['amount'], DEFAULT_REGISTRATION_FEE_AFTER_2019)
31 changes: 27 additions & 4 deletions openregistry/lots/loki/tests/blanks/lot_blanks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import unittest

from copy import deepcopy
from uuid import uuid4
from datetime import timedelta
from isodate import parse_datetime

Expand Down Expand Up @@ -138,7 +137,6 @@ def check_change_to_verification(self):
first_english_data = deepcopy(auction_english_data)
first_english_data['auctionPeriod']['startDate'] = get_now().isoformat()


response = self.app.get('/{}'.format(lot['id']))
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
Expand Down Expand Up @@ -452,7 +450,6 @@ def rectificationPeriod_workflow(self):
add_cancellationDetails_document(self, lot, access_header)
check_patch_status_200(self, '/{}'.format(lot['id']), 'pending.deleted', access_header)


# Check chronograph action
self.app.authorization = ('Basic', ('broker', ''))

Expand Down Expand Up @@ -1819,3 +1816,29 @@ def adding_platformLegalDetails_doc(self):
)
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']['title'], 'another')


def create_lot_check_auctions_registrationFee(test_case):
response = test_case.app.post_json('/', {'data': test_case.initial_data})
lot = response.json['data']
token = response.json['access']['token']
auctions_ids = [auction['id'] for auction in lot['auctions']]

for auction_id in auctions_ids:

# check auction.registrationFee
entrypoint = '/{}/auctions/{}'.format(lot['id'], auction_id)
response = test_case.app.get(entrypoint)
auction = response.json['data']
test_case.assertNotIn('registrationFee', auction.keys())

# try to patch auction.registrationFee
data = {'registrationFee': {'amount': 100}}
entrypoint = '/{}/auctions/{}?acc_token={}'.format(lot['id'], auction_id, token)
response = test_case.app.patch_json(entrypoint, {'data': data})

# check if patch change auction.registrationFee
entrypoint = '/{}/auctions/{}'.format(lot['id'], auction_id)
response = test_case.app.get(entrypoint)
auction = response.json['data']
test_case.assertNotIn('registrationFee', auction.keys())
4 changes: 3 additions & 1 deletion openregistry/lots/loki/tests/lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@
# LotTest
simple_add_lot,
simple_patch,
create_lot_check_auctions_registrationFee
)
from openregistry.lots.loki.models import Lot


class LotTest(BaseWebTest):
class LotTest(BaseLotWebTest):
initial_data = test_loki_lot_data
relative_to = os.path.dirname(__file__)
test_simple_add_lot = snitch(simple_add_lot)
test_create_lot_check_auctions_registrationFee = snitch(create_lot_check_auctions_registrationFee)


class LotResourceTest(BaseLotWebTest, ResourceTestMixin):
Expand Down

0 comments on commit 48bf0c7

Please sign in to comment.