From 6ff0905cb2b9e3a9d55fabf22a174367c43b63c6 Mon Sep 17 00:00:00 2001 From: vitalii-motso Date: Mon, 25 Feb 2019 18:05:47 +0200 Subject: [PATCH] delete default registrationFee from lot.auctions --- openregistry/lots/loki/models.py | 2 +- openregistry/lots/loki/roles.py | 2 +- openregistry/lots/loki/tests/auction.py | 2 - .../lots/loki/tests/blanks/auction_blanks.py | 98 +------------------ .../lots/loki/tests/blanks/lot_blanks.py | 31 +++++- openregistry/lots/loki/tests/lot.py | 4 +- 6 files changed, 33 insertions(+), 106 deletions(-) diff --git a/openregistry/lots/loki/models.py b/openregistry/lots/loki/models.py index 3b1c436..cfd2f33 100644 --- a/openregistry/lots/loki/models.py +++ b/openregistry/lots/loki/models.py @@ -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) diff --git a/openregistry/lots/loki/roles.py b/openregistry/lots/loki/roles.py index 6b1e0fb..776bca0 100644 --- a/openregistry/lots/loki/roles.py +++ b/openregistry/lots/loki/roles.py @@ -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')) diff --git a/openregistry/lots/loki/tests/auction.py b/openregistry/lots/loki/tests/auction.py index e95e87b..21f53a7 100644 --- a/openregistry/lots/loki/tests/auction.py +++ b/openregistry/lots/loki/tests/auction.py @@ -18,7 +18,6 @@ submissionMethodDetails_check, patch_auctions_with_lot, patch_auction_by_concierge, - registrationFee_default, auctionPeriod_endDate_blacklisted ) @@ -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) diff --git a/openregistry/lots/loki/tests/blanks/auction_blanks.py b/openregistry/lots/loki/tests/blanks/auction_blanks.py index 528c55f..2edfe71 100644 --- a/openregistry/lots/loki/tests/blanks/auction_blanks.py +++ b/openregistry/lots/loki/tests/blanks/auction_blanks.py @@ -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': { @@ -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'] @@ -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') @@ -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) @@ -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']) @@ -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) @@ -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') @@ -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'], @@ -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'], @@ -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 @@ -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) diff --git a/openregistry/lots/loki/tests/blanks/lot_blanks.py b/openregistry/lots/loki/tests/blanks/lot_blanks.py index 950162c..eba59dd 100644 --- a/openregistry/lots/loki/tests/blanks/lot_blanks.py +++ b/openregistry/lots/loki/tests/blanks/lot_blanks.py @@ -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 @@ -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') @@ -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', '')) @@ -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()) diff --git a/openregistry/lots/loki/tests/lot.py b/openregistry/lots/loki/tests/lot.py index 5e95e56..75548c8 100644 --- a/openregistry/lots/loki/tests/lot.py +++ b/openregistry/lots/loki/tests/lot.py @@ -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):