Skip to main content

Fluid Attacks Core Library

Project description

Fluid Attacks Core Library

logo

Disclaimer

This library was developed for Fluid Attacks projects. That specific context is reflected in some presets and configurations.

Importing types

from fluidattacks_core.{module}.types import (
    ...
)

where {module} is one of the following:

  • authz

Publishing a new version

  1. Make any changes you want to the library.
  2. Run the Python linter:
    m . /lintPython/dirOfModules/commonUtilsPypiFluidattackscore
    
  3. Upgrade the library version in pyproject.toml.

    Make sure to do this as it is required for your changes to be published.

  4. Push your changes using the common\ pipeline.
  5. Once you reach production, the new version of the library should become available.

Core: Testing

Motivation

Standardize test fundamentals for current and new projects in any organization could be a hard task. Also, thanks to pytest malleability, we find different solutions solving the same problems and a harder test maintainability.

Using pytest, we find that developers tend to use a lot of features (fixtures, patches, marks, etc.) without any standard but pytest is still a very simple and powerful tool.

For this reason, we decided to create a pytest wrapper that includes some presets and defines testing standards for us.

Description

This library aims to provide a simple way to write unit and integration tests for Python products using boto3 services and other common packages.

Philosophy of this package is to be simple and include the most common testing features in a standard way.

Table of Contents

  1. Usage
  2. Tagging
  3. Fakers
  4. Mocking

Usage

fluidattacks_test --help

: '
usage: fluidattacks-test [-h] [--target [TARGET]] [--src [SRC]] [--scope SCOPE]

🏹 Python package for unit and integration testing through Fluid Attacks projects 🏹

options:
  -h, --help         show this help message and exit
  --target [TARGET]  Folder to start the tests. Default is current folder.
  --src [SRC]        Folder with the source code for coverage report. Default is src.
  --scope SCOPE      Type and module to test.

target is the main folder where test and coverage folders will be resolved.

src is the folder where the source code is located and by default it is {target}/src.

scope, the only required argument, is the test folder to run from {target}/test/unit/src.

An example of usage is:

fluidattacks_test --scope billing

Tagging

You can use tags same as marks in pytest:

from fluidattacks_test import tag

@tag.billing
def test_billing():
    ...

@tag.auth
def test_auth():
    ...

Recommendations:

  • Tag every test in one file with the same tag: the folder name.
  • Don't use special pytest tags like slow, skip, only, xfail, etc. If you need any special tag for any reason, please contribute to this package extension.

Fakers

Some fakers are available to generate stub data for tests:

  • fake_vulnerability().
  • fake_finding().
  • fake_group().

Mocking

Some utilities are available via dependency injection to test methods. Mocking is one of them and it allows you to change the behavior and returns of any method or class in your code.

Functions

You can mock functions using mocking:

from fluidattacks_test import tag
from fluidattacks_test.types import MockingFunction

import requests

@tag.billing
def test_billing(mocking: MockingFunction) -> None:
    mock_post = mocking(requests, "post", { "status_code": 200 })

    ...

    call_list = mock_post.calls()
    assert len(call_list) == 1

It changes the behavior of the post method from the requests module to return always { "status_code": 200 }. The mock_post object stores every call running the tests to the method for assertion purposes.

Check the .calls() method for more information.


More instructions coming soon...

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fluidattacks_core-1.0.2.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fluidattacks_core-1.0.2-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file fluidattacks_core-1.0.2.tar.gz.

File metadata

  • Download URL: fluidattacks_core-1.0.2.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Darwin/23.5.0

File hashes

Hashes for fluidattacks_core-1.0.2.tar.gz
Algorithm Hash digest
SHA256 621f1bf165cc248d1109605f6d0fb3a6e96187fa151e094589b22a186d66a395
MD5 91956ca8a31e9fc1344f97a8530bb7ce
BLAKE2b-256 57761d411bb120d38d3abf34f43afc35bde1d1d9ac7e07804f22cc30d76e31f9

See more details on using hashes here.

File details

Details for the file fluidattacks_core-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: fluidattacks_core-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Darwin/23.5.0

File hashes

Hashes for fluidattacks_core-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6c7eb03971adc728dd621cc4f7afa5ba97f936652173450fe43d647e929e53a5
MD5 6572576c93525332ec966c19c0ccacc8
BLAKE2b-256 ede8c8e1818619587a099f3fe6664a3b48bf42f68307604880e4dfd94cbfd1b7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page