|
1 | | -# For convenience, just run the tests from its own directory |
2 | | -import os |
| 1 | +# For convenience, just run the tests in the repo root directory. |
3 | 2 | import sys |
4 | 3 |
|
5 | | -os.chdir(os.path.dirname(sys.argv[0])) |
6 | | -sys.path.append("../lib") |
| 4 | +sys.path.append("lib") |
7 | 5 |
|
8 | 6 | import common |
9 | 7 | import url |
@@ -48,27 +46,49 @@ def test_sanitize(): |
48 | 46 |
|
49 | 47 |
|
50 | 48 | def test_validator(): |
51 | | - validator = common.stream_validator(Settings(included_streams=["*"])) |
52 | | - |
53 | | - assert_equal(validator("foo"), True) |
| 49 | + def stream(name, public, web_public): |
| 50 | + # Returns a minimalist stream dictionary. |
| 51 | + return {"name": name, "invite_only": not public, "is_web_public": web_public} |
| 52 | + |
| 53 | + # Test wildcard operator for public streams. |
| 54 | + for k in ["*", "public:*"]: |
| 55 | + validator = common.stream_validator(Settings(included_streams=[k])) |
| 56 | + assert_equal(validator(stream("foo", True, False)), True) |
| 57 | + assert_equal(validator(stream("foo", True, True)), True) |
| 58 | + assert_equal(validator(stream("bar", False, False)), False) |
| 59 | + assert_equal(validator(stream("bar", False, True)), False) |
| 60 | + |
| 61 | + # Test web-public |
| 62 | + validator = common.stream_validator(Settings(included_streams=["web-public:*"])) |
| 63 | + assert_equal(validator(stream("foo", True, False)), False) |
| 64 | + assert_equal(validator(stream("foo", True, True)), True) |
| 65 | + assert_equal(validator(stream("bar", False, False)), False) |
| 66 | + assert_equal(validator(stream("bar", False, True)), True) |
54 | 67 |
|
55 | 68 | validator = common.stream_validator(Settings(included_streams=["foo", "bar"])) |
56 | | - assert_equal(validator("foo"), True) |
57 | | - assert_equal(validator("bar"), True) |
58 | | - assert_equal(validator("baz"), False) |
| 69 | + assert_equal(validator(stream("foo", True, True)), True) |
| 70 | + assert_equal(validator(stream("bar", True, True)), True) |
| 71 | + assert_equal(validator(stream("baz", True, True)), False) |
59 | 72 |
|
| 73 | + # Test exclude. |
60 | 74 | validator = common.stream_validator( |
61 | 75 | Settings(included_streams=["*"], excluded_streams=["bad", "worse"]) |
62 | 76 | ) |
63 | | - assert_equal(validator("good"), True) |
64 | | - assert_equal(validator("bad"), False) |
65 | | - assert_equal(validator("worse"), False) |
| 77 | + assert_equal(validator(stream("good", True, True)), True) |
| 78 | + assert_equal(validator(stream("bad", True, True)), False) |
| 79 | + assert_equal(validator(stream("worse", True, True)), False) |
66 | 80 |
|
67 | 81 | # edge case: excluded takes precedence over included |
68 | 82 | validator = common.stream_validator( |
69 | 83 | Settings(included_streams=["foo"], excluded_streams=["foo"]) |
70 | 84 | ) |
71 | | - assert_equal(validator("foo"), False) |
| 85 | + assert_equal(validator(stream("foo", False, False)), False) |
| 86 | + |
| 87 | + validator = common.stream_validator( |
| 88 | + Settings(included_streams=["baz"], excluded_streams=["bar"]) |
| 89 | + ) |
| 90 | + assert_equal(validator(stream("foo", True, True)), False) |
| 91 | + assert_equal(validator(stream("bar", False, False)), False) |
72 | 92 |
|
73 | 93 |
|
74 | 94 | if __name__ == "__main__": |
|
0 commit comments