-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_path_genius_app.py
149 lines (107 loc) · 4.44 KB
/
test_path_genius_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"""Test cases for the application."""
# * Author(s): Thomas Glanzer
# * Creation : Oct 2023
# * License : MIT
# %% ----------------------------------
# * Import libraries
import pytest
from path_genius_app import (check_string, mac_to_windows_path,
windows_to_mac_path)
# %% ----------------------------------
# * Define test cases
@pytest.mark.parametrize("possible_link, expected_link_type", [
# Test case for smb:// links
(r"smb://example.corp/_path/folder/etc", -1),
# Test case with leading whitespaces
(r" smb://example.corp/_path/folder/etc", -1),
# Test case with trailing slash
(r"smb://example.corp/_path/folder/etc/", -1),
# Test case without smb://
(r"//example.corp/_path/folder/etc", -1),
# Test case with a file
(r"smb://example.corp/_path/folder/etc/file.txt", -1),
# Test case for file:// links
(r"file:\\example.corp\_path\folder\etc", 1),
# Test case with leading whitespace
(r" file:\\example.corp\_path\folder\etc", 1),
# Test case with trailing slash
(r"file:\\example.corp\_path\folder\etc" + "\\", 1),
# Test case without file://
(r"\\example.corp\_path\folder\etc", 1),
# Test case with a file
(r"file:\\example.corp\_path\folder\etc\file.txt", 1),
# Normal web link
(r"https://example.com", 0),
# Normal string
(r"normal string", 0),
# Empty string
("", 0),
# String with both forward and backslashes
(r"normal string/with/forward\and\backslashes", 0),
])
def test_check_string(possible_link, expected_link_type):
"""Test the identify_string function."""
link_type, _ = check_string(possible_link)
assert link_type == expected_link_type
@pytest.mark.parametrize("mac_path, expected_windows_path", [
# Test case for smb:// links
(r"smb://example.corp/_path/folder/etc",
r"file:\\example.corp\_path\folder\etc"),
# Test case with trailing backslash
(r"smb://example.corp/_path/folder/etc/",
r"file:\\example.corp\_path\folder\etc" + "\\"),
# Test case with a file
(r"smb://example.corp/_path/folder/etc/file.txt",
r"file:\\example.corp\_path\folder\etc\file.txt"),
# Test case with leading whitespace
(r" smb://example.corp/_path/folder/etc",
r"file:\\example.corp\_path\folder\etc"),
# Test case with leading and trailing whitespaces
(r" smb://example.corp/_path/folder/etc ",
r"file:\\example.corp\_path\folder\etc"),
# Test case without smb://
(r"//example.corp/_path/folder/etc",
r"file:\\example.corp\_path\folder\etc"),
# Normal string with whitespace
(r" normal string ", r" normal string "),
])
def test_mac_to_windows_path(mac_path, expected_windows_path):
"""Test the mac_to_windows_path function."""
# Get a clean string
_, cleaned_link = check_string(mac_path)
windows_path = mac_to_windows_path(cleaned_link)
assert windows_path == expected_windows_path
@pytest.mark.parametrize("windows_path, expected_mac_path", [
# Test case for file:// links
(r"file:\\example.corp\_path\folder\etc",
r"smb://example.corp/_path/folder/etc"),
# Test case with trailing backslash
(r"file:\\example.corp\_path\folder\etc" + "\\",
r"smb://example.corp/_path/folder/etc/"),
# Test case with a file
(r"file:\\example.corp\_path\folder\etc\file.txt",
r"smb://example.corp/_path/folder/etc/file.txt"),
# Test case with leading whitespace
(r" file:\\example.corp\_path\folder\etc",
r"smb://example.corp/_path/folder/etc"),
# Test case with leading and trailing whitespaces
(r" file:\\example.corp\_path\folder\etc ",
r"smb://example.corp/_path/folder/etc"),
# Test case without file://
(r"\\example.corp\_path\folder\etc",
r"smb://example.corp/_path/folder/etc"),
# Normal string with whitespace
(r" normal string ", r" normal string "),
# Test case with file:// and forward slashes
(r"file://example.corp/_path/folder/etc",
r"smb://example.corp/_path/folder/etc"),
# Test case with file:// and forward slashes and trailing slash
(r"file://example.corp/_path/folder/etc/",
r"smb://example.corp/_path/folder/etc/"),
])
def test_windows_to_mac_path(windows_path, expected_mac_path):
"""Test the windows_to_mac_path function."""
# Get a clean string
_, cleaned_link = check_string(windows_path)
mac_path = windows_to_mac_path(cleaned_link)
assert mac_path == expected_mac_path