Skip to content

Commit

Permalink
fix: transaction open generates 500 server error (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
cka-y authored Feb 14, 2024
1 parent f995c40 commit 91d39bf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 2 additions & 0 deletions api/src/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ def select(
return results
except Exception as e:
logging.error(f"SELECT query failed with exception: \n{e}")
if global_session is not None:
global_session.rollback()
return None
finally:
if update_session:
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ Ensure your test class is discoverable by adding it to the appropriate module wi
Use the bash script with necessary arguments to specify the API URL, a refresh token for authentication, and the data file path. An optional argument allows filtering which test classes to execute.

```bash
./integration-tests.sh -u <API URL> -t <REFRESH TOKEN> -f <FILE PATH> [-c <CLASS NAMES>]
export REFRESH_TOKEN="your_refresh_token"
./integration-tests.sh -u <API URL> -f <FILE PATH> [-c <CLASS NAMES>]
```

#### Options
- `-u` URL of the API to test against
- `-t` Refresh token for API authentication
- `-f` File path for the data file to be used in tests
- `-c` Optional, comma-separated list of test class names to include for targeted testing

### Example
```bash
./integration-tests.sh -u "http://0.0.0.0:8080" -t "your_refresh_token" -f "/path/to/your/data_file.csv" -c "ClassName1,ClassName2"
./integration-tests.sh -u "http://0.0.0.0:8080" -f "/path/to/your/data_file.csv" -c "ClassName1,ClassName2"
```

This command runs the integration tests against the specified API URL and data file, filtering the tests to only include those from `ClassName1` and `ClassName2`.
Expand Down
26 changes: 26 additions & 0 deletions integration-tests/src/endpoints/gtfs_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,29 @@ def test_order_by_external_id_descending(self):
f"but found '{prev_external_id}' followed by '{current_external_id}'."
)
prev_external_id = current_external_id

def test_invalid_bb_input_followed_by_valid_request(self):
"""Tests the API's resilience by first sending invalid input parameters and then a valid request to ensure the
error does not affect subsequent requests."""

# Sending a request with invalid bounding box parameters
wrong_bounding_lon_lat = "-12,-"
response = self.get_response(
"v1/gtfs_feeds",
params={
"dataset_longitudes": wrong_bounding_lon_lat,
"dataset_latitudes": wrong_bounding_lon_lat,
"bounding_filter_method": "completely_enclosed",
},
)

# Expecting an error due to invalid input, but specific status code check is pending implementation
assert (
response.status_code != 200
), f"Expected an error status code for GTFS feeds request with invalid input, got {response.status_code}."

# Sending a subsequent valid request to ensure APIs proper handling of sequences
response = self.get_response("v1/gtfs_feeds", params={"limit": 10})
assert (
response.status_code == 200
), f"Expected a 200 status code for subsequent valid GTFS feeds request, got {response.status_code}."
2 changes: 1 addition & 1 deletion scripts/integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# -c Optional, comma-separated list of test class names to include

function print_help() {
echo "Usage: $0 -u <API URL> -t <REFRESH TOKEN> -f <FILE PATH> [-c <CLASS NAMES>]"
echo "Usage: $0 -u <API URL> -f <FILE PATH> [-c <CLASS NAMES>]"
echo ""
echo "Options:"
echo " -u URL of the API to test against"
Expand Down

0 comments on commit 91d39bf

Please sign in to comment.