File: test_exceptions.py

package info (click to toggle)
python-marathon 0.13.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 460 kB
  • sloc: python: 1,969; makefile: 185; sh: 58
file content (38 lines) | stat: -rw-r--r-- 1,166 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import json

import requests

from marathon.exceptions import MarathonHttpError, InternalServerError


def test_400_error():
    fake_response = requests.Response()
    fake_message = "Invalid JSON"
    fake_details = [{"path": "/taskKillGracePeriodSeconds", "errors": ["error.expected.jsnumber"]}]
    fake_response._content = json.dumps({"message": fake_message, "details": fake_details}).encode()
    fake_response.status_code = 400
    fake_response.headers['Content-Type'] = 'application/json'

    exc = MarathonHttpError(fake_response)
    assert exc.status_code == 400
    assert exc.error_message == fake_message
    assert exc.error_details == fake_details


def test_503_error():
    fake_response = requests.Response()
    fake_response._content = """<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 503 </title>
</head>
<body>
<h2>HTTP ERROR: 503</h2>
</body>
</html>"""
    fake_response.reason = "reason"
    fake_response.status_code = 503

    exc = InternalServerError(fake_response)
    assert exc.status_code == 503
    assert exc.error_message == "reason"
    assert not hasattr(exc, 'error_details')