def test_public_data_anonymous(self, mock_public_listing): """Testing anonymouse access to: /data/browser /data/browser/public /data/browser/public/nees.public /data/browser/public/nees.public/folder """ urls = [ '/data/browser', '/data/browser/public', '/data/browser/public/nees.public', '/data/browser/public/nees.public/folder'] mock_public_listing.return_value = self.es_listing_json for url in urls: url_components = url.strip('/').split('/') resource = None file_path = None if len(url_components) >= 3: resource = url_components[2] if len(url_components) > 3: file_path = '/'.join(url_components[3:]) #Create request request = RequestFactory().get(url) request.user = AnonymousUser() #Initi view test_view = DataBrowserTestView() #Setup view for testing test_view = self.view_to_test(test_view, request, resource = resource, file_path = file_path) #We're just going to get the context data. context = test_view.get_context_data(**test_view.kwargs) angular_init = json.loads(context['angular_init']) keys = angular_init.keys() self.assertIn('currentSource', keys) self.assertIn('sources', keys) self.assertIn('listing', keys) self.assertIn('state', keys) self.assertIsNotNone(angular_init['currentSource']) self.assertIsNotNone(angular_init['sources']) self.assertIsNotNone(angular_init['listing']) self.assertIsNotNone(angular_init['state']) self.assertIsNotNone(angular_init['state']['search']) if len(url_components) <= 3: mock_public_listing.assert_called_with(None) else: mock_public_listing.assert_called_with('/'.join(url_components[3:]))
from designsafe.apps.data.views.api import * from django.conf.urls import url, patterns from designsafe.apps.data.views.base import (BasePrivateTemplate, BasePublicTemplate, DataBrowserTestView, DataDepotView) from django.core.urlresolvers import reverse from django.utils.translation import ugettext_lazy as _ urlpatterns = patterns( 'designsafe.apps.data.views.base', url(r'^my/$', BasePrivateTemplate.as_view(template_name='data/file-manager/my_data.html'), name='my_data'), url(r'^public/$', BasePublicTemplate.as_view(template_name='data/file-manager/public_data.html'), name='public_data'), url(r'^browser-legacy/$', DataBrowserTestView.as_view(template_name='data/browser.html'), name='data_browser'), url(r'^browser-legacy/(?P<resource>[\w.-]+)/$', DataBrowserTestView.as_view(template_name='data/browser.html'), name='data_browser'), url(r'^browser-legacy/(?P<resource>[\w.-]+)/(?P<file_path>[ \S]+)/?$', DataBrowserTestView.as_view(template_name='data/browser.html'), name='data_browser'), url(r'^browser/', DataDepotView.as_view(template_name='data/data_depot.html'), name='data_depot') ) urlpatterns += patterns('designsafe.apps.data.views.api', url(r'^api/default/listings/(?P<file_path>[ \S]+)?$', ListingsView.as_view(filesystem='default'), name='listings'), url(r'^api/default/download/(?P<file_path>[ \S]+)?$', DownloadView.as_view(filesystem='default'), name='download'),