Exemple #1
0
    def test_json_no_side_effect_on_subsequent_call(self):
        """Test that subsequent call is not polluted with results of previous.

        If the translate_kwargs method is called, resulting in the content-type
        header being added, the header should not also be added on a subsequent
        call that does not need it.
        """
        api = GerritRestAPI(url="http://review.example.com")
        json = {"a": "a"}
        result = api.translate_kwargs(json=json)
        assert "json" in result
        assert "data" not in result
        assert "headers" in result
        headers = result["headers"]
        assert "Content-Type" in headers
        assert result["json"] == {"a": "a"}
        assert headers["Content-Type"] == "application/json;charset=UTF-8"
        kwargs = {"a": "a", "b": "b"}
        result = api.translate_kwargs(**kwargs)
        assert "json" not in result
        assert "data" not in result
        assert "a" in result
        assert "b" in result
        assert "headers" in result
        headers = result["headers"]
        assert "Content-Type" not in headers
Exemple #2
0
    def test_json_no_side_effect_on_subsequent_call(self):
        """Test that subsequent call is not polluted with results of previous.

        If the translate_kwargs method is called, resulting in the content-type
        header being added, the header should not also be added on a subsequent
        call that does not need it.
        """
        api = GerritRestAPI(url="http://review.example.com")
        json = {"a": "a"}
        result = api.translate_kwargs(json=json)
        assert "json" in result
        assert "data" not in result
        assert "headers" in result
        headers = result["headers"]
        assert "Content-Type" in headers
        assert result["json"] == {"a": "a"}
        assert headers["Content-Type"] == "application/json;charset=UTF-8"
        kwargs = {"a": "a", "b": "b"}
        result = api.translate_kwargs(**kwargs)
        assert "json" not in result
        assert "data" not in result
        assert "a" in result
        assert "b" in result
        assert "headers" in result
        headers = result["headers"]
        assert "Content-Type" not in headers
Exemple #3
0
 def test_data_and_json(self):
     """Test that `json` and `data` cannot be used at the same time."""
     api = GerritRestAPI(url="http://review.example.com")
     with self.assertRaises(ValueError) as exc:
         api.translate_kwargs(data="d", json="j")
     assert re.search(r'Cannot use data and json together',
                      str(exc.exception))
Exemple #4
0
 def test_data_as_string_is_unchanged(self):
     """Test that `data` is unchanged when passed as a string."""
     api = GerritRestAPI(url="http://review.example.com")
     kwargs = {"data": "Content with non base64 valid chars åäö"}
     result = api.translate_kwargs(**kwargs)
     assert "json" not in result
     assert "data" in result
     assert result["data"] == "Content with non base64 valid chars åäö"
     assert "headers" in result
     headers = result["headers"]
     assert "Content-Type" not in headers
Exemple #5
0
 def test_data_as_string_is_unchanged(self):
     """Test that `data` is unchanged when passed as a string."""
     api = GerritRestAPI(url="http://review.example.com")
     kwargs = {"data": "Content with non base64 valid chars åäö"}
     result = api.translate_kwargs(**kwargs)
     assert "json" not in result
     assert "data" in result
     assert result["data"] == "Content with non base64 valid chars åäö"
     assert "headers" in result
     headers = result["headers"]
     assert "Content-Type" not in headers
Exemple #6
0
 def test_kwargs_unchanged_when_no_data_or_json(self):
     """Test that `json` or `data` are not added when not passed."""
     api = GerritRestAPI(url="http://review.example.com")
     kwargs = {"a": "a", "b": "b"}
     result = api.translate_kwargs(**kwargs)
     assert "json" not in result
     assert "data" not in result
     assert "a" in result
     assert "b" in result
     assert "headers" in result
     headers = result["headers"]
     assert "Content-Type" not in headers
Exemple #7
0
 def test_json_is_unchanged_and_header_added(self):
     """Test that `json` is unchanged and a Content-Type header is added."""
     api = GerritRestAPI(url="http://review.example.com")
     json = {"a": "a"}
     result = api.translate_kwargs(json=json)
     assert "json" in result
     assert "data" not in result
     assert "headers" in result
     headers = result["headers"]
     assert "Content-Type" in headers
     assert result["json"] == {"a": "a"}
     assert headers["Content-Type"] == "application/json;charset=UTF-8"
Exemple #8
0
 def test_kwargs_unchanged_when_no_data_or_json(self):
     """Test that `json` or `data` are not added when not passed."""
     api = GerritRestAPI(url="http://review.example.com")
     kwargs = {"a": "a", "b": "b"}
     result = api.translate_kwargs(**kwargs)
     assert "json" not in result
     assert "data" not in result
     assert "a" in result
     assert "b" in result
     assert "headers" in result
     headers = result["headers"]
     assert "Content-Type" not in headers
Exemple #9
0
 def test_json_is_unchanged_and_header_added(self):
     """Test that `json` is unchanged and a Content-Type header is added."""
     api = GerritRestAPI(url="http://review.example.com")
     json = {"a": "a"}
     result = api.translate_kwargs(json=json)
     assert "json" in result
     assert "data" not in result
     assert "headers" in result
     headers = result["headers"]
     assert "Content-Type" in headers
     assert result["json"] == {"a": "a"}
     assert headers["Content-Type"] == "application/json;charset=UTF-8"
Exemple #10
0
    def test_data_as_dict_converts_to_json_and_header_added(self):
        """Test that `data` dict is converted to `json`.

        Also test that a Content-Type header is added.
        """
        api = GerritRestAPI(url="http://review.example.com")
        data = {"a": "a"}
        result = api.translate_kwargs(data=data)
        assert "json" in result
        assert "data" not in result
        assert "headers" in result
        headers = result["headers"]
        assert "Content-Type" in headers
        assert result["json"] == {"a": "a"}
        assert headers["Content-Type"] == "application/json;charset=UTF-8"
Exemple #11
0
    def test_data_as_dict_converts_to_json_and_header_added(self):
        """Test that `data` dict is converted to `json`.

        Also test that a Content-Type header is added.
        """
        api = GerritRestAPI(url="http://review.example.com")
        data = {"a": "a"}
        result = api.translate_kwargs(data=data)
        assert "json" in result
        assert "data" not in result
        assert "headers" in result
        headers = result["headers"]
        assert "Content-Type" in headers
        assert result["json"] == {"a": "a"}
        assert headers["Content-Type"] == "application/json;charset=UTF-8"