Verify an nbsinfra API implementation
Project description
NbSAPI Verification Tool
nbsapi_verify is a standalone tool designed to verify that your API implementation conforms to the https://nbsapi.org OpenAPI specification, currently at version 2.0.0
Installation and Usage
Installation (temporary)
Using pipx
pipx nbsapi_verify --help
Using uvx
uvx nbsapi_verify --help
Installation (permanent, on $PATH)
If you would prefer the tool to be installed on your PATH you can run:
pipx install nbsapi_verify or uv tool install nbsapi_verify. You can then run nbsapi_verify without prefixes.
Installation as a package
You can also install the package using your preferred Python package manager:
Using pip
pip install nbsapi_verify
Using uv
uv add nbsapi_verify
Using poetry
poetry add nbsapi_verify
After installation, you can run the tool using the installed script:
nbsapi_verify --help
Usage
nbsapi_verify requires a small amount of configuration:
- First, generate a verification config. This requires you to specify:
- the host the API is running on
- a valid username
- the password for that username
- the ID of that user
- a path for the verification config to be stored (optional: it defaults to the current working directory)
- the test type to be run:
all,auth,user: theauthtests will exercise the write API functions, while theusertests will exercise the read API functions (defaults toall).
In order to test your API while locally developing, that command might look like:
nbsapi_verify --generate \
--host http://localhost:8000 \
--test-type all \
--username testuser \
--password testpass \
--project 1 \
--solution 1\
--impact 1 \
--measure 1 \
--config-dir ~
If the command completes sucessfully, you can run the verification tool:
nbsapi_verify --config-dir ~
You can also generate JSON and HTML reports of the test results:
# Generate default JSON report (nbsapi_verify_report.json)
nbsapi_verify --config-dir ~ --json-output
# Generate default HTML report (nbsapi_verify_report.html)
nbsapi_verify --config-dir ~ --html-output
# Generate both reports
nbsapi_verify --config-dir ~ --json-output --html-output
When all tests pass, your API implementation is conformant to the NbsAPI specification!
Conformance Test Data Requirements
This document describes the test data requirements for running API conformance tests against the NBS API.
Overview
The conformance tests validate that the API implementation matches the OpenAPI specification. However, since these tests may run against production databases where data creation/deletion is not appropriate, they rely on existing test data.
Required Test Data
For all conformance tests to pass, the following data must exist in the database:
Projects
- Project ID:
1- Must exist for project-related endpoint tests- Required for: GET, PATCH, DELETE
/v2/api/projects/1 - Required for: GET
/v2/api/projects/1/export - Required for: GET
/v2/api/projects/1/export/deltares - Required for: POST/DELETE
/v2/api/projects/1/solutions/1
- Required for: GET, PATCH, DELETE
Solutions (Nature-Based Solutions)
- Solution ID:
1- Must exist for solution-related tests- Required for: GET, PATCH
/v2/api/solutions/solutions/1 - Required for: GET
/v2/api/solutions/solutions/1/geojson - Required for: project-solution relationship tests
- Required for: GET, PATCH
Impacts
- Impact ID:
1- Must exist for impact tests- Required for: GET
/v2/api/impacts/impacts/1 - Required for: GET
/v2/api/impacts/solutions/1/impacts
- Required for: GET
Measure Types
- Measure ID:
1- Must exist for measure type tests- Required for: GET, PATCH
/v2/measure_types/1 - Note: DELETE tests are intentionally excluded from conformance tests
- Required for: GET, PATCH
Users
- Username:
testuserwith Password:testpass- Required for authenticated endpoints- Used for obtaining JWT tokens for protected endpoints
Configuration
The test runner accepts these IDs as configuration options:
# Generate configuration with test data IDs
nbsapi-verify --generate \
--host http://localhost:8000 \
--username testuser \
--password testpass \
--project 1 \
--solution 1 \
--impact 1 \
--measure 1
Important: The conformance tests use the project_id query parameter to create projects with predictable IDs for subsequent tests to reference. No special server configuration is required.
Database Setup
Development/Testing Environment
For development environments, you can create the required test data:
-- Create test user (adjust based on your auth system)
INSERT INTO users (username, password_hash) VALUES ('testuser', '<hashed_password>');
-- Create test measure type
INSERT INTO measure_types (id, name, description) VALUES ('1', 'Test Measure', 'Test measure type');
-- Create test solution
INSERT INTO naturebasedsolution (id, name, definition, measure_id) VALUES
(1, 'Test Solution', 'Test nature-based solution', '1');
-- Create test project
INSERT INTO projects (id, title, description) VALUES
('1', 'Test Project', 'Test project for conformance tests');
-- Create test impact
INSERT INTO impacts (id, magnitude, solution_id) VALUES
(1, 100.0, 1);
Production Environment
For production environments:
- Identify existing data that can serve as test subjects
- Update the configuration to use those IDs
- Ensure the test user has appropriate permissions but limited scope
Excluded Tests
The following types of tests are intentionally excluded from conformance testing:
DELETE Operations
DELETE endpoints are skipped because:
- They permanently destroy data
- Running against production databases would be destructive
- They create dependencies between test execution order
Excluded DELETE endpoints:
DELETE /v2/measure_types/{measure_id}DELETE /v2/api/projects/{project_id}DELETE /v2/api/projects/{project_id}/solutions/{solution_id}
Data Creation Tests
Tests that create new data may fail in production environments due to:
- Unique constraints (if test data already exists)
- Permission restrictions
- Database triggers or validation rules
Test Failure Analysis
404 Errors (Data Not Found)
If you see 404 errors like "Project not found", "Solution not found":
- Verify the required test data exists in the database
- Check that the IDs in your configuration match existing data
- Ensure the test user has read access to the data
409 Conflicts (Data Already Exists)
If you see 409 errors for creation endpoints:
- This is normal behavior when test data already exists
- The tests expect either 200 (success) or 409 (conflict) responses
- No action needed unless you're getting different error codes
Authentication Errors
If you see 401/403 errors:
- Verify the test user credentials are correct
- Check that the user has appropriate permissions
- Ensure the JWT token is being generated correctly
Best Practices
- Use Dedicated Test Data: Create specific test records rather than using production data
- Document Test IDs: Keep track of which IDs are reserved for testing
- Isolate Test Data: Use specific naming conventions (e.g., "Test Project") to identify test records
- Regular Cleanup: In development environments, periodically clean up accumulated test data
- Monitor Production: When running against production, monitor for any unintended side effects
Troubleshooting
Common Issues
- "Project not found" errors: The most common issue is missing project ID 1
- Authentication failures: Usually incorrect test user credentials
- Measure type conflicts: Trying to create measure types with existing IDs
Debugging Steps
-
Check database for required test data:
SELECT id, title FROM projects WHERE id = '1'; SELECT id, name FROM naturebasedsolution WHERE id = 1; SELECT id FROM impacts WHERE id = 1; SELECT id, name FROM measure_types WHERE id = '1';
-
Verify test user can authenticate:
curl -X POST http://localhost:8000/auth/token \ -d "username=testuser&password=testpass"
-
Test individual endpoints manually:
curl -H "Authorization: Bearer <token>" \ http://localhost:8000/v2/api/projects/1
Updating Test Data Requirements
When adding new conformance tests, document any additional data requirements here. Consider:
- What IDs/entities the test requires
- Whether the test is destructive
- If it should be excluded from production testing
- What configuration options might be needed
Help
nbsapi_verify --help
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nbsapi_verify-0.2.0.tar.gz.
File metadata
- Download URL: nbsapi_verify-0.2.0.tar.gz
- Upload date:
- Size: 60.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
363bff2e8bb14d350d2fbbdd88a1f3c61c51c70db794e9772d6dab1b2587c474
|
|
| MD5 |
f17f1c43b2a96ada5ef01e15088f9323
|
|
| BLAKE2b-256 |
60fec6903ab8598953bcef10b4aaa47b63a79c33e9546313affbf507fd2239a6
|
Provenance
The following attestation bundles were made for nbsapi_verify-0.2.0.tar.gz:
Publisher:
ci.yml on nbsapi/nbsapi_verification
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nbsapi_verify-0.2.0.tar.gz -
Subject digest:
363bff2e8bb14d350d2fbbdd88a1f3c61c51c70db794e9772d6dab1b2587c474 - Sigstore transparency entry: 249680935
- Sigstore integration time:
-
Permalink:
nbsapi/nbsapi_verification@92230c914a118fdd1b1ef30297857821f97a9471 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/nbsapi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@92230c914a118fdd1b1ef30297857821f97a9471 -
Trigger Event:
push
-
Statement type:
File details
Details for the file nbsapi_verify-0.2.0-py3-none-any.whl.
File metadata
- Download URL: nbsapi_verify-0.2.0-py3-none-any.whl
- Upload date:
- Size: 27.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6698e022b5b9feeae86340eb59443bb55ad541097eb9bdf01fc0f4faa9940b5f
|
|
| MD5 |
4f03cbcf948ecd5443211179201a563c
|
|
| BLAKE2b-256 |
73e51282f614ade82507fe3f7e3c7b0b2312ca3186622d9438634b952b96665d
|
Provenance
The following attestation bundles were made for nbsapi_verify-0.2.0-py3-none-any.whl:
Publisher:
ci.yml on nbsapi/nbsapi_verification
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nbsapi_verify-0.2.0-py3-none-any.whl -
Subject digest:
6698e022b5b9feeae86340eb59443bb55ad541097eb9bdf01fc0f4faa9940b5f - Sigstore transparency entry: 249680948
- Sigstore integration time:
-
Permalink:
nbsapi/nbsapi_verification@92230c914a118fdd1b1ef30297857821f97a9471 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/nbsapi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@92230c914a118fdd1b1ef30297857821f97a9471 -
Trigger Event:
push
-
Statement type: