diff --git a/tests/assets/url_alias_test/create.yml b/tests/assets/url_alias_test/create.yml new file mode 100644 index 00000000..e4633e13 --- /dev/null +++ b/tests/assets/url_alias_test/create.yml @@ -0,0 +1,12 @@ +task: create +host: "http://localhost:8000" +username: admin +password: islandora +input_dir: "tests/assets/url_alias_test" +input_csv: testing.csv +content_type: article + + +nodes_only: true +allow_missing_files: true + diff --git a/tests/assets/url_alias_test/curr_node_ids.csv b/tests/assets/url_alias_test/curr_node_ids.csv new file mode 100644 index 00000000..fcf37789 --- /dev/null +++ b/tests/assets/url_alias_test/curr_node_ids.csv @@ -0,0 +1,3 @@ +node_id +1550 +1551 diff --git a/tests/assets/url_alias_test/curr_node_ids.csv.prepocessed b/tests/assets/url_alias_test/curr_node_ids.csv.prepocessed new file mode 100644 index 00000000..2f7554c0 --- /dev/null +++ b/tests/assets/url_alias_test/curr_node_ids.csv.prepocessed @@ -0,0 +1,3 @@ +node_id +1548 +1549 diff --git a/tests/assets/url_alias_test/delete.yml b/tests/assets/url_alias_test/delete.yml new file mode 100644 index 00000000..68799fb5 --- /dev/null +++ b/tests/assets/url_alias_test/delete.yml @@ -0,0 +1,8 @@ +task: delete +host: "http://localhost:8000" +username: admin +password: islandora +input_dir: "tests/assets/url_alias_test" +input_csv: curr_node_ids.csv +content_type: article + diff --git a/tests/assets/url_alias_test/rollback.csv b/tests/assets/url_alias_test/rollback.csv new file mode 100644 index 00000000..fcf37789 --- /dev/null +++ b/tests/assets/url_alias_test/rollback.csv @@ -0,0 +1,3 @@ +node_id +1550 +1551 diff --git a/tests/assets/url_alias_test/testing.csv b/tests/assets/url_alias_test/testing.csv new file mode 100644 index 00000000..78d4d6db --- /dev/null +++ b/tests/assets/url_alias_test/testing.csv @@ -0,0 +1,3 @@ +id,title,url_alias +01,Alias1,/test1 +02,Test2,/test2 \ No newline at end of file diff --git a/tests/assets/url_alias_test/testing.csv.prepocessed b/tests/assets/url_alias_test/testing.csv.prepocessed new file mode 100644 index 00000000..b9f5a97b --- /dev/null +++ b/tests/assets/url_alias_test/testing.csv.prepocessed @@ -0,0 +1,3 @@ +id,title,url_alias +01,Alias1,/test1 +02,Test2,/test2 diff --git a/tests/assets/url_alias_test/update.csv b/tests/assets/url_alias_test/update.csv new file mode 100644 index 00000000..5c099188 --- /dev/null +++ b/tests/assets/url_alias_test/update.csv @@ -0,0 +1,3 @@ +node_id,url_alias +1550,/test_update1 +1551,/test_update2 diff --git a/tests/assets/url_alias_test/update.csv.prepocessed b/tests/assets/url_alias_test/update.csv.prepocessed new file mode 100644 index 00000000..44cd3c47 --- /dev/null +++ b/tests/assets/url_alias_test/update.csv.prepocessed @@ -0,0 +1,3 @@ +node_id,url_alias +1550,/test_update1 +1551,/test_update2 diff --git a/tests/assets/url_alias_test/update.yml b/tests/assets/url_alias_test/update.yml new file mode 100644 index 00000000..efc49ff9 --- /dev/null +++ b/tests/assets/url_alias_test/update.yml @@ -0,0 +1,12 @@ +task: update +host: "http://localhost:8000" +username: admin +password: islandora +input_dir: "tests/assets/url_alias_test" +input_csv: update.csv +content_type: article + + +nodes_only: true +allow_missing_files: true + diff --git a/tests/islandora_tests.py b/tests/islandora_tests.py index 448dbdbe..e8700eb3 100644 --- a/tests/islandora_tests.py +++ b/tests/islandora_tests.py @@ -290,6 +290,125 @@ def tearDown(self): os.remove(self.preprocessed_file_path) +class TestUrlAliases(unittest.TestCase): + + def setUp(self): + self.current_dir = os.path.dirname(os.path.abspath(__file__)) + create_config_file_path = os.path.join(self.current_dir, 'assets', 'url_alias_test', 'create.yml') + self.create_cmd = ["./workbench", "--config", create_config_file_path] + + create_csv_file_path = os.path.join(self.current_dir, 'assets', 'url_alias_test', 'testing.csv') + self.input_file = create_csv_file_path + + self.nid_file = os.path.join(self.current_dir, 'assets', 'url_alias_test', 'curr_node_ids.csv') + self.nids = list() + + def test_create(self): + create_output = subprocess.check_output(self.create_cmd) + create_output = create_output.decode().strip() + create_lines = create_output.splitlines() + with open(self.nid_file, "w") as fh: + fh.write("node_id\n") + for line in create_lines: + if 'created at' in line: + nid = line.rsplit('/', 1)[-1] + nid = nid.strip('.') + self.nids.append(nid) + fh.write(nid + "\n") + + self.assertEqual(len(self.nids), 2) + + print("Created initial nodes with url alias") + + #print(self.nids) + + def test_http_req(self): + status = 1 + + with open(self.input_file, "r") as fh: + for line in fh: + if '/' in line: + nid = line.rsplit(',', 1)[-1] + nid = nid.strip() + test_url = "http://drupalvm.test/" + nid + #print(test_url) + resp = requests.get(test_url) + #print(resp.text) + #print(resp.status_code) + if resp.status_code != 200: + raise ValueError("Couldn't connect to url alias") + print("fail 1") + status = 0 + + if (status): + print("[pass1]") + print("Connected to all url aliases") + + def test_http_update(self): + update_csv_file_path = os.path.join(self.current_dir, 'assets', 'url_alias_test', 'update.csv') + + with open(self.nid_file, "r") as fh: + fh.readline() + for line in fh: + nid = line + self.nids.append(nid) + + + with open(update_csv_file_path, "w") as uf: + index = 1 + uf.write("node_id,url_alias\n") + for nid in self.nids: + uf.write(nid.strip('\n') + ",/test_update"+str(index)+"\n") + index = index+1 + + update_config_file_path = os.path.join(self.current_dir, 'assets', 'url_alias_test', 'update.yml') + update_cmd = ["./workbench", "--config", update_config_file_path] + update_output = subprocess.check_output(update_cmd) + update_output = update_output.decode().strip() + update_lines = update_output.splitlines() + + print("updated url aliases") + + + def test_http_update_req(self): + update_csv_file_path = os.path.join(self.current_dir, 'assets', 'url_alias_test', 'update.csv') + + status = 1 + with open(update_csv_file_path, "r") as fh: + for line in fh: + if '/' in line: + nid = line.rsplit(',', 1)[-1] + nid = nid.strip() + test_url = "http://drupalvm.test/" + nid + resp = requests.get(test_url) + if resp.status_code != 200: + raise ValueError("Couldn't connect to updated url aliases") + print("fail 2") + status = 0 + + if (status): + print("[pass2]") + print("Connected to all updated url aliases") + + + + def tearDown(self): + self.rollback_file_path = os.path.join(self.current_dir, 'assets', 'url_alias_test', 'rollback.csv') + if os.path.exists(self.rollback_file_path): + os.remove(self.rollback_file_path) + + self.preprocessed_file_path = os.path.join(self.current_dir, 'assets', 'url_alias_test', 'metadata.csv.prepocessed') + if os.path.exists(self.preprocessed_file_path): + os.remove(self.preprocessed_file_path) + + #delete_config_file_path = os.path.join(self.current_dir, 'assets', 'url_alias_test', 'delete.yml') + #delete_cmd = ["./workbench", "--config", delete_config_file_path] + #delete_output = subprocess.check_output(delete_cmd) + #delete_output = delete_output.decode().strip() + #delete_lines = delete_output.splitlines() + #os.remove(self.nid_file) + + class TestCreateWithFieldTemplatesCheck(unittest.TestCase): def setUp(self):