Example #1
0
    def test_invalid_json(self):
        """It should raise ValueError if the setting is invalid."""
        config = mock.MagicMock()
        config.registry.settings = {"h.blocklist": "invalid"}

        with pytest.raises(ValueError):
            views._validate_blocklist(config)
Example #2
0
    def test_default_value(self):
        """It should insert an empty dict if there's no setting."""
        config = mock.MagicMock()
        config.registry.settings = {}

        views._validate_blocklist(config)

        assert config.registry.settings["h.blocklist"] == {}
Example #3
0
    def test_valid(self):
        """It should load the setting into a dict."""
        blocklist = {
            "seanh.cc": {},
            "finance.yahoo.com": {},
            "twitter.com": {}
        }
        config = mock.MagicMock()
        config.registry.settings = {"h.blocklist": json.dumps(blocklist)}

        views._validate_blocklist(config)

        assert config.registry.settings["h.blocklist"] == blocklist, (
            "_validate_blocklist() should parse the JSON and turn it into a "
            "dict")