Skip to content

Commit

Permalink
Merge pull request #734 from City-of-Helsinki/eol_mothballing
Browse files Browse the repository at this point in the history
FIX fix and enable tests with profile queries
  • Loading branch information
mikkovihonen committed Feb 17, 2023
2 parents 35559f1 + 7bd7c16 commit d09b23a
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 265 deletions.
24 changes: 10 additions & 14 deletions customers/tests/test_customers_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import uuid
from unittest import mock

from requests import Session

import pytest
from dateutil.utils import today
from django.core.files.uploadedfile import SimpleUploadedFile
Expand Down Expand Up @@ -525,19 +527,16 @@ def test_create_berth_service_profile_no_id(superuser_api_client):
"""


@pytest.mark.skip(
reason="temporarily disabled so that retry logic can be tested in test env"
)
def test_create_my_berth_profile(user_api_client, hki_profile_address):
customer_id = to_global_id(ProfileNode, uuid.uuid4())

variables = {"profileToken": "token"}

assert CustomerProfile.objects.count() == 0

with mock.patch(
"customers.services.profile.requests.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 @@ -546,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 @@ -565,15 +564,12 @@ def test_create_my_berth_profile(user_api_client, hki_profile_address):
assert profile.user.groups.first() == get_berth_customers_group()


@pytest.mark.skip(
reason="temporarily disabled so that retry logic can be tested in test env"
)
def test_create_my_berth_profile_does_not_exist(user_api_client):
variables = {"profileToken": "token"}
with mock.patch(
"customers.services.profile.requests.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
6 changes: 0 additions & 6 deletions customers/tests/test_customers_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1418,9 +1418,6 @@ def test_filter_profile_by_sticker_season_only(superuser_api_client):
assert to_global_id(ProfileNode, profile_3.id) in str(executed["data"])


@pytest.mark.skip(
reason="temporarily disabled so that retry logic can be tested in test env"
)
def test_filter_by_hki_profile_filters_without_profile_token(superuser_api_client):
CustomerProfileFactory() # needed to trigger the profile query, or otherwise no ids
query = """
Expand All @@ -1438,9 +1435,6 @@ def test_filter_by_hki_profile_filters_without_profile_token(superuser_api_clien
assert_in_errors("API Token", executed)


@pytest.mark.skip(
reason="temporarily disabled so that retry logic can be tested in test env"
)
@patch("customers.services.profile.ProfileService.find_profile")
def test_filter_by_hki_profile_filters(mock_find_profile, superuser_api_client):
profile_1 = WinterStorageLeaseFactory(
Expand Down
43 changes: 16 additions & 27 deletions customers/tests/test_profile_service.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest import mock
from uuid import UUID, uuid4
from requests import Session

import pytest
from faker import Faker

from customers.schema import ProfileNode
Expand All @@ -15,12 +15,10 @@
)


@pytest.mark.skip(
reason="temporarily disabled so that retry logic can be tested in test env"
)
def test_get_all_profiles():
with mock.patch(
"customers.services.profile.requests.session.post",
with mock.patch.object(
Session,
"post",
side_effect=mocked_response_profile(count=5),
):
profiles = ProfileService(profile_token="token").get_all_profiles()
Expand All @@ -34,17 +32,14 @@ def test_get_all_profiles():
assert user_profile.phone is not None


@pytest.mark.skip(
reason="temporarily disabled so that retry logic can be tested in test env"
)
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(
"customers.services.profile.requests.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 @@ -59,15 +54,12 @@ def test_get_all_profiles_id_list():
assert user_profile.phone is not None


@pytest.mark.skip(
reason="temporarily disabled so that retry logic can be tested in test env"
)
def test_get_profile(customer_profile, user, hki_profile_address):
faker = Faker()
phone = faker.phone_number()
with mock.patch(
"customers.services.profile.requests.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 @@ -78,7 +70,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 @@ -92,15 +84,12 @@ def test_get_profile(customer_profile, user, hki_profile_address):
assert profile.city == hki_profile_address.get("city")


@pytest.mark.skip(
reason="temporarily disabled so that retry logic can be tested in test env"
)
def test_get_my_profile(customer_profile, user, hki_profile_address):
faker = Faker()
phone = faker.phone_number()
with mock.patch(
"customers.services.profile.requests.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 @@ -109,7 +98,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
23 changes: 9 additions & 14 deletions leases/tests/test_lease_mutations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import uuid
from random import randint
from unittest import mock
from requests import Session

import pytest
from babel.dates import format_date
Expand Down Expand Up @@ -2178,9 +2179,6 @@ def test_terminate_berth_lease_with_drafted_order(
)


@pytest.mark.skip(
reason="temporarily disabled so that retry logic can be tested in test env"
)
@freeze_time("2020-07-01T08:00:00Z")
@pytest.mark.parametrize(
"api_client",
Expand Down Expand Up @@ -2208,10 +2206,10 @@ def test_terminate_berth_lease_without_application(
"primary_phone": {},
}

with mock.patch(
"customers.services.profile.requests.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 @@ -2424,9 +2422,6 @@ def test_terminate_ws_lease_with_application(
]


@pytest.mark.skip(
reason="temporarily disabled so that retry logic can be tested in test env"
)
@freeze_time("2020-12-01T08:00:00Z")
@pytest.mark.parametrize(
"api_client",
Expand Down Expand Up @@ -2454,10 +2449,10 @@ def test_terminate_ws_lease_without_application(
"primary_phone": {},
}

with mock.patch(
"customers.services.profile.requests.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
15 changes: 0 additions & 15 deletions leases/tests/test_lease_sticker_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
"""


@pytest.mark.skip(
reason="temporarily disabled so that retry logic can be tested in test env"
)
def test_assign_new_sticker_number_error_when_unpaid(
sticker_sequences, superuser_api_client, winter_storage_lease
):
Expand All @@ -32,9 +29,6 @@ def test_assign_new_sticker_number_error_when_unpaid(
assert_in_errors("Lease must be in PAID status", executed)


@pytest.mark.skip(
reason="temporarily disabled so that retry logic can be tested in test env"
)
def test_assign_new_sticker_number_error_when_marked_lease(
sticker_sequences,
superuser_api_client,
Expand Down Expand Up @@ -68,9 +62,6 @@ def test_assign_new_sticker_number_error_when_marked_lease(
"""


@pytest.mark.skip(
reason="temporarily disabled so that retry logic can be tested in test env"
)
def test_assign_new_sticker_number(
sticker_sequences,
superuser_api_client,
Expand Down Expand Up @@ -99,9 +90,6 @@ def test_assign_new_sticker_number(
assert len(sticker_season) == 9


@pytest.mark.skip(
reason="temporarily disabled so that retry logic can be tested in test env"
)
def test_assign_new_sticker_number_resets_posted_date(
sticker_sequences,
superuser_api_client,
Expand Down Expand Up @@ -139,9 +127,6 @@ def test_assign_new_sticker_number_resets_posted_date(
"""


@pytest.mark.skip(
reason="temporarily disabled so that retry logic can be tested in test env"
)
def test_set_stickers_posted(superuser_api_client, winter_storage_lease):
lease_id = to_global_id(WinterStorageLeaseNode, winter_storage_lease.id)

Expand Down
Loading

0 comments on commit d09b23a

Please sign in to comment.