test_preparemoodle.py 1.33 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
24
25
26
27
        import preparemoodle

        expected_feedback_folder = 'Four, Student_107_assignsubmission_file_'
        expected_feedback_file = '123456_Nachname.pdf'

        # Prepare parameter
Deb's avatar
Deb committed
28
29
        in_dir = './tests/assets/pdfs'
        sheet_csv = "./tests/assets/Grades.csv"
30
31
32
33
34
35
36
37
        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
Deb's avatar
Deb committed
38
39
        preparemoodle.main([in_dir, sheet_csv,
                            "-t", tmp_dir, out_zip])
40
41
42
43
44
45
46
47

        # 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)