test_remove_pardir_symbols_remove_pardir_symobls()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
dl 0
loc 5
rs 9.4285
1
# coding=utf-8
2
"""
3
"""
4
__author__ = 'Alisue <[email protected]>'
5
from django.test import TestCase
6
from roughpages.utils import (url_to_filename,
7
                              remove_pardir_symbols,
8
                              replace_dots_to_underscores_at_last)
9
from roughpages.tests.compat import patch
10
11
12
class RoughpagesUtilsTestCase(TestCase):
13
    def test_url_to_filename_remove_leading_slash(self):
14
        url = "/aaa/bbb/ccc"
15
        expected = "aaa/bbb/ccc"
16
        self.assertEqual(url_to_filename(url),
17
                         expected)
18
19
    def test_url_to_filename_remove_trailing_slash(self):
20
        url = "aaa/bbb/ccc/"
21
        expected = "aaa/bbb/ccc"
22
        self.assertEqual(url_to_filename(url),
23
                         expected)
24
25
    def test_url_to_filename_remove_call_remove_pardir_symbols(self):
26
        with patch('roughpages.utils.remove_pardir_symbols') as p:
27
            url_to_filename("")
28
            self.assertTrue(p.called)
29
30
    def test_url_to_filename_remove_call_replace_dots_to_underscores_at_last(self):
31
        with patch('roughpages.utils.replace_dots_to_underscores_at_last') as p:
32
            url_to_filename("")
33
            self.assertTrue(p.called)
34
35
    def test_remove_pardir_symbols_remove_pardir_symobls(self):
36
        path = "/../A/../B/../C/../"
37
        expected = "/A/B/C/"
38
        self.assertEqual(remove_pardir_symbols(path),
39
                         expected)
40
41
    def test_replace_dots_to_underscores_at_last(self):
42
        path = '/AA.AA.AA/BB.BB.BB/CC.CC.CC'
43
        expected = '/AA.AA.AA/BB.BB.BB/CC_CC_CC'
44
        self.assertEqual(replace_dots_to_underscores_at_last(path),
45
                         expected)
46