Completed
Pull Request — master (#37)
by
unknown
28s
created

FileUtilsTest.tearDown()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
1
# -*- coding: utf-8 -*-
2
import unittest
3
import os
4
from datetime import date
5
from shutil import copyfile
6
7
from oe_utils.utils.actor_utils import actor_uri
8
from oe_utils.utils.file_utils import (
9
    get_file_size,
10
    get_last_modified_date,
11
    convert_size
12
)
13
14
15
class ActorUtilsTest(unittest.TestCase):
16
    def setUp(self):
17
        self.user = {"userid": "jalapjo", "actor": {"uri": "https://actor.test.org.test/a/123", "id": 123,
18
                                                    "omschrijving": "The Jalapeno, Jose"}}
19
20
    def tearDown(self):
21
        pass
22
23
    def test_actor_uri(self):
24
        uri = actor_uri(self.user)
25
        self.assertEqual("https://actor.test.org.test/a/123", uri)
26
27
    def test_actor_uri_na(self):
28
        uri = actor_uri({})
29
        self.assertEqual("NA", uri)
30
31
32
class FileUtilsTest(unittest.TestCase):
33
    def setUp(self):
34
        self.fixtures_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'fixtures')
35
        self.test_file = os.path.join(self.fixtures_path, 'Test_document.pdf')
36
37
    def tearDown(self):
38
        pass
39
40
    def test_get_file_size(self):
41
        filesize = get_file_size(self.test_file)
42
        self.assertEqual('7.94 KB', filesize)
43
44
    def test_get_last_modified_date(self):
45
        today = date.today().strftime('%d/%m/%Y')
46
        # recreate new file to guarantee the last modified date is today
47
        copyfile(self.test_file,
48
                 os.path.join(self.fixtures_path, 'Test_document2.pdf'))
49
        self.new_file = os.path.join(self.fixtures_path, 'Test_document2.pdf')
50
        lm_date = get_last_modified_date(self.new_file)
51
        self.assertEqual(today, lm_date)
52
        os.remove(self.new_file)
53
54
    def test_convert_size(self):
55
        self.assertEqual('2.0 KB', convert_size(2048))
56
        self.assertEqual('20.0 MB', convert_size(20971520))
57
        self.assertEqual('1.0 GB', convert_size(1073741824))
58