# Stress testing framework
Repo is managed by Terraform.

**Requierements**: Docker, Python3

**Structure**:
```
├── Makefile (includes run commands (local run with dashboard and run without GUI))
├── constants (Basic files with onstants shared among the projects)
│   ├── apple_album.py
│   ├── ....py
│   └── vendor.py
├── locustfile.py (entry point, code in file binds virtual users and task sets)
├── requirements.txt
└── tasksets
    ├── auth.py (Auth0 authentification helper, get a token for virtual users)
    ├── base.py (includes base taskset class and tag functionality)
    ├── helper.py (module with helpful functions, it helps shrink test development)
    └── vendor_api (testset example)
        ├── config.py (taskset configs)
        ├── constants.py (local taskset constants)
        └── tasksets
            ├── generated_taskset.py (fully implemented test set class, which gather all related tasks together and implement extra logic, like direct authentification)
            └── generated_tests
                ├── apple
                │   ├── albums.py
                │   ├── ....py
                │   └── tracks.py
                ├── spotify
                │   ├── albums.py
                │   ├── ....py
                │   └── users.py
                └── vendors
                    └── search_by_isrc.py
```

The locustio lib version is 0.12.2 and can not be upgraded because of Taurus report generation limitation (CI/CD integration).

**Official documentaion**: https://docs.locust.io/en/0.12.2/

Tests can be performed through API gateway with Auth0 token and directly as well. By default, it's API gateway way. Direct authentification supports the Authorization header which should be implemented in the generated test set file. Take a look at an example.

**Tags**

The framework supports tags. The test will be executed especially for chosen tags. Example: TAGS=APOLLO,VENDOR. The tagged tests might belong to different test suits.

**Test exmaple**
```
class Episodes(TaskSet):
    @tag(Tag.VENDOR)   # TAG, send more tags if needed
    def episodes_test_single(self):
        self.get(      # http method
            name=self.url("spotify/v1/episodes/EPISODE_ID"),  # API call name in the test report. Use the "name" argument if URI is dynamic, for instance, if object ID is part of URI, not URL argument. If the URL is static, the default name will be the URL below. 
            url=self.url(  # URL build function with arguments, the API prefix is added automatically on the fly from env variables  
                "spotify/v1/episodes/{episode_id}",
                episode_id=Helper.get_random_value(SPOTIFY_EPISODE_ID, config.EXT_API_SINGLE_ID_OPTIONS_LIMIT)
            ),
            params=Helper.get_params(  # URL arguments
                {"market": Helper.get_optional(Helper.get_spotify_market(config.EXT_API_PARAM_OPTIONS_LIMIT))}  # Use helpers to get unique tests
            ),
        )
```

Base tests were generated by _https://pypi.org/project/swagger2locustio/_ based on OpenApi specification.

**Local run**

Take a look at Makefile. There are a few helpful examples. Choose the configuration and run it in the terminal:
```
>make name_of_configuration
```