Пример #1
0
    def test_odata_v4_exception(self):
        message = {
            "error": {
                "code": "501",
                "message": "Unsupported functionality",
                "target": "query",
                "details": [{
                    "code": "301",
                    "target": "$search",
                    "message": "$search query option not supported",
                }],
                "innererror": {
                    "trace": [],
                    "context": {}
                }
            }
        }
        exp = ODataV4Error(_build_response(json.dumps(message).encode("utf-8")))

        assert exp.code == "501"
        assert exp.message == "Unsupported functionality"
        assert exp.target == "query"
        assert exp.details[0].code == "301"
        assert exp.details[0].target == "$search"
        assert "trace" in exp.innererror
        assert "context" in exp.innererror

        message = {}
        exp = ODataV4Error(_build_response(json.dumps(message).encode("utf-8")))
        assert exp.message == "Operation returned an invalid status 'Bad Request'"

        exp = ODataV4Error(_build_response(b""))
        assert exp.message == "Operation returned an invalid status 'Bad Request'"
        assert str(exp) == "Operation returned an invalid status 'Bad Request'"
 def test_odata_v4_minimal(self, mock_response):
     """Minimal valid OData v4 is code/message and nothing else.
     """
     message = {
         "error": {
             "code": "501",
             "message": "Unsupported functionality",
         }
     }
     exp = ODataV4Error(mock_response(json.dumps(message).encode("utf-8")))
     assert exp.code == "501"
     assert exp.message == "Unsupported functionality"
     assert exp.target is None
     assert exp.details == []
     assert exp.innererror == {}