Coverage for api/tests/test_validators.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import pytest
3from shopyo.api import validators
4from shopyo.api import constants
7class TestValidators:
8 """Tests validator methods"""
10 @pytest.mark.parametrize(
11 "url,expected",
12 [
13 ("google", False),
14 ("www.google.com", True),
15 ("https://www.google.com", True),
16 ("localhost:3000", True),
17 ("192.168.0.250", True),
18 ("2001:0db8:85a3:0000:0000:8a2e:0370:7334", True),
19 ],
20 )
21 def test_is_valid_url(self, url, expected):
22 result = validators.is_valid_url(url)
23 assert result == expected
27 @pytest.mark.parametrize(
28 "string,expected",
29 [
30 ("efwfwefwefwef", True),
31 ("wehfbweur76tr46348tr", True),
32 ("uwfehbuweify2874gr34_____________", True),
33 ("^uefew.", False),
34 ("wefwfwe/wfwefewf/ewfwef", False),
35 ("""%^$^$£%£""£%"£""", False),
36 ("""%^$^$£%£""£%"£__""", False),
37 ("""%^$^$£%£""£%"£wdwqdqwd__""", False),
38 ("""%^$^$£%£""£%"£423423423""", False),
39 ],
40 )
41 def test_is_alpha_num_underscore(self, string, expected):
42 result = validators.is_alpha_num_underscore(string)
43 assert result == expected
47 @pytest.mark.parametrize(
48 "string,expected",
49 [
50 (" ", True),
51 ("", True),
52 (" adqwd", False),
53 ("wefwefwef", False)
54 ],
55 )
56 def test_is_empty_str(self, string, expected):
57 result = validators.is_empty_str(string)
58 assert result == expected
61 @pytest.mark.parametrize(
62 "string,expected",
63 [
64 ("wefwf-wfwefwef-wefwef", True),
65 ("-wefwef-ewfwef-wefwef-wefwef", True),
66 ("-wefefwef-", True),
67 ("-w6ef78wef687ewf6-wefwef-", True),
68 ("---", True),
69 ("/efiewf/", False),
70 ("(ewfewf)", False)
71 ],
72 )
73 def test_is_valid_slug(self, string, expected):
74 result = validators.is_valid_slug(string)
75 assert bool(result) == expected
78class TestConstants:
81 def test_constants(self):
82 assert constants.SEP_CHAR == '#'
83 assert constants.SEP_NUM == 23