Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
api-client-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
funkwhale
api-client-python
Commits
45f416d7
Verified
Commit
45f416d7
authored
2 years ago
by
Georg Krause
Browse files
Options
Downloads
Patches
Plain Diff
Add a basic guide how to write tests
parent
ab50a69b
No related branches found
No related tags found
No related merge requests found
Pipeline
#23629
failed
2 years ago
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.md
+13
-0
13 additions, 0 deletions
README.md
with
13 additions
and
0 deletions
README.md
+
13
−
0
View file @
45f416d7
...
@@ -92,3 +92,16 @@ If you want to install this client into another project without publishing it (e
...
@@ -92,3 +92,16 @@ If you want to install this client into another project without publishing it (e
### Run tests
### Run tests
To run the tests, run
`poetry run pytest`
.
To run the tests, run
`poetry run pytest`
.
### How to write test cases
There are two things to test: The models and the API functions.
Lets imagine you want to write a test case for the endpoint
`/api/v1/albums`
focusing on the models for now. Since this endpoint lists the Albums, the
correct API call is in
`api/albums/albums_list.py`
. Check the function called
`_parse_response()`
. The model used to parse the response is called
`PaginatedAlbumList`
, which we will run tests against. Now curl the endpoint you
want to write tests for and put the response into
`tests/data/albums.json`
. Now
we can load this json file, load it with the model and do some assertions. The
example is available in
`tests/unit/test_model_paginated_album_list.py`
.
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment