forked from p15670423/monkey
Island: Fix representations to not do nested json
This commit is contained in:
parent
f1e00dd3ee
commit
4357251394
|
@ -1,6 +1,6 @@
|
|||
from http import HTTPStatus
|
||||
|
||||
from flask import make_response, request
|
||||
from flask import request
|
||||
|
||||
from common.credentials import Credentials
|
||||
from monkey_island.cc.repository import ICredentialsRepository
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from json import loads
|
||||
|
||||
import bson
|
||||
from flask import make_response
|
||||
|
@ -19,7 +20,7 @@ class APIEncoder(JSONEncoder):
|
|||
if issubclass(type(value), Enum):
|
||||
return value.name
|
||||
if issubclass(type(value), IJSONSerializable):
|
||||
return value.__class__.to_json(value)
|
||||
return loads(value.__class__.to_json(value))
|
||||
try:
|
||||
return JSONEncoder.default(self, value)
|
||||
except TypeError:
|
||||
|
@ -27,6 +28,6 @@ class APIEncoder(JSONEncoder):
|
|||
|
||||
|
||||
def output_json(value, code, headers=None):
|
||||
resp = make_response(dumps(value, APIEncoder), code)
|
||||
resp = make_response(dumps(value, cls=APIEncoder), code)
|
||||
resp.headers.extend(headers or {})
|
||||
return resp
|
||||
|
|
|
@ -50,7 +50,7 @@ def test_propagation_credentials_endpoint_get(flask_client, credentials_reposito
|
|||
)
|
||||
|
||||
resp = flask_client.get(ALL_CREDENTIALS_URL)
|
||||
actual_propagation_credentials = Credentials.from_json_array(resp.text)
|
||||
actual_propagation_credentials = [Credentials.from_mapping(creds) for creds in resp.json]
|
||||
|
||||
assert resp.status_code == HTTPStatus.OK
|
||||
assert len(actual_propagation_credentials) == 4
|
||||
|
@ -76,7 +76,7 @@ def test_propagation_credentials_endpoint__get_stolen(flask_client, credentials_
|
|||
)
|
||||
|
||||
resp = flask_client.get(url)
|
||||
actual_propagation_credentials = Credentials.from_json_array(resp.text)
|
||||
actual_propagation_credentials = [Credentials.from_mapping(creds) for creds in resp.json]
|
||||
|
||||
assert resp.status_code == HTTPStatus.OK
|
||||
assert len(actual_propagation_credentials) == 2
|
||||
|
@ -98,7 +98,7 @@ def test_propagation_credentials_endpoint__post_stolen(flask_client, credentials
|
|||
assert resp.status_code == HTTPStatus.NO_CONTENT
|
||||
|
||||
resp = flask_client.get(url)
|
||||
retrieved_propagation_credentials = Credentials.from_json_array(resp.text)
|
||||
retrieved_propagation_credentials = [Credentials.from_mapping(creds) for creds in resp.json]
|
||||
|
||||
assert resp.status_code == HTTPStatus.OK
|
||||
assert len(retrieved_propagation_credentials) == 3
|
||||
|
|
Loading…
Reference in New Issue