Skip to content

Commit

Permalink
fix angular table
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Sep 14, 2017
1 parent d4a99a7 commit b2f9b00
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 195 deletions.
10 changes: 5 additions & 5 deletions daiquiri/core/static/core/js/table.js
Expand Up @@ -9,13 +9,13 @@ angular.module('core')
scope: {
'rowsUrl': '@',
'columnsUrl': '@',
'fileBaseUrl': '@',
'filesUrl': '@',
'params': '=',
'pageSizes': '='
},
link: function(scope, element, attrs) {
scope.table = TableService;
scope.table.init(scope.rowsUrl, scope.columnsUrl, scope.fileBaseUrl, scope.params, scope.pageSizes);
scope.table.init(scope.rowsUrl, scope.columnsUrl, scope.filesUrl, scope.params, scope.pageSizes);

// refresh the tooltips everytime a new set of columns is fetched
scope.$watch(function() {
Expand Down Expand Up @@ -104,7 +104,7 @@ angular.module('core')
modal: {},
};

service.init = function(rows_url, columns_url, file_base_url, params, page_sizes) {
service.init = function(rows_url, columns_url, files_url, params, page_sizes) {
service.ready = false;

// set up resources
Expand All @@ -116,8 +116,8 @@ angular.module('core')
}

// setup file base url
if (angular.isDefined(file_base_url)) {
service.file_base_url = baseurl + file_base_url
if (angular.isDefined(files_url)) {
service.file_base_url = baseurl + files_url + '?search=';
}

// add params from the dom to service.params
Expand Down
11 changes: 4 additions & 7 deletions daiquiri/files/tests/test_views.py
@@ -1,12 +1,9 @@
import os

from django.conf import settings
from django.test import TestCase

from test_generator.views import TestViewMixin


class ServeViewTestCase(TestCase):
class FilesViewTestCase(TestCase):

fixtures = (
'auth.json',
Expand All @@ -21,7 +18,7 @@ class ServeViewTestCase(TestCase):
)


class InternalFileTests(TestViewMixin, ServeViewTestCase):
class InternalFileTests(TestViewMixin, FilesViewTestCase):

url_names = {
'list_view': 'files:file'
Expand All @@ -35,11 +32,11 @@ class InternalFileTests(TestViewMixin, ServeViewTestCase):

def _test_get(self, username):
self.assert_list_view(username, kwargs={
'file_path': 'www/'
'file_path': 'html/'
})


class PrivateFileTests(TestViewMixin, ServeViewTestCase):
class PrivateFileTests(TestViewMixin, FilesViewTestCase):

url_names = {
'list_view': 'files:file'
Expand Down
190 changes: 11 additions & 179 deletions daiquiri/files/tests/test_viewsets.py
Expand Up @@ -3,220 +3,52 @@
from test_generator.viewsets import TestViewsetMixin


class ServeTestCase(TestCase):
class FilesViewsetTestCase(TestCase):

fixtures = (
'auth.json',
'metadata.json',
'jobs.json',
'queryjobs.json'
'files.json'
)

users = (
('admin', 'admin'),
('manager', 'manager'),
('user', 'user'),
('anonymous', None),
)

status_map = {
'list_viewset': {
'admin': 200, 'user': 403, 'anonymous': 403
},
'retrieve_viewset': {
'admin': 200, 'user': 403, 'anonymous': 403
},
'create_viewset': {
'admin': 201, 'user': 403, 'anonymous': 403
},
'update_viewset': {
'admin': 200, 'user': 403, 'anonymous': 403
},
'delete_viewset': {
'admin': 204, 'user': 403, 'anonymous': 403
},
'discover_viewset': {
'admin': 200, 'user': 403, 'anonymous': 403
},
'management_viewset': {
'admin': 200, 'user': 403, 'anonymous': 403
},
'user_viewset': {
'admin': 200, 'user': 200, 'anonymous': 200
}
}


class PublicRowTests(TestViewsetMixin, ServeTestCase):
class InternalFileTests(TestViewsetMixin, FilesViewsetTestCase):

url_names = {
'viewset': 'serve:row'
'viewset': 'files:file'
}

status_map = {
'list_viewset': {
'admin': 200, 'user': 200, 'anonymous': 200
'admin': 200, 'manager': 200, 'user': 200, 'anonymous': 404
}
}

def _test_list_viewset(self, username):
self.assert_list_viewset(username, query_params={
'database': 'daiquiri_data_obs',
'table': 'stars'
'search': 'index.html',
})


class InternalRowTests(TestViewsetMixin, ServeTestCase):
class PrivateFileTests(TestViewsetMixin, FilesViewsetTestCase):

url_names = {
'viewset': 'serve:row'
'viewset': 'files:file'
}

status_map = {
'list_viewset': {
'admin': 200, 'user': 200, 'anonymous': 404
'admin': 404, 'manager': 200, 'user': 404, 'anonymous': 404
}
}

def _test_list_viewset(self, username):
self.assert_list_viewset(username, query_params={
'database': 'daiquiri_data_sim',
'table': 'particles'
})


class UserRowTests(TestViewsetMixin, ServeTestCase):

url_names = {
'viewset': 'serve:row'
}

status_map = {
'list_viewset': {
'admin': 404, 'user': 200, 'anonymous': 404
}
}

def _test_list_viewset(self, username):
self.assert_list_viewset(username, query_params={
'database': 'daiquiri_user_user',
'table': 'test'
})


class NotFoundRowTests(TestViewsetMixin, ServeTestCase):

url_names = {
'viewset': 'serve:row'
}

status_map = {
'list_viewset': {
'admin': 404, 'user': 404, 'anonymous': 404
}
}

def _test_non_existing_database_viewset(self, username):
self.assert_list_viewset(username, query_params={
'database': 'non_existing',
'table': 'stars'
})

def _test_non_existing_table_viewset(self, username):
self.assert_list_viewset(username, query_params={
'database': 'daiquiri_data_obs',
'table': 'non_existing'
})

def _test_non_existing_user_table_viewset(self, username):
self.assert_list_viewset(username, query_params={
'database': 'daiquiri_user_user',
'table': 'non_existing'
})


class PublicColumnTests(TestViewsetMixin, ServeTestCase):

url_names = {
'viewset': 'serve:column'
}

status_map = {
'list_viewset': {
'admin': 200, 'user': 200, 'anonymous': 200
}
}

def _test_list_viewset(self, username):
self.assert_list_viewset(username, query_params={
'database': 'daiquiri_data_obs',
'table': 'stars'
})


class InternalColumnTests(TestViewsetMixin, ServeTestCase):

url_names = {
'viewset': 'serve:column'
}

status_map = {
'list_viewset': {
'admin': 200, 'user': 200, 'anonymous': 404
}
}

def _test_list_viewset(self, username):
self.assert_list_viewset(username, query_params={
'database': 'daiquiri_data_sim',
'table': 'particles'
})


class UserColumnTests(TestViewsetMixin, ServeTestCase):

url_names = {
'viewset': 'serve:column'
}

status_map = {
'list_viewset': {
'admin': 404, 'user': 200, 'anonymous': 404
}
}

def _test_list_viewset(self, username):
self.assert_list_viewset(username, query_params={
'database': 'daiquiri_user_user',
'table': 'test'
})


class NotFoundColumnTests(TestViewsetMixin, ServeTestCase):

url_names = {
'viewset': 'serve:column'
}

status_map = {
'list_viewset': {
'admin': 404, 'user': 404, 'anonymous': 404
}
}

def _test_non_existing_database_viewset(self, username):
self.assert_list_viewset(username, query_params={
'database': 'non_existing',
'table': 'stars'
})

def _test_non_existing_table_viewset(self, username):
self.assert_list_viewset(username, query_params={
'database': 'daiquiri_data_obs',
'table': 'non_existing'
})

def _test_non_existing_user_table_viewset(self, username):
self.assert_list_viewset(username, query_params={
'database': 'daiquiri_user_user',
'table': 'non_existing'
'search': 'image_00.jpg',
})
8 changes: 6 additions & 2 deletions daiquiri/files/utils.py
Expand Up @@ -13,7 +13,11 @@ def get_file(user, file_path):

results = set()
for directory in directories:
absolute_file_path = os.path.join(directory.path, file_path)
# normalize the file path so that /a/b/c and b/c/d/e become /a/b/c and d/e
normalized_file_path = normalize_file_path(directory.path, file_path)

# join directory_path and file_path so that it becomes /a/b/c/d/e
absolute_file_path = os.path.join(directory.path, normalized_file_path)

# check if absolute_file_path is actually a file
if os.path.isfile(absolute_file_path):
Expand All @@ -40,7 +44,7 @@ def search_file(user, file_path):

# join directory_path and file_path so that it becomes /a/b/c/d/e
absolute_file_path = os.path.join(directory_path, normalized_file_path)
print(os.path.isfile(absolute_file_path))

# check if absolute_file_path is actually a file
if os.path.isfile(absolute_file_path):
results.add(absolute_file_path)
Expand Down
2 changes: 1 addition & 1 deletion daiquiri/query/static/query/js/services/query.js
Expand Up @@ -178,7 +178,7 @@ app.factory('QueryService', ['$resource', '$injector', '$q', '$filter', 'Polling
service.form = null;
service.fetchJob(job).then(function() {
if (service.job.phase == 'COMPLETED') {
service.table = TableService.init('serve/api/rows/', 'serve/api/columns/', 'serve/file/', {
service.table = TableService.init('serve/api/rows/', 'serve/api/columns/', 'files/api/files/', {
database: service.job.database_name,
table: service.job.table_name
});
Expand Down
2 changes: 1 addition & 1 deletion daiquiri/serve/templates/serve/table.html
Expand Up @@ -33,7 +33,7 @@ <h1>{{ database }}.{{ table }}</h1>
<div daiquiri-table
data-rows-url="serve/api/rows/"
data-columns-url="serve/api/columns/"
data-file-base-url="serve/file/"
data-files-url="files/api/files/"
data-params="{database: '{{ database }}', table: '{{ table }}'}">
</div>

Expand Down
File renamed without changes.

0 comments on commit b2f9b00

Please sign in to comment.