Skip to content

Commit

Permalink
Merge pull request #735 from City-of-Helsinki/eol_mothballing
Browse files Browse the repository at this point in the history
FIX code style
  • Loading branch information
mikkovihonen committed Feb 17, 2023
2 parents d09b23a + 71f9da5 commit 2764dad
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 114 deletions.
21 changes: 11 additions & 10 deletions customers/tests/test_customers_mutations.py
Expand Up @@ -2,11 +2,10 @@
import uuid
from unittest import mock

from requests import Session

import pytest
from dateutil.utils import today
from django.core.files.uploadedfile import SimpleUploadedFile
from requests import Session

from berth_reservations.tests.utils import (
assert_doesnt_exist,
Expand Down Expand Up @@ -534,9 +533,10 @@ def test_create_my_berth_profile(user_api_client, hki_profile_address):

assert CustomerProfile.objects.count() == 0

with mock.patch.object(Session,
"post",
side_effect=mocked_response_my_profile(
with mock.patch.object(
Session,
"post",
side_effect=mocked_response_my_profile(
data={
"id": customer_id,
"first_name": "test",
Expand All @@ -545,7 +545,7 @@ def test_create_my_berth_profile(user_api_client, hki_profile_address):
"primary_phone": {"phone": "0501234567"},
"primary_address": hki_profile_address,
},
),
),
):
executed = user_api_client.execute(
CREATE_MY_BERTH_PROFILE_MUTATION, input=variables
Expand All @@ -566,10 +566,11 @@ def test_create_my_berth_profile(user_api_client, hki_profile_address):

def test_create_my_berth_profile_does_not_exist(user_api_client):
variables = {"profileToken": "token"}
with mock.patch.object(Session,
"post",
side_effect=mocked_response_my_profile(None),
):
with mock.patch.object(
Session,
"post",
side_effect=mocked_response_my_profile(None),
):
executed = user_api_client.execute(
CREATE_MY_BERTH_PROFILE_MUTATION, input=variables
)
Expand Down
29 changes: 16 additions & 13 deletions customers/tests/test_profile_service.py
@@ -1,8 +1,8 @@
from unittest import mock
from uuid import UUID, uuid4
from requests import Session

from faker import Faker
from requests import Session

from customers.schema import ProfileNode
from customers.services.profile import ProfileService
Expand Down Expand Up @@ -36,10 +36,11 @@ def test_get_all_profiles_id_list():
profiles = [get_customer_profile_dict() for _i in range(0, 5)]
profile_ids = [UUID(from_global_id(profile["id"])) for profile in profiles]

with mock.patch.object(Session,
"post",
side_effect=mocked_response_profile(data=profiles, count=0),
):
with mock.patch.object(
Session,
"post",
side_effect=mocked_response_profile(data=profiles, count=0),
):
profiles = ProfileService(profile_token="token").get_all_profiles(
profile_ids=profile_ids
)
Expand All @@ -57,9 +58,10 @@ def test_get_all_profiles_id_list():
def test_get_profile(customer_profile, user, hki_profile_address):
faker = Faker()
phone = faker.phone_number()
with mock.patch.object(Session,
"post",
side_effect=mocked_response_profile(
with mock.patch.object(
Session,
"post",
side_effect=mocked_response_profile(
count=0,
data={
"id": to_global_id(ProfileNode, customer_profile.id),
Expand All @@ -70,7 +72,7 @@ def test_get_profile(customer_profile, user, hki_profile_address):
"primary_address": hki_profile_address,
},
use_edges=False,
),
),
):
profile = ProfileService(profile_token="token").get_profile(customer_profile.id)

Expand All @@ -87,9 +89,10 @@ def test_get_profile(customer_profile, user, hki_profile_address):
def test_get_my_profile(customer_profile, user, hki_profile_address):
faker = Faker()
phone = faker.phone_number()
with mock.patch.object(Session,
"post",
side_effect=mocked_response_my_profile(
with mock.patch.object(
Session,
"post",
side_effect=mocked_response_my_profile(
data={
"id": to_global_id(ProfileNode, customer_profile.id),
"first_name": user.first_name,
Expand All @@ -98,7 +101,7 @@ def test_get_my_profile(customer_profile, user, hki_profile_address):
"primary_phone": {"phone": phone},
"primary_address": hki_profile_address,
},
),
),
):
profile = ProfileService(profile_token="token").get_my_profile()

Expand Down
20 changes: 11 additions & 9 deletions leases/tests/test_lease_mutations.py
@@ -1,14 +1,14 @@
import uuid
from random import randint
from unittest import mock
from requests import Session

import pytest
from babel.dates import format_date
from dateutil.relativedelta import relativedelta
from dateutil.utils import today
from django.core import mail
from freezegun import freeze_time
from requests import Session

from applications.enums import ApplicationStatus
from applications.schema import BerthApplicationNode, WinterStorageApplicationNode
Expand Down Expand Up @@ -2206,10 +2206,11 @@ def test_terminate_berth_lease_without_application(
"primary_phone": {},
}

with mock.patch.object(Session,
"post",
side_effect=mocked_response_profile(count=0, data=data, use_edges=False),
):
with mock.patch.object(
Session,
"post",
side_effect=mocked_response_profile(count=0, data=data, use_edges=False),
):
executed = api_client.execute(TERMINATE_BERTH_LEASE_MUTATION, input=variables)

assert executed["data"]["terminateBerthLease"]["berthLease"] == {
Expand Down Expand Up @@ -2449,10 +2450,11 @@ def test_terminate_ws_lease_without_application(
"primary_phone": {},
}

with mock.patch.object(Session,
"post",
side_effect=mocked_response_profile(count=0, data=data, use_edges=False),
):
with mock.patch.object(
Session,
"post",
side_effect=mocked_response_profile(count=0, data=data, use_edges=False),
):
executed = api_client.execute(
TERMINATE_WINTER_STORAGE_LEASE_MUTATION, input=variables
)
Expand Down
1 change: 0 additions & 1 deletion leases/tests/test_lease_sticker_mutations.py
@@ -1,4 +1,3 @@
import pytest
from dateutil.utils import today

from applications.enums import ApplicationAreaType
Expand Down
48 changes: 24 additions & 24 deletions leases/tests/test_send_berth_invoice_service.py
@@ -1,5 +1,4 @@
from unittest import mock
from requests import Session

import pytest # noqa
from anymail.exceptions import AnymailError
Expand All @@ -9,6 +8,7 @@
from django.test import RequestFactory
from faker import Faker
from freezegun import freeze_time
from requests import Session

from berth_reservations.tests.factories import UserFactory
from contracts.tests.factories import BerthContractFactory
Expand Down Expand Up @@ -48,12 +48,10 @@ def _send_invoices(data):
return invoicing_service


@ freeze_time("2020-01-01T08:00:00Z")
@ pytest.mark.parametrize(
@freeze_time("2020-01-01T08:00:00Z")
@pytest.mark.parametrize(
"invoicing_type,sent_mail_count",
[(InvoicingType.ONLINE_PAYMENT, 1), (InvoicingType.PAPER_INVOICE, 0)],
)
def test_send_berth_invoices_basic(
invoicing_type, sent_mail_count, notification_template_orders_approved
Expand Down Expand Up @@ -117,7 +115,7 @@ def test_send_berth_invoices_basic(
assert order.order_number in msg.body


@ freeze_time("2020-01-01T08:00:00Z")
@freeze_time("2020-01-01T08:00:00Z")
def test_send_berth_invoices_no_contract(notification_template_orders_approved):
lease = BerthLeaseFactory(
boat=None,
Expand Down Expand Up @@ -154,7 +152,7 @@ def test_send_berth_invoices_no_contract(notification_template_orders_approved):
assert BerthLease.objects.count() == 1


@ freeze_time("2020-01-01T08:00:00Z")
@freeze_time("2020-01-01T08:00:00Z")
def test_use_berth_leases_from_last_season(notification_template_orders_approved):
# This lease from the upcoming season should be ignored
_lease_with_contract(
Expand Down Expand Up @@ -214,7 +212,7 @@ def test_use_berth_leases_from_last_season(notification_template_orders_approved
assert order.order_number in msg.body


@ freeze_time("2020-10-01T08:00:00Z")
@freeze_time("2020-10-01T08:00:00Z")
def test_use_berth_leases_from_current_season(notification_template_orders_approved):
# This lease from last season should be ignored
_lease_with_contract(
Expand Down Expand Up @@ -274,7 +272,7 @@ def test_use_berth_leases_from_current_season(notification_template_orders_appro
assert order.order_number in msg.body


@ freeze_time("2020-01-01T08:00:00Z")
@freeze_time("2020-01-01T08:00:00Z")
def test_berth_lease_berth_product(notification_template_orders_approved):
lease = _lease_with_contract(
boat=None,
Expand Down Expand Up @@ -308,7 +306,7 @@ def test_berth_lease_berth_product(notification_template_orders_approved):
assert isinstance(order.product, BerthProduct)


@ freeze_time("2020-01-01T08:00:00Z")
@freeze_time("2020-01-01T08:00:00Z")
def test_berth_lease_no_product():
lease = _lease_with_contract(
boat=None,
Expand Down Expand Up @@ -347,7 +345,7 @@ def test_berth_lease_no_product():
)


@ freeze_time("2020-01-01T08:00:00Z")
@freeze_time("2020-01-01T08:00:00Z")
def test_send_berth_invoices_missing_email(notification_template_orders_approved):
lease = _lease_with_contract(
boat=None,
Expand Down Expand Up @@ -395,7 +393,7 @@ def test_send_berth_invoices_missing_email(notification_template_orders_approved
assert lease.end_date.isoformat() == "2020-09-14"


@ freeze_time("2020-01-01T08:00:00Z")
@freeze_time("2020-01-01T08:00:00Z")
def test_send_berth_invoices_invalid_example_email(
notification_template_orders_approved,
):
Expand Down Expand Up @@ -445,7 +443,7 @@ def test_send_berth_invoices_invalid_example_email(
assert lease.end_date.isoformat() == "2020-09-14"


@ freeze_time("2020-01-01T08:00:00Z")
@freeze_time("2020-01-01T08:00:00Z")
def test_send_berth_invoices_send_error(notification_template_orders_approved):
lease = _lease_with_contract(
boat=None,
Expand All @@ -467,10 +465,11 @@ def test_send_berth_invoices_send_error(notification_template_orders_approved):

assert Order.objects.count() == 0

with mock.patch.object(Session,
"post",
side_effect=mocked_response_profile(count=0, data=data),
):
with mock.patch.object(
Session,
"post",
side_effect=mocked_response_profile(count=0, data=data),
):
with mock.patch(
"payments.utils.send_notification",
side_effect=AnymailError("Anymail error"),
Expand Down Expand Up @@ -509,7 +508,7 @@ def test_send_berth_invoices_send_error(notification_template_orders_approved):
)


@ freeze_time("2020-01-01T08:00:00Z")
@freeze_time("2020-01-01T08:00:00Z")
def test_send_berth_invoices_only_not_renewed(notification_template_orders_approved):
# This lease should be ignored since it already has a lease for the upcoming season
renewed_lease = _lease_with_contract(
Expand Down Expand Up @@ -579,7 +578,7 @@ def test_send_berth_invoices_only_not_renewed(notification_template_orders_appro
assert order.status == OrderStatus.OFFERED


@ freeze_time("2020-01-01T08:00:00Z")
@freeze_time("2020-01-01T08:00:00Z")
def test_send_berth_invoices_invalid_limit_reached(
notification_template_orders_approved,
):
Expand Down Expand Up @@ -616,10 +615,11 @@ def test_send_berth_invoices_invalid_limit_reached(
invoicing_service = BerthInvoicingService(
request=RequestFactory().request(), profile_token="token"
)
with mock.patch.object(Session,
"post",
side_effect=mocked_response_profile(count=1, data=data),
):
with mock.patch.object(
Session,
"post",
side_effect=mocked_response_profile(count=1, data=data),
):
with mock.patch.object(
invoicing_service,
"email_admins",
Expand All @@ -633,7 +633,7 @@ def test_send_berth_invoices_invalid_limit_reached(
assert invoicing_service.failure_count == 1


@ freeze_time("2020-01-01T08:00:00Z")
@freeze_time("2020-01-01T08:00:00Z")
def test_non_invoiceable_berth(notification_template_orders_approved):
berth = BerthFactory(is_invoiceable=False)

Expand Down
11 changes: 6 additions & 5 deletions payments/tests/test_payments_mutations_approve_ap_order.py
@@ -1,11 +1,11 @@
from unittest import mock
from requests import Session

import pytest
from dateutil.relativedelta import relativedelta
from dateutil.utils import today
from django.core import mail
from freezegun import freeze_time
from requests import Session

from applications.enums import ApplicationStatus
from customers.services import SMSNotificationService
Expand Down Expand Up @@ -58,10 +58,11 @@ def test_approve_ap_order(
"profileToken": "mock_token",
}

with mock.patch.object(Session,
"post",
side_effect=mocked_response_profile(count=1, data=None, use_edges=False),
), mock.patch.object(
with mock.patch.object(
Session,
"post",
side_effect=mocked_response_profile(count=1, data=None, use_edges=False),
), mock.patch.object(
SMSNotificationService, "send", return_value=None
) as mock_send_sms:
executed = api_client.execute(APPROVE_ORDER_MUTATION, input=variables)
Expand Down

0 comments on commit 2764dad

Please sign in to comment.