Skip to content

Commit

Permalink
[MNT] Implemented logic to make sure node URLs end with / (#25)
Browse files Browse the repository at this point in the history
* Implemented check that node urls end with `/`

* Updated test cases

* Updated README.md
  • Loading branch information
rmanaem authored Nov 16, 2023
1 parent b6a4b81 commit 9e32522
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Please refer to our [**official documentation**](https://neurobagel.org/overview
## Launching the API
### 1. Set the Neurobagel nodes to federate over
Create an `.env` file with the variable `NB_NODES` set to the URLs of the nodes to be federated over.
The URLs should be stored as a **space-separated, unquoted** string.
Each URL **must end with a `/`**.
The URLs should be stored as a **space-separated, unquoted** string.

e.g.,
```bash
Expand Down
9 changes: 7 additions & 2 deletions app/api/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@

def parse_nodes_as_list(nodes: str) -> list:
"""Returns user-defined Neurobagel nodes as a list.
Empty strings are filtered out, because they are falsy."""
return list(filter(None, nodes.split(" ")))
Empty strings are filtered out, because they are falsy.
Makes sure node URLs end with a slash."""
nodes_list = nodes.split(" ")
for i in range(len(nodes_list)):
if nodes_list[i] and not nodes_list[i].endswith("/"):
nodes_list[i] += "/"
return list(filter(None, nodes_list))


def send_get_request(url: str, params: list):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"set_nodes, expected_nodes",
[
(
"https://firstnode.neurobagel.org/query/",
"https://firstnode.neurobagel.org/query",
["https://firstnode.neurobagel.org/query/"],
),
(
"https://firstnode.neurobagel.org/query/ https://secondnode.neurobagel.org/query/",
"https://firstnode.neurobagel.org/query/ https://secondnode.neurobagel.org/query",
[
"https://firstnode.neurobagel.org/query/",
"https://secondnode.neurobagel.org/query/",
Expand Down

0 comments on commit 9e32522

Please sign in to comment.