def test_not_found_amount(self, raise_operation_error_mock): class MyExc(Exception): pass raise_operation_error_mock.return_value = MyExc() request = Mock( currency_rates=[ { "cc": "USD", "rate": 8.2 } ], logging_context={} ) value = {"amount": 300, "currency": "рупии"} with self.assertRaises(MyExc): get_uah_amount_from_value(request, value, {}) raise_operation_error_mock.assert_called_once_with( request, "Couldn't find currency {} on bank.gov.ua".format(value["currency"]), status=422 )
def test_usd_amount(self): usd_rate = 8.2 request = Mock(currency_rates=[{ "cc": "USD", "rate": usd_rate }], logging_context={}) value = {"amount": 12.3, "currency": "USD"} result = get_uah_amount_from_value(request, value, {}) self.assertEqual(result, value["amount"] * usd_rate)
def get_complaint_amount(request, tender, complaint): if tender["status"] in ( "active.tendering", "active.pre-qualification", # cancellation complaint "active.pre-qualification.stand-still"): return COMPLAINT_MIN_AMOUNT else: # only bid owners can post complaints here acc_token = extract_access_token(request) for bid in tender.get("bids", ""): if bid["owner_token"] == acc_token: value = get_bid_value(tender, complaint, bid) base_amount = get_uah_amount_from_value( request, value, {"complaint_id": complaint.id}) amount = restrict_value_to_bounds( base_amount * COMPLAINT_ENHANCED_AMOUNT_RATE, COMPLAINT_ENHANCED_MIN_AMOUNT, COMPLAINT_ENHANCED_MAX_AMOUNT) return amount else: # never happens as acc_token must be in bids to allow complaint creation return raise_operation_error( request, "Couldn't set a complaint value for an invalid bidder", )
def test_uah_amount(self): request = Mock() value = {"amount": 12.3, "currency": "UAH"} result = get_uah_amount_from_value(request, value, {}) self.assertEqual(result, value["amount"])