test_preparemoodle.py 1.36 KB
Newer Older
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
    def test_preparemoodle_single(self):
22
23
        import preparemoodle

Christian Rohlfing's avatar
Christian Rohlfing committed
24
25
26
        expected_feedback_folder =\
            'LastnameB, FirstnameB_1519322_assignsubmission_file_'
        expected_feedback_file = '123002_LastnameB.pdf'
27
28

        # Prepare parameter
Deb's avatar
Deb committed
29
30
        in_dir = './tests/assets/pdfs'
        sheet_csv = "./tests/assets/Grades.csv"
31
32
33
34
35
36
37
38
        feedback_zip = 'feedbacks.zip'

        tmp_dir = os.path.join(self.test_dir, 'tmp')
        os.mkdir(tmp_dir)

        out_zip = os.path.join(self.test_dir, feedback_zip)

        # Call function
Christian Rohlfing's avatar
Christian Rohlfing committed
39
40
        preparemoodle.main([in_dir, sheet_csv, out_zip,
                            "-t", tmp_dir])
41
42
43
44
45
46
47
48

        # Unpack feedbacks
        shutil.unpack_archive(out_zip, tmp_dir)
        feedback_folders = os.listdir(tmp_dir)
        self.assertTrue(feedback_folders[0], expected_feedback_folder)

        feedbacks = os.listdir(os.path.join(tmp_dir, feedback_folders[0]))
        self.assertTrue(feedbacks[0], expected_feedback_file)