Example #1
0
    def test_library_not_staff(self, mock_ProxyApp, mock_TethysApp,
                               mock_render, mock_custom_template):
        mock_request = mock.MagicMock()
        mock_request.user.is_staff = False

        mock_app1 = mock.MagicMock()
        mock_app1.configured = True
        mock_app2 = mock.MagicMock()
        mock_app2.configured = False
        mock_TethysApp.objects.all.return_value = [mock_app1, mock_app2]

        mock_proxy_app1 = mock.MagicMock(spec=ProxyApp)
        mock_ProxyApp.objects.all.return_value = [mock_proxy_app1]
        mock_custom_template.return_value = mock.MagicMock(
            content='custom_templates/test.html')

        mock_render.return_value = True

        ret = library(mock_request)
        self.assertEqual(ret, mock_render.return_value)
        mock_TethysApp.objects.all.assert_called_once()
        mock_ProxyApp.objects.all.assert_called_once()

        proxy_app_dict = {
            'proxied': True,
            'show_in_apps_library': mock_proxy_app1.show_in_apps_library,
            'enabled': mock_proxy_app1.enabled,
            'url': mock_proxy_app1.endpoint,
            'icon': mock_proxy_app1.logo_url,
            'name': mock_proxy_app1.name,
            'description': mock_proxy_app1.description,
            'tags': mock_proxy_app1.tags
        }

        # Unconfigured apps hidden to non-staff users
        expected_context = {
            'apps': {
                'configured': [mock_app1, proxy_app_dict],
                'unconfigured': []
            }
        }
        mock_render.assert_called_with(mock_request,
                                       'custom_templates/test.html',
                                       expected_context)
Example #2
0
    def test_library_no_staff(self, mock_tethys_app, mock_render):
        mock_request = mock.MagicMock()
        mock_request.user.is_staff = False
        mock_app1 = mock.MagicMock()
        mock_app1.configured = True
        mock_app2 = mock.MagicMock()
        mock_app2.configured = False
        mock_tethys_app.objects.all.return_value = [mock_app1, mock_app2]
        mock_render.return_value = True

        ret = library(mock_request)
        self.assertEqual(ret, mock_render.return_value)
        mock_tethys_app.objects.all.assert_called_once()
        mock_render.assert_called_once_with(
            mock_request, 'tethys_apps/app_library.html',
            {'apps': {
                'configured': [mock_app1],
                'unconfigured': []
            }})