From 44bdef8b5cb198fee3659d1462e608a0330c48ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20Mag=C3=A1n?= Date: Fri, 7 Nov 2014 10:37:08 +0100 Subject: [PATCH] Fix #16 --- .../fanstatic/allowed_users.js | 17 +++++---- .../privatedatasets/tests/test_selenium.py | 38 +++++++++++++++++-- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/ckanext/privatedatasets/fanstatic/allowed_users.js b/ckanext/privatedatasets/fanstatic/allowed_users.js index 268497d..07315ef 100644 --- a/ckanext/privatedatasets/fanstatic/allowed_users.js +++ b/ckanext/privatedatasets/fanstatic/allowed_users.js @@ -27,6 +27,7 @@ this.ckan.module('allowed-users', function ($, _) { return { initialize: function() { + this.original_acquire_url = $('[name=acquire_url]').val(); $('#field-private').on('change', this._onChange); this._onChange(); //Initial }, @@ -34,17 +35,19 @@ this.ckan.module('allowed-users', function ($, _) { var ds_private = $('#field-private').val(); if (ds_private == 'True') { - $('#field-allowed_users_str').prop('disabled', false); //Enable - $('#field-acquire_url').prop('disabled', false); //Enable - $('#field-searchable').prop('disabled', false); //Enable + $('#field-allowed_users_str').prop('disabled', false); //Enable + $('#field-acquire_url').prop('disabled', false); //Enable + $('#field-searchable').prop('disabled', false); //Enable + $('[name=acquire_url]').val(this.original_acquire_url); //Set previous acquire URL } else { - $('#field-allowed_users_str').prop('disabled', true); //Disable - $('#field-acquire_url').prop('disabled', true); //Disable - $('#field-searchable').prop('disabled', true); //Disable + $('#field-allowed_users_str').prop('disabled', true); //Disable + $('#field-acquire_url').prop('disabled', true); //Disable + $('#field-searchable').prop('disabled', true); //Disable //Remove previous values $('#field-allowed_users_str').select2('val', ''); - $('#field-acquire_url').val(''); + this.original_acquire_url = $('[name=acquire_url]').val(); //Get previous value + $('[name=acquire_url]').val(''); //Acquire URL should be reseted $('#field-searchable').val('True'); } } diff --git a/ckanext/privatedatasets/tests/test_selenium.py b/ckanext/privatedatasets/tests/test_selenium.py index 0a13a48..d34bf39 100644 --- a/ckanext/privatedatasets/tests/test_selenium.py +++ b/ckanext/privatedatasets/tests/test_selenium.py @@ -129,7 +129,7 @@ class TestSelenium(unittest.TestCase): driver.find_element_by_id('username').send_keys(user) driver.find_element_by_name('submit').click() - def create_ds_first_page(self, name, description, tags, private, searchable, allowed_users, acquire_url): + def fill_ds_general_info(self, name, description, tags, private, searchable, allowed_users, acquire_url): # FIRST PAGE: Dataset properties driver = self.driver driver.get(self.base_url) @@ -160,7 +160,7 @@ class TestSelenium(unittest.TestCase): def create_ds(self, name, description, tags, private, searchable, allowed_users, acquire_url, resource_url, resource_name, resource_description, resource_format): driver = self.driver - self.create_ds_first_page(name, description, tags, private, searchable, allowed_users, acquire_url) + self.fill_ds_general_info(name, description, tags, private, searchable, allowed_users, acquire_url) # SECOND PAGE: Add Resources try: @@ -182,6 +182,11 @@ class TestSelenium(unittest.TestCase): # THIRD PAGE: Metadata driver.find_element_by_xpath('(//button[@name=\'save\'])[4]').click() + def modify_ds(self, url, name, description, tags, private, searchable, allowed_users, acquire_url): + driver = self.driver + driver.get('%sdataset/edit/%s' % (self.base_url, url)) + self.fill_ds_general_info(name, description, tags, private, searchable, allowed_users, acquire_url) + def check_ds_values(self, url, private, searchable, allowed_users, acquire_url): driver = self.driver driver.get(self.base_url + 'dataset/edit/' + url) @@ -330,7 +335,7 @@ class TestSelenium(unittest.TestCase): # Create the dataset self.login(user, user) pkg_name = 'Dataset 2' - self.create_ds_first_page(pkg_name, 'Example description', ['tag1'], True, True, allowed_users, acquire_url) + self.fill_ds_general_info(pkg_name, 'Example description', ['tag1'], True, True, allowed_users, acquire_url) # Check the error message msg_error = self.driver.find_element_by_xpath('//div[@id=\'content\']/div[3]/div/section/div/form/div/ul/li').text @@ -481,4 +486,29 @@ class TestSelenium(unittest.TestCase): acquired = user in adquiring_users in_org = user in orgs[0]['users'] self.check_user_access(pkg_name, url, False, acquired, in_org, private, searchable, acquire_url) - self.check_acquired(pkg_name, url, acquired, private) \ No newline at end of file + self.check_acquired(pkg_name, url, acquired, private) + + def test_bug_16(self): + """ + Private datasets cannot be turned to public datasets when the Acquisition URL is set + """ + user = 'user1' + self.default_register(user) + + # The user creates a dataset + self.login(user, user) + pkg_name = 'Dataset 1' + description = 'Example Description' + tags = ['tag1', 'tag2', 'tag3'] + url = get_dataset_url(pkg_name) + self.create_ds(pkg_name, 'Example description', ['tag1', 'tag2', 'tag3'], True, True, + [], 'http://example.com', 'http://upm.es', 'UPM Main', 'Example Description', 'CSV') + + self.modify_ds(self, url, pkg_name, description, tags, False, None, None, None) + expected_url = 'dataset/%s' % url + current_url = self.driver.current_url + self.assertEquals(expected_url, current_url) + + + +