diff --git a/ckanext/odsh/tests/ckan_selenium.py b/ckanext/odsh/tests/ckan_selenium.py new file mode 100644 index 0000000000000000000000000000000000000000..f3ffd93c90f3aa8640190df9a36c6e9d524662eb --- /dev/null +++ b/ckanext/odsh/tests/ckan_selenium.py @@ -0,0 +1,94 @@ + +from selenium import webdriver +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import Select +from selenium.webdriver.common.action_chains import ActionChains + + +from seleniumrequests import Chrome +import uuid +import pdb + + +class SeleniumCkanApp: + + def __init__(self): + self.base_url = "http://141.91.184.85" + self.driver = Chrome() + + def login(self): + self.driver.get(self.url("/user/login")) + assert "Open Data Schleswig-Holstein" in self.driver.title + elem = self.driver.find_element_by_id("field-login") + elem.clear() + elem.send_keys("sysadmin") + elem = self.driver.find_element_by_id("field-password") + elem.clear() + elem.send_keys("OpenData!0619") + elem.send_keys(Keys.RETURN) + print(self.driver.title) + assert "Datens" in self.driver.title + # assert "No results found." not in driver.page_source + + def create_package(self): + guid = str(uuid.uuid4()) + title = 'test_' + guid + data = {"name": title, "title": title, "notes": "This is an automated Upload", "owner_org": "stadt-norderstedt", "license_id": "http://dcat-ap.de/def/licenses/dl-by-de/2.0", + "extras": [{"key": "licenseAttributionByText", "value": "Test Lizenz"}, {"key": "issued", "value": "2019-04-23T09:18:11"}, { + "key": "spatial_uri", "value": "http://dcat-ap.de/def/politicalGeocoding/regionalKey/010600063063"}, {"key": "temporal_start", "value": "1989-01-01T00:00:00"}, {"key": "temporal_end", "value": "1993-12-19T00:00:00"}], "tags": [{"name": "Test"}], "resources": [{"name": "A distribution for this dataset", "format": "HTML", "url": "https://www.google.de/"}], + "groups": [{"id": "econ"}] + } + response = self.driver.request('POST', self.url( + '/api/3/action/package_create'), data) + pdb.set_trace() + + def url(self, path): + return self.base_url + path + + def got_to_url(self, path): + self.driver.get(self.url(path)) + + def close(): + driver.close() + + def get_slave_flag(self): + return self.findElementByXPath("//meta[@data-name='type']").get_attribute("content") + + def findElementByXPath(self, xpath): + return self.driver.find_element(By.XPATH, xpath) + + def findElementByName(self, name): + return self.driver.find_element_by_name(name) + + def findElementById(self, id): + return self.driver.find_element_by_id(id) + + def findElementByClassName(self, clazz): + return self.driver.find_element_by_class_name(clazz) + + def fill_form(self, data, keyprefix=''): + for key, value in data.iteritems(): + elem = self.driver.find_element_by_id(keyprefix + key) + elem.send_keys(value) + + def select_by_visible_text(self, fieldId, text): + select = Select(self.driver.find_element_by_id(fieldId)) + select.select_by_visible_text(text) + + def select_by_value(self, fieldId, value): + select = Select(self.driver.find_element_by_id(fieldId)) + select.select_by_value(value) + + def clickOnElement(self, elem): + loc = elem.location + action = ActionChains(self.driver) + action.move_by_offset(loc['x'], loc['y']) + action.click().perform() + + def currentUrl(self): + return self.driver.current_url + + def onMaster(self): + cont = self.get_slave_flag() + return cont == u'0' diff --git a/ckanext/odsh/tests/rdf_catalog_empty.xml b/ckanext/odsh/tests/rdf_catalog_empty.xml new file mode 100644 index 0000000000000000000000000000000000000000..7af9ac96ee981d5fbae560abe1858aede7e11eb7 --- /dev/null +++ b/ckanext/odsh/tests/rdf_catalog_empty.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="utf-8"?> +<rdf:RDF + xmlns:foaf="http://xmlns.com/foaf/0.1/" + xmlns:locn="http://www.w3.org/ns/locn#" + xmlns:hydra="http://www.w3.org/ns/hydra/core#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:dcat="http://www.w3.org/ns/dcat#" + xmlns:dct="http://purl.org/dc/terms/" + xmlns:dcatde="http://dcat-ap.de/def/dcatde/1.0.1/" + xmlns:skos="http://www.w3.org/2004/02/skos/core#" + xmlns:schema="http://schema.org/" +> + <dcat:Catalog rdf:about="http://192.168.57.3:5000"> + <dcat:dataset> + <dcat:Dataset rdf:about="http://opendata.schleswig-holstein.de/dataset/norderstedt-gehwege"> + <dct:title>Gehwege</dct:title> + <dcat:distribution> + <dcat:Distribution rdf:about="http://opendata.schleswig-holstein.de/dataset/norderstedt-gehwege/resource"> + <dcat:accessURL rdf:resource="http://185.223.104.6/data/norderstedt/7002_Gehwege_F.zip" /> + <dct:license rdf:resource="http://dcat-ap.de/def/licenses/dl-zero-de/2.0" /> + + <dct:format rdf:resource="http://publications.europa.eu/resource/authority/file-type/SHP" /> + </dcat:Distribution> + </dcat:distribution> + <dcat:theme rdf:resource="http://publications.europa.eu/resource/authority/data-theme/TRAN" /> + <dct:description>Gehwege</dct:description> + <dct:language rdf:resource="http://publications.europa.eu/resource/authority/language/DEU" /> + <dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2018-10-12</dct:issued> + <dct:license rdf:resource="http://dcat-ap.de/def/licenses/dl-zero-de/2.0" /> + + <dct:publisher> + <foaf:Organization rdf:about="http://opendata.schleswig-holstein.de/norderstedt" /> + </dct:publisher> + <dct:spatial> + <dct:Location rdf:about="http://dcat-ap.de/def/politicalGeocoding/regionalKey/010600063063" /> + </dct:spatial> + <dct:temporal> + <dct:PeriodOfTime> + <schema:startDate rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2018-10-12</schema:startDate> + </dct:PeriodOfTime> + </dct:temporal> + <dcat:keyword>Gehwege</dcat:keyword> + </dcat:Dataset> + </dcat:dataset> + </dcat:Catalog> +</rdf:RDF> diff --git a/ckanext/odsh/tests/test_selenium.py b/ckanext/odsh/tests/test_selenium.py new file mode 100644 index 0000000000000000000000000000000000000000..189cfc0144a2d861e67b19763e96be3d1cae0def --- /dev/null +++ b/ckanext/odsh/tests/test_selenium.py @@ -0,0 +1,66 @@ +# coding: utf-8 +from nosedep import depends + +from ckanext.odsh.tests.ckan_selenium import SeleniumCkanApp +import pdb +import uuid + + +test_org = 'testherausgeber' + + +class TestSelenium: + + app = None + + @classmethod + def setup_class(cls): + TestSelenium.app = SeleniumCkanApp() + # TestSelenium.app.login() + + def notest_edit_paths(self): + paths = ['/organization/edit/' + test_org, + '/dataset/edit/testtesttest', + '/dataset/testtesttest/resource_edit/afaec407-d033-439d-a699-fe9279b20e6b', + '/dataset/new_resource/testtesttest', + '/dataset/new?group=', + '/harvest', + '/harvest/test2', + '/harvest/admin/test2' + ] + for path in paths: + TestSelenium.app.got_to_url(path) + cont = TestSelenium.app.get_slave_flag() + assert cont == u'0' + + def test_login(self): + TestSelenium.app.login() + assert '/dataset' in TestSelenium.app.currentUrl() + + @depends(after=test_login) + def test_create_dataset(self): + TestSelenium.app.got_to_url('/dataset/new?group=') + # assert TestSelenium.app.onMaster() + + guid = str(uuid.uuid4()) + title = 'test_' + guid + data = {"field-title": title, "field-notes": title, 'datepicker_start': '26.06.2019', + 'field-spatial_uri-value': 'http://dcat-ap.de/def/politicalGeocoding/districtKey/01001'} + TestSelenium.app.fill_form(data) + TestSelenium.app.select_by_visible_text( + 'field-license', 'Creative Commons CC Zero License (cc-zero)') + + elem = TestSelenium.app.findElementByClassName( + 'multiselect-native-select') + TestSelenium.app.clickOnElement(elem) + TestSelenium.app.findElementByXPath("//input[@value = 'soci']").click() + TestSelenium.app.clickOnElement(elem) + + TestSelenium.app.findElementByName('save').click() + TestSelenium.app.findElementByXPath("//a[text()='Link']").click() + + TestSelenium.app.fill_form( + {'field-image-url': 'url.png', 'field-format': 'png'}) + TestSelenium.app.findElementById('form-submit-button').click() + + assert 'dataset/'+title in TestSelenium.app.currentUrl()