-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sites HH data report: Can't access if viewer
- Loading branch information
Showing
3 changed files
with
55 additions
and
4 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
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,9 +1,11 @@ | ||
from io import BytesIO | ||
from zipfile import ZipFile | ||
|
||
from requests.auth import _basic_auth_str | ||
|
||
from utils import match | ||
|
||
from chellow.models import Site, User | ||
from chellow.models import Contract, MarketRole, Participant, Site, User, UserRole | ||
from chellow.reports.report_183 import _process_site, none_content | ||
from chellow.utils import ct_datetime, to_utc | ||
|
||
|
@@ -68,6 +70,45 @@ def test_do_post_site_codes(mocker, client, sess): | |
MockThread.assert_called_with(target=none_content, args=expected_args) | ||
|
||
|
||
def test_do_post_viewer(mocker, raw_client, sess): | ||
vf = to_utc(ct_datetime(2022, 7, 1)) | ||
user_role = UserRole.insert(sess, "viewer") | ||
user = User.insert(sess, "[email protected]", "admin", user_role, None) | ||
participant = Participant.insert(sess, "CALB", "Calb") | ||
market_role = MarketRole.insert(sess, "Z", "Non-core") | ||
participant.insert_party(sess, market_role, "neut", vf, None, "") | ||
Contract.insert_non_core(sess, "configuration", "", {}, vf, None, {}) | ||
sess.commit() | ||
|
||
MockThread = mocker.patch("chellow.reports.report_183.threading.Thread") | ||
|
||
data = { | ||
"start_year": "2022", | ||
"start_month": "07", | ||
"start_day": "01", | ||
"finish_year": "2022", | ||
"finish_month": "07", | ||
"finish_day": "31", | ||
"type": "used", | ||
"site_codes": "", | ||
} | ||
headers = {"Authorization": _basic_auth_str("[email protected]", "admin")} | ||
response = raw_client.post("/reports/183", data=data, headers=headers) | ||
|
||
match(response, 303) | ||
|
||
expected_args = ( | ||
None, | ||
"used", | ||
to_utc(ct_datetime(2022, 7, 1)), | ||
to_utc(ct_datetime(2022, 7, 31, 23, 30)), | ||
user.id, | ||
"sites_hh_data_202207312330_filter.zip", | ||
) | ||
|
||
MockThread.assert_called_with(target=none_content, args=expected_args) | ||
|
||
|
||
def test_process_site(sess): | ||
f = BytesIO() | ||
zf = ZipFile(f, mode="w") | ||
|