Ejemplo n.º 1
0
 def _create_document(self, doc_type=None, party_code=None):
     if not doc_type:
         doc_type = self.default_doc_type
     if not party_code:
         party_code = self.default_party_code
     new_file = _create_file()
     document = Document(file=new_file,
                         bceid_user=self.user,
                         party_code=party_code,
                         doc_type=doc_type)
     document.save()
     return document
Ejemplo n.º 2
0
    def test_storage_redis_delete(self, mock_redis_an, mock_redis_save,
                                  mock_redis_delete):
        mock_redis_an.return_value = '6061bebb-f2be-4a74-8757-c4063f6f6993_file_txt'
        mock_redis_save.return_value = 'file.txt'
        mock_redis_delete.return_value = True

        file = SimpleUploadedFile('file.txt', b'this is some content')
        test = Document()
        test.file = file
        test.doc_type = 'MC'
        test.bceid_user = self.user
        test.save()

        test.delete()

        self.assertTrue(mock_redis_delete.called)
Ejemplo n.º 3
0
    def test_storage_file_name_match(self, mock_redis_an, mock_redis_save):
        mock_redis_an.return_value = 'file.txt'
        mock_redis_save.return_value = 'file.txt'

        file = SimpleUploadedFile('file.txt', b'this is some content')
        test = Document()
        test.file = file
        test.doc_type = 'MC'
        test.bceid_user = self.user
        test.save()

        self.assertTrue(mock_redis_save.called)
        self.assertEqual(test.filename, test.file.name)
Ejemplo n.º 4
0
    def test_storage_redis_storage(self, mock_redis_an, mock_redis_save):
        mock_redis_an.return_value = '6061bebb-f2be-4a74-8757-c4063f6f6993_file_txt'
        mock_redis_save.return_value = 'file.txt'

        file = SimpleUploadedFile('file.txt', b'this is some content')
        test = Document()
        test.file = file
        test.doc_type = 'MC'
        test.bceid_user = self.user
        test.save()

        self.assertTrue(mock_redis_save.called)
        self.assertEqual(Document.objects.count(), 1)
        test = Document.objects.get(id=test.id)
        self.assertEqual(test.filename, 'file.txt')
        self.assertNotEqual(test.file.name, 'file.txt')
Ejemplo n.º 5
0
    def test_storage_connection_error(self, mock_redis):
        mock_redis.side_effect = ConnectionError()

        original_count = Document.objects.count()
        connection_error = False

        try:
            file = SimpleUploadedFile('file.txt', b'this is some content')
            test = Document()
            test.file = file
            test.doc_type = 'MC'
            test.bceid_user = self.user
            test.save()
        except ConnectionError:
            connection_error = True

        self.assertTrue(connection_error)
        self.assertEqual(Document.objects.count(), original_count)
Ejemplo n.º 6
0
 def test_content_type_from_filename(self):
     self.assertEqual(Document.content_type_from_filename('test_file1.pdf'), 'application/pdf')
     self.assertEqual(Document.content_type_from_filename('redis_key_test_file1_pdf'), 'application/pdf')
     self.assertEqual(Document.content_type_from_filename('test_file2.png'), 'image/png')
     self.assertEqual(Document.content_type_from_filename('redis_key_test_file2_png'), 'image/png')
     self.assertEqual(Document.content_type_from_filename('Test File 3.GIF'), 'image/gif')
     self.assertEqual(Document.content_type_from_filename('redis_key_test_file_3_GIF'), 'image/gif')
     self.assertEqual(Document.content_type_from_filename('Test_File--4.JPEG'), 'image/jpeg')
     self.assertEqual(Document.content_type_from_filename('redis_key_test_file_4_jpeg'), 'image/jpeg')
     self.assertEqual(Document.content_type_from_filename('TestFile5.jpe'), 'image/jpeg')
     self.assertEqual(Document.content_type_from_filename('redis_key_test_file_5_jpe'), 'image/jpeg')
     self.assertEqual(Document.content_type_from_filename('testFile6.jpeg'), 'image/jpeg')
     self.assertEqual(Document.content_type_from_filename('redis_key_testfile_6_jpeg'), 'image/jpeg')
     self.assertEqual(Document.content_type_from_filename('test_file7.HEIC'), 'application/unknown')
     self.assertEqual(Document.content_type_from_filename('redis_key_testfile_7_svgg'), 'application/unknown')