Пример #1
0
    def test_signature_download_view_with_permission(self):
        with open(TEST_DOCUMENT_PATH) as file_object:
            document = self.document_type.new_document(
                file_object=file_object
            )

        with open(TEST_SIGNATURE_FILE_PATH) as file_object:
            signature = DetachedSignature.objects.create(
                document_version=document.latest_version,
                signature_file=File(file_object)
            )

        self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD)

        self.role.permissions.add(
            permission_document_version_signature_download.stored_permission
        )

        self.expected_content_type = 'application/octet-stream; charset=utf-8'

        response = self.get(
            'signatures:document_version_signature_download',
            args=(signature.pk,),
        )

        with signature.signature_file as file_object:
            assert_download_response(
                self, response=response, content=file_object.read(),
            )
Пример #2
0
    def test_download_xml(self):
        """Test download qplotly xml file capability"""

        # Create widget
        qwidget = QplotlyWidget(xml=self.cities_histogram_plot_xml)
        qwidget.save()

        # get download url
        url = reverse('qplotly-download-xml', kwargs={'pk': qwidget.pk})

        # test login required
        response = self.client.get(url)
        self.assertEqual(response.status_code, 302)

        # test download
        self.assertTrue(
            self.client.login(username='******', password='******'))
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        print(response['Content-Type'])
        assert_download_response(
            self,
            response,
            basename=f"qplotly_{slugify(qwidget.title)}.xml",
            content=qwidget.xml,
            mime_type="application/xml; charset=utf-8",
        )

        # widget not found
        url = reverse('qplotly-download-xml', kwargs={'pk': 1111111})

        response = self.client.get(url)
        self.assertEqual(response.status_code, 404)

        self.client.logout()
Пример #3
0
    def test_signature_download_view_with_access(self):
        with open(TEST_DOCUMENT_PATH) as file_object:
            document = self.document_type.new_document(file_object=file_object)

        with open(TEST_SIGNATURE_FILE_PATH) as file_object:
            signature = DetachedSignature.objects.create(
                document_version=document.latest_version,
                signature_file=File(file_object))

        self.login_user()

        self.grant_access(
            obj=document,
            permission=permission_document_version_signature_download)

        self.expected_content_type = 'application/octet-stream; charset=utf-8'

        response = self.get(
            'signatures:document_version_signature_download',
            args=(signature.pk, ),
        )

        with signature.signature_file as file_object:
            assert_download_response(
                self,
                response=response,
                content=file_object.read(),
            )
Пример #4
0
    def test_signature_download_view_with_access(self):
        with open(TEST_DOCUMENT_PATH) as file_object:
            document = self.document_type.new_document(
                file_object=file_object
            )

        with open(TEST_SIGNATURE_FILE_PATH) as file_object:
            signature = DetachedSignature.objects.create(
                document_version=document.latest_version,
                signature_file=File(file_object)
            )

        self.login_user()

        self.grant_access(
            obj=document,
            permission=permission_document_version_signature_download
        )

        self.expected_content_type = 'application/octet-stream; charset=utf-8'

        response = self.get(
            'signatures:document_version_signature_download',
            args=(signature.pk,),
        )

        with signature.signature_file as file_object:
            assert_download_response(
                self, response=response, content=file_object.read(),
            )
Пример #5
0
    def test_key_download_view_with_permission(self):
        self.expected_content_type = 'application/octet-stream; charset=utf-8'

        self._create_test_key()

        self.grant_access(obj=self.test_key,
                          permission=permission_key_download)

        response = self._request_test_key_download_view()
        assert_download_response(
            self,
            response=response,
            content=self.test_key.key_data,
            basename=self.test_key.key_id,
        )
Пример #6
0
    def test_key_download_view_with_permission(self):
        key = Key.objects.create(key_data=TEST_KEY_DATA)

        self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD)

        self.role.permissions.add(permission_key_download.stored_permission)

        response = self.get(viewname='django_gpg:key_download',
                            args=(key.pk, ))

        assert_download_response(
            self,
            response=response,
            content=key.key_data,
            basename=key.key_id,
        )
Пример #7
0
    def test_key_download_view_with_permission(self):
        key = Key.objects.create(key_data=TEST_KEY_DATA)

        self.login_user()

        self.role.permissions.add(permission_key_download.stored_permission)

        self.expected_content_type = 'application/octet-stream; charset=utf-8'

        response = self.get(
            viewname='django_gpg:key_download', args=(key.pk,)
        )

        assert_download_response(
            self, response=response, content=key.key_data,
            basename=key.key_id,
        )
Пример #8
0
    def test_key_download_view_with_permission(self):
        key = Key.objects.create(key_data=TEST_KEY_DATA)

        self.login_user()

        self.role.permissions.add(permission_key_download.stored_permission)

        self.expected_content_type = 'application/octet-stream; charset=utf-8'

        response = self.get(viewname='django_gpg:key_download',
                            args=(key.pk, ))

        assert_download_response(
            self,
            response=response,
            content=key.key_data,
            basename=key.key_id,
        )
Пример #9
0
    def test_signature_download_view_with_access(self):
        self.test_document_path = TEST_SMALL_DOCUMENT_PATH
        self.upload_document()

        self._create_test_detached_signature()

        self.grant_access(
            obj=self.test_document,
            permission=permission_document_version_signature_download
        )

        self.expected_content_types = ('application/octet-stream; charset=utf-8',)

        response = self._request_test_document_version_signature_download_view()

        with self.test_signature.signature_file as file_object:
            assert_download_response(
                self, response=response, content=file_object.read(),
            )