-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Running `pytest` would work, but not `pytest -k contractor`. This commit makes various fixes to fix the flakiness of the tests. Refs: PS-160, PS-159
- Loading branch information
Showing
7 changed files
with
148 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import pytest | ||
from datetime import datetime | ||
from django.contrib.gis.geos import MultiPolygon, Polygon | ||
from django.utils.timezone import make_aware | ||
from rest_framework.reverse import reverse | ||
|
||
|
@@ -15,24 +14,7 @@ | |
|
||
@pytest.fixture | ||
def contract_zone(): | ||
return ContractZoneFactory( | ||
boundary=MultiPolygon( | ||
Polygon(((24, 60), (25, 60), (25, 61), (24, 61), (24, 60))) | ||
), | ||
contact_person="John Doe", | ||
email="[email protected]", | ||
phone="555-1234567", | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def two_events_2018(): | ||
return EventFactory.create_batch(2) | ||
|
||
|
||
@pytest.fixture | ||
def two_events_2019(): | ||
return EventFactory.create_batch(2, start_time=make_aware(datetime(2019, 3, 3))) | ||
return ContractZoneFactory() | ||
|
||
|
||
def get_expected_base_data(contract_zone): | ||
|
@@ -52,36 +34,43 @@ def get_expected_base_data_with_contact_data(contract_zone): | |
) | ||
|
||
|
||
def test_get_list_non_official_no_stats_no_contact_info( | ||
contract_zone, two_events_2018, user_api_client | ||
): | ||
def test_get_list_non_official_no_stats_no_contact_info(contract_zone, user_api_client): | ||
EventFactory.create_batch( | ||
2, contract_zone=contract_zone, start_time=make_aware(datetime(2018, 3, 3)) | ||
) | ||
response_data = get(user_api_client, LIST_URL + "?stats_year=2018") | ||
|
||
assert response_data["results"] == [get_expected_base_data(contract_zone)] | ||
|
||
|
||
def test_get_list_official_no_filter_no_stats_check_contact_data( | ||
contract_zone, two_events_2018, official_api_client | ||
contract_zone, official_api_client | ||
): | ||
EventFactory.create_batch(2, contract_zone=contract_zone) | ||
response_data = get(official_api_client, LIST_URL) | ||
|
||
assert response_data["results"] == [ | ||
get_expected_base_data_with_contact_data(contract_zone) | ||
] | ||
|
||
|
||
def test_get_list_official_check_stats( | ||
contract_zone, two_events_2018, two_events_2019, official_api_client | ||
): | ||
def test_get_list_official_check_stats(contract_zone, official_api_client): | ||
event_1, event_2 = EventFactory.create_batch( | ||
2, contract_zone=contract_zone, start_time=make_aware(datetime(2018, 3, 3)) | ||
) | ||
EventFactory.create_batch( | ||
2, contract_zone=contract_zone, start_time=make_aware(datetime(2019, 3, 3)) | ||
) | ||
non_approved_event_that_should_be_ignored = EventFactory( | ||
estimated_attendee_count=100000, state=Event.WAITING_FOR_APPROVAL | ||
estimated_attendee_count=100000, | ||
state=Event.WAITING_FOR_APPROVAL, | ||
contract_zone=contract_zone, | ||
) | ||
assert non_approved_event_that_should_be_ignored.contract_zone == contract_zone | ||
assert non_approved_event_that_should_be_ignored.start_time.date().year == 2018 | ||
|
||
response_data = get(official_api_client, LIST_URL + "?stats_year=2018") | ||
|
||
event_1, event_2 = two_events_2018 | ||
expected_data = dict( | ||
get_expected_base_data_with_contact_data(contract_zone), | ||
event_count=2, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import pytest | ||
from django.contrib.gis.geos import MultiPolygon, Point, Polygon | ||
|
||
from areas.factories import ContractZoneFactory | ||
from common.tests.conftest import * # noqa | ||
|
@@ -10,17 +9,9 @@ | |
|
||
@pytest.fixture | ||
def contract_zone(): | ||
return ContractZoneFactory( | ||
boundary=MultiPolygon( | ||
Polygon(((24, 60), (25, 60), (25, 61), (24, 61), (24, 60))) | ||
), | ||
email="[email protected]", | ||
secondary_email="[email protected]", | ||
) | ||
return ContractZoneFactory() | ||
|
||
|
||
@pytest.fixture | ||
def event(contract_zone): | ||
event = EventFactory(location=Point(24.5, 60.5)) | ||
assert event.contract_zone == contract_zone | ||
return event | ||
def event(): | ||
return EventFactory() |
Oops, something went wrong.