Added schemathesis dependency

This commit is contained in:
Luis Hebendanz 2023-11-07 20:53:29 +01:00
parent 798fbe3839
commit 32aa287da5
6 changed files with 37 additions and 19 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
.direnv .direnv
***/.hypothesis
.coverage.* .coverage.*
**/qubeclan **/qubeclan
**/testdir **/testdir

View File

@ -22,6 +22,11 @@ To implement property-based testing in FastAPI, you can use the following framew
- [Schemathesis](https://schemathesis.readthedocs.io/en/stable/#id2) - [Schemathesis](https://schemathesis.readthedocs.io/en/stable/#id2)
- [Hypothesis: Property-Based Testing](https://hypothesis.readthedocs.io/en/latest/quickstart.html) - [Hypothesis: Property-Based Testing](https://hypothesis.readthedocs.io/en/latest/quickstart.html)
### Nix code
https://github.com/kadena-io/signing-api/blob/master/schema-tests.nix
https://github.com/garbas/cicero/blob/67acaaa6f568d6f5032419bdcf0f4c97fb46e5ec/pkgs/schemathesis.nix#L5
### Why Schemas Are Not Contracts ### Why Schemas Are Not Contracts
A schema is a description of the data structure of your API, whereas a contract defines not only the structure but also the expected behavior and constraints. The following resource explains why schemas are not contracts in more detail: A schema is a description of the data structure of your API, whereas a contract defines not only the structure but also the expected behavior and constraints. The following resource explains why schemas are not contracts in more detail:
@ -38,6 +43,8 @@ Contract-driven testing combines the benefits of type annotations and property-b
- Contracts, like property-based tests, allow you to specify conditions and constraints, with the testing framework automatically generating test cases and verifying call results. - Contracts, like property-based tests, allow you to specify conditions and constraints, with the testing framework automatically generating test cases and verifying call results.
### Frameworks for Contract-Driven Testing ### Frameworks for Contract-Driven Testing
To implement contract-driven testing in FastAPI, consider the following framework and extension: To implement contract-driven testing in FastAPI, consider the following framework and extension:
@ -45,4 +52,6 @@ To implement contract-driven testing in FastAPI, consider the following framewor
- [iContract: Contract-Driven Development](https://icontract.readthedocs.io/en/latest/introduction.html) - [iContract: Contract-Driven Development](https://icontract.readthedocs.io/en/latest/introduction.html)
- [FastAPI-iContract: Extension for FastAPI](https://github.com/mristin/fastapi-icontract) - [FastAPI-iContract: Extension for FastAPI](https://github.com/mristin/fastapi-icontract)
By adopting contract-driven testing, you can ensure that your FastAPI application not only has a well-defined structure but also behaves correctly, making it more robust and reliable. By adopting contract-driven testing, you can ensure that your FastAPI application not only has a well-defined structure but also behaves correctly, making it more robust and reliable.
**However: icontract uses a 3 year old version of deal and a 3 year old version of typeguard. And icontract-fastapi is not maintained anymore**

View File

@ -62,11 +62,11 @@
}, },
"luispkgs": { "luispkgs": {
"locked": { "locked": {
"lastModified": 1699286483, "lastModified": 1699386673,
"narHash": "sha256-gzY56MbP3UTztI7Ra69RCNq81fKlsQu79LZ2gGss3Eg=", "narHash": "sha256-T9ZrVSf0ymSBHFpRw7K+DSNzY0sCkwkDe0VIzE033Ac=",
"owner": "Luis-Hebendanz", "owner": "Luis-Hebendanz",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "b59438a5a3b4d50e117081d41ed6f8833f65934d", "rev": "e918074d416f0918ac6c3895c6a5db2ae5ce3c1e",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -9,6 +9,7 @@
#nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small"; #nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
# https://github.com/NixOS/nixpkgs/pull/265872 # https://github.com/NixOS/nixpkgs/pull/265872
luispkgs.url = "github:Luis-Hebendanz/nixpkgs/fix_python_deal"; luispkgs.url = "github:Luis-Hebendanz/nixpkgs/fix_python_deal";
floco.url = "github:aakropotkin/floco"; floco.url = "github:aakropotkin/floco";
floco.inputs.nixpkgs.follows = "nixpkgs"; floco.inputs.nixpkgs.follows = "nixpkgs";
disko.url = "github:nix-community/disko"; disko.url = "github:nix-community/disko";
@ -32,6 +33,7 @@
"aarch64-darwin" "aarch64-darwin"
]; ];
imports = [ imports = [
./checks/flake-module.nix ./checks/flake-module.nix
./devShell.nix ./devShell.nix
./formatter.nix ./formatter.nix

View File

@ -34,8 +34,8 @@
, gnupg , gnupg
, e2fsprogs , e2fsprogs
, mypy , mypy
, cntr
, deal , deal
, schemathesis
}: }:
let let
@ -58,6 +58,7 @@ let
gnupg gnupg
stdenv.cc stdenv.cc
deal deal
schemathesis
]; ];
# Optional dependencies for clan cli, we re-expose them here to make sure they all build. # Optional dependencies for clan cli, we re-expose them here to make sure they all build.

View File

@ -1,20 +1,25 @@
{ inputs, ... }: { inputs, ... }:
{ {
perSystem = { self', pkgs, system, ... }: { perSystem = { self', pkgs, system, ... }:
devShells.clan-cli = pkgs.callPackage ./shell.nix { let
inherit (self'.packages) clan-cli ui-assets nix-unit; luisPythonPkgs = inputs.luispkgs.legacyPackages.${system}.python3Packages;
}; in
packages = { {
clan-cli = pkgs.python3.pkgs.callPackage ./default.nix { devShells.clan-cli = pkgs.callPackage ./shell.nix {
inherit (self'.packages) ui-assets; inherit (self'.packages) clan-cli ui-assets nix-unit;
inherit (inputs) nixpkgs; };
deal = inputs.luispkgs.legacyPackages.${system}.python3Packages.deal; packages = {
clan-cli = pkgs.python3.pkgs.callPackage ./default.nix {
inherit (self'.packages) ui-assets;
inherit (inputs) nixpkgs;
deal = luisPythonPkgs.deal;
schemathesis = luisPythonPkgs.schemathesis;
};
inherit (self'.packages.clan-cli) clan-openapi;
default = self'.packages.clan-cli;
}; };
inherit (self'.packages.clan-cli) clan-openapi;
default = self'.packages.clan-cli;
};
checks = self'.packages.clan-cli.tests; checks = self'.packages.clan-cli.tests;
}; };
} }