Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
maurosoria
GitHub Repository: maurosoria/dirsearch
Path: blob/master/tests/utils/test_common.py
896 views
1
# -*- coding: utf-8 -*-
2
# This program is free software; you can redistribute it and/or modify
3
# it under the terms of the GNU General Public License as published by
4
# the Free Software Foundation; either version 2 of the License, or
5
# (at your option) any later version.
6
#
7
# This program is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
# GNU General Public License for more details.
11
#
12
# You should have received a copy of the GNU General Public License
13
# along with this program; if not, write to the Free Software
14
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
15
# MA 02110-1301, USA.
16
#
17
# Author: Mauro Soria
18
19
from unittest import TestCase
20
21
from lib.utils.common import (
22
merge_path,
23
replace_path,
24
strip_and_uniquify,
25
get_valid_filename,
26
)
27
28
29
class TestCommonUtils(TestCase):
30
def test_replace_path(self):
31
self.assertEqual(replace_path("/abc or /abc?k=v", "abc", "REPLACED"), "REPLACED or REPLACED?k=v", "Path was not replaced")
32
self.assertEqual(replace_path("http://a.co/abc", "abc", "REPLACED"), "http://a.coREPLACED", "Path was not replaced")
33
self.assertEqual(replace_path("http://a.co/abcdef", "abc", "REPLACED"), "http://a.co/abcdef", "Path was replaced even though it should have not")
34
35
def test_strip_and_uniquify(self):
36
self.assertEqual(strip_and_uniquify(["foo", "bar", " bar ", "foo"]), ["foo", "bar"], "The results are not stripped or contain duplicates or in wrong order")
37
38
def test_get_valid_filename(self):
39
self.assertEqual(get_valid_filename("http://example.com:80/foobar"), "http___example.com_80_foobar", "Invalid filename for Windows")
40
41
def test_merge_path(self):
42
self.assertEqual(merge_path("http://example.com/foo", "bar"), "http://example.com/bar")
43
self.assertEqual(merge_path("http://example.com/folder/", "foo/../bar/./"), "http://example.com/folder/bar/")
44
45