Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests for creating URL aliases #154

Open
mjordan opened this issue Nov 27, 2020 · 23 comments
Open

Add integration tests for creating URL aliases #154

mjordan opened this issue Nov 27, 2020 · 23 comments
Labels
testing User, unit, and integration testing

Comments

@mjordan
Copy link
Owner

mjordan commented Nov 27, 2020

No description provided.

@mjordan mjordan added the testing User, unit, and integration testing label Nov 27, 2020
@mjordan
Copy link
Owner Author

mjordan commented Feb 24, 2021

@Ansel-Hong thanks very much for taking this on.

Here are some preliminary steps:

  1. integration tests require a running Islandora Playbook on the same machine as Workbench (e.g. at http://localhost:8000).
  2. fork/clone this repo and create a branch called issue-154 for your work.
  3. the only file you need to change is tests/islandora_test.py
  4. you are going to need a directory for your CSV and .yml files within tests/assets. I suggest naming it tests/assets/url_alias_test.
  5. before you commit your changes, check for code style by running within the islandora_workbench directory pycodestyle --show-source --show-pep8 --ignore=E402,W504 --max-line-length=200 tests/islandora_tests.py
  6. since you are not testing media creation, I recommend adding nodes_only: true to the .yml file you are using for the create test.

For this specific integration test, I would copy the TestCreate class at https://github.com/mjordan/islandora_workbench/blob/main/tests/islandora_tests.py#L250 and use it as the basis for your test. If I were you, for the create task I would create some nodes with URL aliases, then issue an HTTP request to the alias and see if you get a 200 response for each aliased node.

In your assets directory, create a simple input CSV file (maybe using input_data/metadata.csv as its basis) and add a url_alias column.

You will also need a configuration file in this assets directory. It will need to point to your input CSV (and should contain nodes_only: true). Your test class's setUp() function will need to point to this config file.

Once you have this all set up, you can run only your new test class using the following command (assumes your new test class is called TestUrlAliases): python3 tests/islandora_tests.py TestUrlAliases. Don't forget that your Playbook needs to be running since Workbench actually creates nodes during this test.

Is this enough to get you going? If so, we can check in whenever you need more help. The test for the update task is bit trickier since your CSV file will need to know the node IDs of the nodes created during the test. I can offer some guidance on how I've done this in other tests if you want.

@Ansel-Hong
Copy link

@mjordan Hi, can I get some tidbits as to how to find the node ID for the update task, and also do I need the node ID for the delete task as well or is there another way to do that, thanks.

@mjordan
Copy link
Owner Author

mjordan commented Feb 26, 2021

I'm tied up today but I'll provide a bit more info over the weekend. Thanks!

@mjordan
Copy link
Owner Author

mjordan commented Feb 28, 2021

https://github.com/mjordan/islandora_workbench/blob/main/tests/islandora_tests.py#L406 shows how I get the nids for a delete test - write them to a temporary file that has node_id as its first line (required by the delete task) and then append each node ID that is created to this file. Then, to delete them, use that file as the CSV input in a delete task. Finally, remove the temporary node file. Does that make sense?

@Ansel-Hong
Copy link

Ah makes sense, and for the update task do I have to somehow merge the node_id file and the other columns of the create file

@mjordan
Copy link
Owner Author

mjordan commented Mar 1, 2021

Good question. Instead of merging, I would add some simple field data to the file I am writing out, for example:

node_id,field_description,field_extent
245,A description,2 items

@Ansel-Hong
Copy link

Hi, sorry for taking so long to respond, just finished exams recently. I would like to ask why I'm getting a error message when I delete nodes saying
Traceback (most recent call last): File "./workbench", line 920, in <module> delete() File "./workbench", line 656, in delete media_id = media['mid'][0]['value'] TypeError: string indices must be integers
Also, I'll try to get the integration test done by this weekend, Thanks.

@mjordan
Copy link
Owner Author

mjordan commented Mar 8, 2021

Don't know... I haven't see that error before. Can you confirm that the nodes you are deleting have media attached? If so, I'll try to replicate the error. Also, what content type are your nodes?

No sweat on the tests, thanks for checking in.

@Ansel-Hong
Copy link

The nodes Im deleting dont have media attached, they are of the "Article" type. Should I use another type instead?

@mjordan
Copy link
Owner Author

mjordan commented Mar 8, 2021

Type shouldn't matter, but I'll take a look.

@mjordan
Copy link
Owner Author

mjordan commented Mar 9, 2021

@Ansel-Hong I added a check for media that should avoid this problem. Can you pull down the latest changes to the main branch and test deleting again?

@Ansel-Hong
Copy link

Yup it works now thank you, I realised however the url alias is not deleted (under configuration>url alias) but I'm guessing thats the point of the integration test to check for issues like that.

@Ansel-Hong
Copy link

@mjordan I'm trying to push my local repo for issue-154 but im getting a error saying Can't connect to any URI: [email protected]:mjordan/islandora_workbench.git ([email protected]:mjordan/islandora_workbench.git: No more authentication methods available) do you know what the problem might be?

@mjordan
Copy link
Owner Author

mjordan commented Mar 12, 2021

Looks like you are trying to push to my Github account. Also, I don't see a fork of Islandora Workbench at https://github.com/Ansel-Hong. I'm really only familiar with the workflow of forking a repo into your own Github account, pushing your changes to your fork, and then opening a pull request, which I would then merge into mine. Is what you are trying to do?

@Ansel-Hong
Copy link

Ah okay my bad, I dont know why it was in pushing with ssh. I managed to push it now.

@mjordan
Copy link
Owner Author

mjordan commented Mar 14, 2021

@Ansel-Hong feel free to open a pull request when you're ready.

@Ansel-Hong
Copy link

Okay I will do that still need to write code to remove the url alias during tearDown because right now it removes the nodes without deleting the corresponding url alias

@Ansel-Hong
Copy link

Should the test code only create a node with a url alias and update it without deleting? If so I can just send a pull request then.

@mjordan
Copy link
Owner Author

mjordan commented Mar 15, 2021

In general, the tests should delete everything they create. The one exception is taxonomy terms.

If you want to open the pull request without deleting the aliases, go ahead. We can add code to delete those later.

@Ansel-Hong
Copy link

Okay Ill just make a pull request first so you can check if everything works on your end. Thanks, and sorry again for taking so long.

@Ansel-Hong
Copy link

#246 (comment)

@Ansel-Hong
Copy link

For deleting the url alias shound I hook the url alias to the node or how do I delete it?

@Ansel-Hong
Copy link

@mjordan Sorry, forgot to @ you about the question, Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing User, unit, and integration testing
Projects
None yet
Development

No branches or pull requests

2 participants