Exemplo n.º 1
0
    def test_it_works(self, rf, mocker, static_url_pattern):
        mock_reverse = mocker.patch("normandy.base.api.views.reverse")
        mock_reverse.return_value = "/test"
        view = APIRootView.as_view(api_urls=[static_url_pattern])

        res = view(rf.get("/test"))
        assert mock_reverse.called
        assert res.status_code == 200
        res.render()
        assert json.loads(res.content.decode()) == {"test-view": "http://testserver/test"}
Exemplo n.º 2
0
    def test_it_works(self, rf, mocker, static_url_pattern_conf):
        mock_reverse = mocker.patch("normandy.base.api.views.reverse")
        mock_reverse.return_value = "/test"
        view = APIRootView.as_view(urlconf=static_url_pattern_conf)

        res = view(rf.get("/test"))
        assert mock_reverse.called
        assert res.status_code == 200
        res.render()
        assert json.loads(res.content.decode()) == {"test-view": "http://testserver/test"}
Exemplo n.º 3
0
    def test_dynamic_views_and_no_setting(self, rf, mocker, settings, dynamic_url_pattern):
        mock_reverse = mocker.patch("normandy.base.api.views.reverse")
        mock_reverse.return_value = "/test"
        settings.APP_SERVER_URL = None
        view = APIRootView.as_view(api_urls=[dynamic_url_pattern])

        res = view(rf.get("/test"))
        assert mock_reverse.called
        assert res.status_code == 200
        res.render()
        assert json.loads(res.content.decode()) == {"test-view": "http://testserver/test"}
Exemplo n.º 4
0
    def test_dynamic_views_and_no_setting(self, rf, mocker, settings, dynamic_url_pattern_conf):
        mock_reverse = mocker.patch("normandy.base.api.views.reverse")
        mock_reverse.return_value = "/test"
        settings.APP_SERVER_URL = None
        view = APIRootView.as_view(urlconf=dynamic_url_pattern_conf)

        res = view(rf.get("/test"))
        assert mock_reverse.called
        assert res.status_code == 200
        res.render()
        assert json.loads(res.content.decode()) == {"test-view": "http://testserver/test"}
Exemplo n.º 5
0
    def test_it_reroutes_dynamic_views(self, rf, mocker, settings, dynamic_url_pattern):
        mock_reverse = mocker.patch('normandy.base.api.views.reverse')
        mock_reverse.return_value = '/test'
        settings.APP_SERVER_URL = 'https://testserver-app/'
        view = APIRootView.as_view(api_urls=[dynamic_url_pattern])

        res = view(rf.get('/test'))
        assert mock_reverse.called
        assert res.status_code == 200
        res.render()
        assert json.loads(res.content.decode()) == {
            'test-view': 'https://testserver-app/test',
        }
Exemplo n.º 6
0
    def test_it_reroutes_dynamic_views(self, rf, mocker, settings,
                                       dynamic_url_pattern_conf):
        mock_reverse = mocker.patch("normandy.base.api.views.reverse")
        mock_reverse.return_value = "/test"
        settings.APP_SERVER_URL = "https://testserver-app/"
        view = APIRootView.as_view(urlconf=dynamic_url_pattern_conf)

        res = view(rf.get("/test"))
        assert mock_reverse.called
        assert res.status_code == 200
        res.render()
        assert json.loads(res.content.decode()) == {
            "test-view": "https://testserver-app/test"
        }
Exemplo n.º 7
0
from django.conf.urls import url

from normandy.base.api.views import APIRootView

app_name = "base"

urlpatterns = [url(r"^$", APIRootView.as_view())]
Exemplo n.º 8
0
from django.conf.urls import include, url

from normandy.base.api.routers import MixedViewRouter
from normandy.base.api.v3 import views
from normandy.base.api.views import APIRootView


# API Router
router = MixedViewRouter()
router.register("user", views.UserViewSet)
router.register("group", views.GroupViewSet)


app_name = "base"

urlpatterns = [
    url(r"^$", APIRootView.as_view()),
    url(r"^service_info/", views.ServiceInfoView.as_view(), name="service-info"),
    url(r"", include(router.urls)),
]