test_encrypt.py 2.18 KB
Newer Older
Christian Rohlfing's avatar
Christian Rohlfing committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import unittest
import time
import os
import tempfile
import shutil


class MainTest(unittest.TestCase):
    def setUp(self):
        self.tic = time.time()  # todo this is sooo ugly
        self.test_dir = tempfile.mkdtemp()

    def tearDown(self):
        self.toc = time.time()
        t = self.toc - self.tic
        print('Time: %.3f' % (t))

        # Clean up
        shutil.rmtree(self.test_dir)

Deb's avatar
Deb committed
21
22
23
    def test_encrypt_scan_single(self):
        import encrypt

24
25
        expected_files = [
            '123001_LastnameA_aes.pdf']
Deb's avatar
Deb committed
26
27

        # Prepare parameter
28
29
        in_pdf = './tests/assets/pdfs/123001_LastnameA.pdf'
        enc_pdf = '123001_LastnameA_aes.pdf'
Deb's avatar
Deb committed
30
31
32
33
34

        out_dir = os.path.join(self.test_dir, 'out')
        os.mkdir(out_dir)

        # Encrypt files
35
36
37
        encrypt.encrypt(
            pdf_file=in_pdf, enc_file=os.path.join(out_dir, enc_pdf),
            password='tests_are_fun')
Deb's avatar
Deb committed
38
39
40
41
42

        created_files = os.listdir(out_dir)
        created_files.sort()
        self.assertEqual(expected_files, created_files)

43
    def test_encrypt_scans(self):
Christian Rohlfing's avatar
Christian Rohlfing committed
44
45
        import encrypt

Deb's avatar
Deb committed
46
47
48
49
        expected_files = ["123001_LastnameA_aes.pdf",
                          "123002_LastnameB_aes.pdf",
                          "123010_LastnameJ_aes.pdf",
                          "123011_LastnameK_aes.pdf",
Christian Rohlfing's avatar
Christian Rohlfing committed
50
51
52
                          'passwords.csv']

        # Prepare parameter
Deb's avatar
Deb committed
53
        in_dir = './tests/assets/pdfs'
Christian Rohlfing's avatar
Christian Rohlfing committed
54
55
56
57
58

        out_dir = os.path.join(self.test_dir, 'out')
        os.mkdir(out_dir)

        # Encrypt files
59
        encrypt.main([in_dir, out_dir])
Christian Rohlfing's avatar
Christian Rohlfing committed
60
61
62
63

        created_files = os.listdir(out_dir)
        created_files.sort()
        self.assertEqual(expected_files, created_files)
64
65
66
67

    def test_encrypt_supplements(self):
        import encrypt

68
        expected_files = ['GDET3_20H_aes.pdf', 'GDET3_20H_loes_aes.pdf',
69
70
71
                          'passwords.csv']

        # Prepare parameter
Deb's avatar
Deb committed
72
        in_dir = './tests/assets/supplements'
73
74
75
76
77

        out_dir = os.path.join(self.test_dir, 'out')
        os.mkdir(out_dir)

        # Encrypt files
Deb's avatar
Deb committed
78
        encrypt.main([in_dir, out_dir])
79
80
81
82

        created_files = os.listdir(out_dir)
        created_files.sort()
        self.assertEqual(expected_files, created_files)