Verified Commit 178f05c7 authored by Pierre-Elliott Bécue's avatar Pierre-Elliott Bécue 🚼
Browse files

Create the appropriate tests for the DownloadStatements view permission checks

parent e0f381b3
...@@ -21,6 +21,7 @@ class TestDownloadStatements(ProcessFixtureMixin, TestCase): ...@@ -21,6 +21,7 @@ class TestDownloadStatements(ProcessFixtureMixin, TestCase):
super(TestDownloadStatements, cls).setUpClass() super(TestDownloadStatements, cls).setUpClass()
cls.create_person("app", status=const.STATUS_DC) cls.create_person("app", status=const.STATUS_DC)
cls.processes.create("app", person=cls.persons.app, applying_for=const.STATUS_DD_U, fd_comment="test") cls.processes.create("app", person=cls.persons.app, applying_for=const.STATUS_DD_U, fd_comment="test")
cls.processes.create("ddem", person=cls.persons.dd_u, applying_for=const.STATUS_EMERITUS_DD, fd_comment="test_emeritus")
cls.create_person("am", status=const.STATUS_DD_NU) cls.create_person("am", status=const.STATUS_DD_NU)
cls.ams.create("am", person=cls.persons.am) cls.ams.create("am", person=cls.persons.am)
cls.amassignments.create( cls.amassignments.create(
...@@ -32,6 +33,8 @@ class TestDownloadStatements(ProcessFixtureMixin, TestCase): ...@@ -32,6 +33,8 @@ class TestDownloadStatements(ProcessFixtureMixin, TestCase):
"app", person=cls.persons.app, fpr=test_fingerprint1, is_active=True, audit_skip=True) "app", person=cls.persons.app, fpr=test_fingerprint1, is_active=True, audit_skip=True)
cls.fingerprints.create( cls.fingerprints.create(
"dd_nu", person=cls.persons.dd_nu, fpr=test_fingerprint2, is_active=True, audit_skip=True) "dd_nu", person=cls.persons.dd_nu, fpr=test_fingerprint2, is_active=True, audit_skip=True)
cls.fingerprints.create(
"dd_u", person=cls.persons.dd_u, fpr=test_fingerprint3, is_active=True, audit_skip=True)
cls.statements.create("intent", cls.statements.create("intent",
requirement=cls.processes.app.requirements.get(type="intent"), requirement=cls.processes.app.requirements.get(type="intent"),
...@@ -43,6 +46,12 @@ class TestDownloadStatements(ProcessFixtureMixin, TestCase): ...@@ -43,6 +46,12 @@ class TestDownloadStatements(ProcessFixtureMixin, TestCase):
fpr=cls.fingerprints.app, fpr=cls.fingerprints.app,
statement=test_fpr1_signed_valid_text_nonascii, statement=test_fpr1_signed_valid_text_nonascii,
uploaded_by=cls.persons.app, uploaded_time=now()) uploaded_by=cls.persons.app, uploaded_time=now())
cls.statements.create("intent",
requirement=cls.processes.ddem.requirements.get(type="intent"),
fpr=cls.fingerprints.dd_u,
statement=test_fpr3_signed_valid_text,
uploaded_by=cls.persons.dd_u, uploaded_time=now())
# Python2's mbox seems to explode on non-ascii in headers # Python2's mbox seems to explode on non-ascii in headers
cls.persons.dd_nu.cn = "Ondřej" cls.persons.dd_nu.cn = "Ondřej"
cls.persons.dd_nu.sn = "Nový" cls.persons.dd_nu.sn = "Nový"
...@@ -73,6 +82,42 @@ class TestDownloadStatements(ProcessFixtureMixin, TestCase): ...@@ -73,6 +82,42 @@ class TestDownloadStatements(ProcessFixtureMixin, TestCase):
with get_mbox(tf.name) as mbox: with get_mbox(tf.name) as mbox:
self.assertEqual(len(mbox), 3) self.assertEqual(len(mbox), 3)
def test_download_emeritus_403(self):
url = reverse("process_download_statements", args=[self.processes.ddem.pk])
client = self.make_test_client(self.visitor)
response = client.get(url)
self.assertEqual(response.status_code, 403)
def test_download_emeritus_self(self):
url = reverse("process_download_statements", args=[self.processes.ddem.pk])
client = self.make_test_client(self.persons.dd_u)
response = client.get(url)
with tempfile.NamedTemporaryFile() as tf:
tf.write(response.content)
tf.flush()
with get_mbox(tf.name) as mbox:
self.assertEqual(len(mbox), 1)
def test_download_emeritus_fd(self):
url = reverse("process_download_statements", args=[self.processes.ddem.pk])
client = self.make_test_client(self.persons.fd)
response = client.get(url)
with tempfile.NamedTemporaryFile() as tf:
tf.write(response.content)
tf.flush()
with get_mbox(tf.name) as mbox:
self.assertEqual(len(mbox), 1)
def test_download_emeritus_dd(self):
url = reverse("process_download_statements", args=[self.processes.ddem.pk])
client = self.make_test_client(self.persons.dd_nu)
response = client.get(url)
with tempfile.NamedTemporaryFile() as tf:
tf.write(response.content)
tf.flush()
with get_mbox(tf.name) as mbox:
self.assertEqual(len(mbox), 1)
class TestApprovals(ProcessFixtureMixin, TestCase): class TestApprovals(ProcessFixtureMixin, TestCase):
def make_process(self, status, applying_for): def make_process(self, status, applying_for):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment