diff --git a/.gitignore b/.gitignore index c899ee71..d9ec20f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .direnv +***/.hypothesis .coverage.* **/qubeclan **/testdir diff --git a/docs/testing.md b/docs/testing.md index cfba2139..5dcd7f5a 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -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) - [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 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. + + ### Frameworks for Contract-Driven Testing 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) - [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. \ No newline at end of file +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** \ No newline at end of file diff --git a/flake.lock b/flake.lock index 06a001f2..5000742f 100644 --- a/flake.lock +++ b/flake.lock @@ -62,11 +62,11 @@ }, "luispkgs": { "locked": { - "lastModified": 1699286483, - "narHash": "sha256-gzY56MbP3UTztI7Ra69RCNq81fKlsQu79LZ2gGss3Eg=", + "lastModified": 1699386673, + "narHash": "sha256-T9ZrVSf0ymSBHFpRw7K+DSNzY0sCkwkDe0VIzE033Ac=", "owner": "Luis-Hebendanz", "repo": "nixpkgs", - "rev": "b59438a5a3b4d50e117081d41ed6f8833f65934d", + "rev": "e918074d416f0918ac6c3895c6a5db2ae5ce3c1e", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index a222e4f7..cebc496b 100644 --- a/flake.nix +++ b/flake.nix @@ -9,6 +9,7 @@ #nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small"; # https://github.com/NixOS/nixpkgs/pull/265872 luispkgs.url = "github:Luis-Hebendanz/nixpkgs/fix_python_deal"; + floco.url = "github:aakropotkin/floco"; floco.inputs.nixpkgs.follows = "nixpkgs"; disko.url = "github:nix-community/disko"; @@ -32,6 +33,7 @@ "aarch64-darwin" ]; imports = [ + ./checks/flake-module.nix ./devShell.nix ./formatter.nix diff --git a/pkgs/clan-cli/default.nix b/pkgs/clan-cli/default.nix index 9cf55b12..4dc13659 100644 --- a/pkgs/clan-cli/default.nix +++ b/pkgs/clan-cli/default.nix @@ -34,8 +34,8 @@ , gnupg , e2fsprogs , mypy -, cntr , deal +, schemathesis }: let @@ -58,6 +58,7 @@ let gnupg stdenv.cc deal + schemathesis ]; # Optional dependencies for clan cli, we re-expose them here to make sure they all build. diff --git a/pkgs/clan-cli/flake-module.nix b/pkgs/clan-cli/flake-module.nix index afba1380..7a230dab 100644 --- a/pkgs/clan-cli/flake-module.nix +++ b/pkgs/clan-cli/flake-module.nix @@ -1,20 +1,25 @@ { inputs, ... }: { - perSystem = { self', pkgs, system, ... }: { - devShells.clan-cli = pkgs.callPackage ./shell.nix { - inherit (self'.packages) clan-cli ui-assets nix-unit; - }; - packages = { - clan-cli = pkgs.python3.pkgs.callPackage ./default.nix { - inherit (self'.packages) ui-assets; - inherit (inputs) nixpkgs; - deal = inputs.luispkgs.legacyPackages.${system}.python3Packages.deal; + perSystem = { self', pkgs, system, ... }: + let + luisPythonPkgs = inputs.luispkgs.legacyPackages.${system}.python3Packages; + in + { + devShells.clan-cli = pkgs.callPackage ./shell.nix { + inherit (self'.packages) clan-cli ui-assets nix-unit; + }; + 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; + }; }