# Path: achilles/common.py
# def achilles_plugins():
#     """
#     Return a dict of the enabled plugins with achilles namespace as keys
#     """
#     return getattr(settings, 'ACHILLES_PLUGINS',
#                    {
#                        'blocks': 'achilles.blocks',
#                        'actions': 'achilles.actions',
#                        'console': 'achilles.console',
#                        'redirect': 'achilles.redirect',
#                        'messages': 'achilles.messages',
#                    })
# 
# Path: achilles/views.py
# def endpoint(request):
#     if request.method != 'POST':
#         return HttpResponseBadRequest()
# 
#     match = CONTENT_TYPE_RE.match(request.META['CONTENT_TYPE'])
#     if match:
#         charset = match.group(1)
#     else:
#         charset = settings.DEFAULT_CHARSET
# 
#     transport = AchillesTransport(request)
#     data = json.loads(request.body.decode(charset))
#     run_actions(transport, data)
# 
#     result = {}
#     for (namespace, render) in achilles_renders().items():
#         result[namespace] = render(transport)
# 
#     return HttpResponse(json.dumps(result), content_type="application/json")


from django.test import RequestFactory, TestCase
from django.conf import settings
from achilles.common import achilles_plugins
from achilles.views import endpoint
import json




class ActionsTests(TestCase):

    @classmethod
    def setupClass(cls):
        cls.request_factory = RequestFactory()

    def setUp(self):
        self.request = self.request_factory.post(
            '/path', data='[]',
            content_type='application/octet-stream')

    def test_json_endpoint(self):
        result = endpoint(self.request)
        data = json.loads(result.content.decode(settings.DEFAULT_CHARSET))


# Path: achilles/common.py
# def achilles_plugins():
#     """
#     Return a dict of the enabled plugins with achilles namespace as keys
#     """
#     return getattr(settings, 'ACHILLES_PLUGINS',
#                    {
#                        'blocks': 'achilles.blocks',
#                        'actions': 'achilles.actions',
#                        'console': 'achilles.console',
#                        'redirect': 'achilles.redirect',
#                        'messages': 'achilles.messages',
#                    })
# 
# Path: achilles/views.py
# def endpoint(request):
#     if request.method != 'POST':
#         return HttpResponseBadRequest()
# 
#     match = CONTENT_TYPE_RE.match(request.META['CONTENT_TYPE'])
#     if match:
#         charset = match.group(1)
#     else:
#         charset = settings.DEFAULT_CHARSET
# 
#     transport = AchillesTransport(request)
#     data = json.loads(request.body.decode(charset))
#     run_actions(transport, data)
# 
#     result = {}
#     for (namespace, render) in achilles_renders().items():
#         result[namespace] = render(transport)
# 
#     return HttpResponse(json.dumps(result), content_type="application/json")


# Path: achilles/tests/test_views.py
from django.test import RequestFactory, TestCase
from django.conf import settings
from achilles.common import achilles_plugins
from achilles.views import endpoint
import json





class ActionsTests(TestCase):

    @classmethod
    def setupClass(cls):
        cls.request_factory = RequestFactory()

    def setUp(self):
        self.request = self.request_factory.post(
            '/path', data='[]',
            content_type='application/octet-stream')

    def test_json_endpoint(self):
        result = endpoint(self.request)
        data = json.loads(result.content.decode(settings.DEFAULT_CHARSET))


        self.assertEqual(set(achilles_plugins().keys()), set(data.keys()))