diff --git a/process/tests/test_views.py b/process/tests/test_views.py index b813490197d5dae279a4feabca33179ea9af2294..2cabbf95fade10170edb3aa2ef2c53b45b6cecac 100644 --- a/process/tests/test_views.py +++ b/process/tests/test_views.py @@ -21,6 +21,7 @@ class TestDownloadStatements(ProcessFixtureMixin, TestCase): super(TestDownloadStatements, cls).setUpClass() 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("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.ams.create("am", person=cls.persons.am) cls.amassignments.create( @@ -32,6 +33,8 @@ class TestDownloadStatements(ProcessFixtureMixin, TestCase): "app", person=cls.persons.app, fpr=test_fingerprint1, is_active=True, audit_skip=True) cls.fingerprints.create( "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", requirement=cls.processes.app.requirements.get(type="intent"), @@ -43,6 +46,12 @@ class TestDownloadStatements(ProcessFixtureMixin, TestCase): fpr=cls.fingerprints.app, statement=test_fpr1_signed_valid_text_nonascii, 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 cls.persons.dd_nu.cn = "Ondřej" cls.persons.dd_nu.sn = "Nový" @@ -73,6 +82,42 @@ class TestDownloadStatements(ProcessFixtureMixin, TestCase): with get_mbox(tf.name) as mbox: 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): def make_process(self, status, applying_for):