# Path: chaosmonkey/api/hal.py
# class Document(BaseDocument):
#     """Constructs a ``HAL`` document.
#     """
# 
#     def __init__(self, data=None, links=None, embedded=None, external_self=False):
#         """Initialises a new ``HAL`` Document instance. If no arguments are
#         provided a minimal viable ``HAL`` Document is created.
# 
#         Keyword Args:
#             data (dict): Data for the document
#             links (chaosmonkey.api.hal.link.Collection): A collection of ``HAL`` links
#             embedded: TBC
#             external_self: use a fully-qualified link for self
# 
#         Raises:
#             TypeError: If ``links`` is not a :class:`chaosmonkey.api.hal.link.Collection`
#         """
#         super(Document, self).__init__(data, links, embedded)
#         self.links.append(Self(external=external_self))


from flask import url_for
from chaosmonkey.api.hal import Document
import test.planners.planner1 as planner1_module
import test.planners.planner2 as planner2_module


def test_empty_planners_store_return_hal(app, manager):
    url = url_for("planners.list_planners")

    planners_list = []
    manager.planners_store.set_modules(planners_list)

    with app.test_request_context(url):
        res = app.test_client().get(url)
        assert res.status_code == 200
        assert res.mimetype == "application/hal+json"
        assert res.json == Document(data={"planners": []}).to_dict()


def test_planners_list_return_hal(app, manager):
    url = url_for("planners.list_planners")

    module_list = [planner1_module, planner2_module]
    manager.planners_store.set_modules(module_list)

    with app.test_request_context(url):

        planner_list = [planner1_module.Planner1("planner1").to_dict(), planner2_module.Planner2("planner2").to_dict()]

        res = app.test_client().get(url)
        assert res.status_code == 200
        assert res.mimetype == "application/hal+json"

# Path: chaosmonkey/api/hal.py
# class Document(BaseDocument):
#     """Constructs a ``HAL`` document.
#     """
# 
#     def __init__(self, data=None, links=None, embedded=None, external_self=False):
#         """Initialises a new ``HAL`` Document instance. If no arguments are
#         provided a minimal viable ``HAL`` Document is created.
# 
#         Keyword Args:
#             data (dict): Data for the document
#             links (chaosmonkey.api.hal.link.Collection): A collection of ``HAL`` links
#             embedded: TBC
#             external_self: use a fully-qualified link for self
# 
#         Raises:
#             TypeError: If ``links`` is not a :class:`chaosmonkey.api.hal.link.Collection`
#         """
#         super(Document, self).__init__(data, links, embedded)
#         self.links.append(Self(external=external_self))


# Path: test/unit/chaosmonkey/api/planners_blueprint_test.py
from flask import url_for
from chaosmonkey.api.hal import Document
import test.planners.planner1 as planner1_module
import test.planners.planner2 as planner2_module



def test_empty_planners_store_return_hal(app, manager):
    url = url_for("planners.list_planners")

    planners_list = []
    manager.planners_store.set_modules(planners_list)

    with app.test_request_context(url):
        res = app.test_client().get(url)
        assert res.status_code == 200
        assert res.mimetype == "application/hal+json"
        assert res.json == Document(data={"planners": []}).to_dict()


def test_planners_list_return_hal(app, manager):
    url = url_for("planners.list_planners")

    module_list = [planner1_module, planner2_module]
    manager.planners_store.set_modules(module_list)

    with app.test_request_context(url):

        planner_list = [planner1_module.Planner1("planner1").to_dict(), planner2_module.Planner2("planner2").to_dict()]

        res = app.test_client().get(url)
        assert res.status_code == 200
        assert res.mimetype == "application/hal+json"

        assert res.json == Document(data={"planners": planner_list}).to_dict()