Пример #1
0
 def test_eq_operator__considers_path_template_only(self):
     route1 = routes.CDNRoute("/foo/bar", {"hello", "world"}, sizable=False)
     route2 = routes.CDNRoute("/foo/bar", {"i", "said", "meow"}, sizable=True)
     route3 = routes.CDNRoute("/foo/bar", {"i", "said", "meow"}, sizable=False)
     route4 = routes.CDNRoute("/foo/bar/baz", {"i", "said", "meow"}, sizable=True)
     assert route1 == route2
     assert route1 == route3
     assert route1 != route4
     assert route2 == route3
     assert route2 != route4
     assert route3 != route4
Пример #2
0
 def test_hash_operator_considers_path_template_only(self):
     route1 = routes.CDNRoute("/foo/bar", {"hello", "world"}, sizable=False)
     route2 = routes.CDNRoute("/foo/bar", {"i", "said", "meow"}, sizable=True)
     route3 = routes.CDNRoute("/foo/bar", {"i", "said", "meow"}, sizable=False)
     route4 = routes.CDNRoute("/foo/bar/baz", {"i", "said", "meow"}, sizable=True)
     assert hash(route1) == hash(route2)
     assert hash(route1) == hash(route3)
     assert hash(route1) != hash(route4)
     assert hash(route2) == hash(route3)
     assert hash(route2) != hash(route4)
     assert hash(route3) != hash(route4)
Пример #3
0
 def test_passing_size_on_sizable_does_not_raise_TypeError(self):
     route = routes.CDNRoute("/foo/bar", {"png", "jpg", "gif"},
                             sizable=True)
     route.compile("http://example.com",
                   file_format="png",
                   hash="boooob",
                   size=128)
Пример #4
0
 def test_requesting_non_gif_on_animated_hash_does_not_raise_TypeError(
         self, format):
     route = routes.CDNRoute("/foo/bar", {"png", "jpg", "webp", "gif"},
                             sizable=False)
     route.compile("http://example.com",
                   file_format=format,
                   hash="a_boooob")
Пример #5
0
 def test_requesting_gif_on_non_animated_hash_raises_TypeError(self):
     route = routes.CDNRoute("/foo/bar", {"png", "jpg", "gif"},
                             sizable=False)
     with pytest.raises(TypeError):
         route.compile("http://example.com",
                       file_format="gif",
                       hash="boooob")
Пример #6
0
 def test_passing_no_size_does_not_add_query_string(self):
     route = routes.CDNRoute("/foo/bar", {"png", "jpg", "gif"},
                             sizable=True)
     compiled_url = route.compile("http://example.com",
                                  file_format="png",
                                  hash="boooob")
     assert "?size=" not in compiled_url, f"compiled_url={compiled_url}"
Пример #7
0
 def test_compile_uses_lowercase_file_format_always(self, input_file_format,
                                                    expected_file_format):
     route = routes.CDNRoute("/foo/bar", {"png", "jpg"}, sizable=False)
     compiled_url = route.compile("http://example.com",
                                  file_format=input_file_format)
     assert compiled_url.endswith(
         f".{expected_file_format}"), f"compiled_url={compiled_url}"
Пример #8
0
 def test_passing_negative_sizes_to_sizable_raises_ValueError(self, size):
     route = routes.CDNRoute("/foo/bar", {"png", "jpg", "png"},
                             sizable=True)
     with pytest.raises(ValueError, match="size must be positive"):
         route.compile("http://example.com",
                       file_format="png",
                       hash="boooob",
                       size=size)
Пример #9
0
 def test_passing_size_on_non_sizable_raises_TypeError(self):
     route = routes.CDNRoute("/foo/bar", {"png", "jpg", "gif"},
                             sizable=False)
     with pytest.raises(TypeError):
         route.compile("http://example.com",
                       file_format="png",
                       hash="boooob",
                       size=128)
Пример #10
0
 def test_passing_valid_sizes_to_sizable_does_not_raise_ValueError(
         self, size):
     route = routes.CDNRoute("/foo/bar", {"png", "jpg", "gif"},
                             sizable=True)
     route.compile("http://example.com",
                   file_format="png",
                   hash="boooob",
                   size=size)
Пример #11
0
 def test_passing_size_adds_query_string(self):
     route = routes.CDNRoute("/foo/bar", {"png", "jpg", "gif"},
                             sizable=True)
     compiled_url = route.compile("http://example.com",
                                  file_format="png",
                                  hash="boooob",
                                  size=128)
     assert compiled_url.endswith(
         ".png?size=128"), f"compiled_url={compiled_url}"
Пример #12
0
 def test_compile_generates_expected_url(self, base_url, template, format,
                                         size_kwds, foo, bar, expected_url):
     route = routes.CDNRoute(template, {"png", "gif", "jpg", "webp"},
                             sizable=True)
     actual_url = route.compile(base_url=base_url,
                                file_format=format,
                                foo=foo,
                                bar=bar,
                                **size_kwds)
     assert actual_url == expected_url
Пример #13
0
 def test_passing_invalid_magnitude_sizes_to_sizable_raises_ValueError(
         self, size):
     route = routes.CDNRoute("/foo/bar", {"png", "jpg", "png"},
                             sizable=True)
     with pytest.raises(
             ValueError,
             match=
             "size must be an integer power of 2 between 16 and 4096 inclusive"
     ):
         route.compile("http://example.com",
                       file_format="png",
                       hash="boooob",
                       size=size)
Пример #14
0
 def test_formats_converted_to_frozenset(self):
     route = routes.CDNRoute("/foo/bar", {"i", "really", "like", "cats"})
     assert isinstance(route.valid_formats, frozenset)
     assert route.valid_formats == {"i", "really", "like", "cats"}
Пример #15
0
 def test_formats_converted_to_lower(self):
     route = routes.CDNRoute("/foo/bar", {"FOO", "BaR", "bAz", "bork"})
     assert route.valid_formats == {"foo", "bar", "baz", "bork"}
Пример #16
0
 def test_any_formats_results_in_no_error(self):
     routes.CDNRoute("/foo/bar", {"do", "ray", "me"})
Пример #17
0
 def test_zero_formats_results_in_error(self):
     with pytest.raises(
             ValueError,
             match="/foo/bar must have at least one valid format set"):
         routes.CDNRoute("/foo/bar", set())
Пример #18
0
 def test_disallowed_file_format_raises_TypeError(self):
     route = routes.CDNRoute("/foo/bar", {"png", "jpg"}, sizable=False)
     with pytest.raises(TypeError):
         route.compile("http://example.com", file_format="gif")
Пример #19
0
 def test_allowed_file_format_does_not_raise_TypeError(self):
     route = routes.CDNRoute("/foo/bar", {"png", "jpg"}, sizable=False)
     route.compile("http://example.com", file_format="png")
Пример #20
0
 def test_requesting_gif_without_passing_hash_does_not_raise_TypeError(
         self):
     route = routes.CDNRoute("/foo/bar", {"png", "jpg", "gif"},
                             sizable=False)
     route.compile("http://example.com", file_format="gif")