~ltrager/maas/lp1554636_2.0

« back to all changes in this revision

Viewing changes to src/maasserver/api/tests/test_describe.py

Merge Blake's branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
__all__ = []
7
7
 
8
8
import http.client
9
 
import json
10
9
from operator import itemgetter
11
10
from urllib.parse import urlparse
12
11
 
20
19
from maasserver.api.doc_handler import describe
21
20
from maasserver.testing.factory import factory
22
21
from maasserver.testing.testcase import MAASServerTestCase
 
22
from maasserver.utils.converters import json_load_bytes
23
23
from testscenarios import multiply_scenarios
24
24
from testtools.matchers import (
25
25
    AfterPreprocessing,
49
49
                (Equals(http.client.OK),
50
50
                 Equals("application/json"),
51
51
                 StartsWith(b'{'),
52
 
                 Contains('name'))),
 
52
                 Contains(b'name'))),
53
53
            response)
54
54
 
55
55
    def test_describe(self):
56
56
        response = self.client.get(reverse('describe'))
57
 
        description = json.loads(response.content)
 
57
        description = json_load_bytes(response.content)
58
58
        self.assertSetEqual(
59
59
            {"doc", "handlers", "resources", "hash"}, set(description))
60
60
        self.assertIsInstance(description["handlers"], list)
61
61
 
62
62
    def test_describe_hash_is_the_api_hash(self):
63
63
        response = self.client.get(reverse('describe'))
64
 
        description = json.loads(response.content)
 
64
        description = json_load_bytes(response.content)
65
65
        self.assertThat(
66
66
            description["hash"], Equals(
67
67
                get_api_description_hash()))
102
102
            http.client.OK, response.status_code,
103
103
            "API description failed with code %s:\n%s"
104
104
            % (response.status_code, response.content))
105
 
        return json.loads(response.content)
 
105
        return json_load_bytes(response.content)
106
106
 
107
107
    def patch_script_prefix(self, script_name):
108
108
        """Patch up Django's and Piston's notion of the script_name prefix.