Skip to content

Commit

Permalink
Sites HH data report: Can't access if viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
tlocke committed Sep 7, 2023
1 parent 5ae37f9 commit a5f3d09
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
1 change: 1 addition & 0 deletions chellow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def check_permissions(*args, **kwargs):
or path
in (
"/reports/169",
"/reports/183",
"/reports/187",
"/reports/247",
"/reports/111",
Expand Down
15 changes: 12 additions & 3 deletions chellow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,15 @@ def insert_llfc(
else:
raise BadRequest("This party isn't a DNO.")

@classmethod
def insert(
cls, sess, participant, market_role, name, valid_from, valid_to, dno_code
):
party = Party(participant, market_role, name, valid_from, valid_to, dno_code)
sess.add(party)
sess.flush()
return party

@staticmethod
def find_by_participant_role(sess, participant, market_role, valid_from):
return sess.execute(
Expand Down Expand Up @@ -2260,9 +2269,9 @@ def update(self, name):
self.name = name

def insert_party(self, sess, market_role, name, valid_from, valid_to, dno_code):
party = Party(self, market_role, name, valid_from, valid_to, dno_code)
sess.add(party)
return party
return Party.insert(
sess, self, market_role, name, valid_from, valid_to, dno_code
)

def get_dno(self, sess):
return sess.execute(
Expand Down
43 changes: 42 additions & 1 deletion test/reports/test_report_183.py
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

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit a5f3d09

Please sign in to comment.