From 4545e7ffa6017590d108b30a72e1dd220e104255 Mon Sep 17 00:00:00 2001 From: albertkun Date: Thu, 9 Nov 2023 22:01:25 -0800 Subject: [PATCH] feat: update AWS deployment and unit tests docs: readme.md for unit tests --- .github/workflows/dev-aws.yml | 7 ++-- fastapi/tests/readme.md | 33 ++++++++++++------- fastapi/tests/run_tests.py | 2 +- .../tests/{test_main.py => test_endpoints.py} | 0 4 files changed, 25 insertions(+), 17 deletions(-) rename fastapi/tests/{test_main.py => test_endpoints.py} (100%) diff --git a/.github/workflows/dev-aws.yml b/.github/workflows/dev-aws.yml index bb085fab..a2545ebe 100644 --- a/.github/workflows/dev-aws.yml +++ b/.github/workflows/dev-aws.yml @@ -79,10 +79,9 @@ jobs: - name: Push Updated Docker Image on Lightsail Dev if: steps.changed-files.outputs.any_changed == 'true' run: | - aws lightsail create-container-service-deployment \ - --service-name dev-metro-api-v2 \ + aws lightsail create-container-service-deployment + --service-name dev-metro-api-v2 --containers '{"memcached": {"image": "memcached:latest", "environment": {}, "ports": {"11211": "TCP"}}, "data-loading-service": {"image":"lacmta/metro-api-v2:data-loading-service", "environment": {"FTP_SERVER": "${{secrets.FTP_SERVER}}", "FTP_USERNAME": "${{secrets.FTP_USERNAME}}", "FTP_PASS": "${{secrets.FTP_PASS}}", "SWIFTLY_AUTH_KEY_BUS": "${{secrets.SWIFTLY_AUTH_KEY_BUS}}", "SWIFTLY_AUTH_KEY_RAIL": "${{secrets.SWIFTLY_AUTH_KEY_RAIL}}", "AWS_ACCESS_KEY_ID": "${{secrets.AWS_ACCESS_KEY_ID}}", "ACCESS_SECRET_KEY": "${{secrets.ACCESS_SECRET_KEY}}", "SWIFTLY_AUTH_KEY": "${{secrets.SWIFTLY_AUTH_KEY}}", "API_DB_URI": "${{secrets.API_DB_URI}}", "HASH_KEY": "${{secrets.HASH_KEY}}", "HASHING_ALGORITHM": "${{secrets.HASHING_ALGORITHM}}", "LOGZIO_TOKEN": "${{secrets.LOGZIO_TOKEN}}", "LOGZIO_URL": "${{secrets.LOGZIO_URL}}", "RUNNING_ENV": "dev"}}, "fastapi": {"image":"lacmta/metro-api-v2:fastapi", "environment": {"FTP_SERVER": "${{secrets.FTP_SERVER}}", "FTP_USERNAME": "${{secrets.FTP_USERNAME}}", "FTP_PASS": "${{secrets.FTP_PASS}}", "SWIFTLY_AUTH_KEY_BUS": "${{secrets.SWIFTLY_AUTH_KEY_BUS}}", "SWIFTLY_AUTH_KEY_RAIL": "${{secrets.SWIFTLY_AUTH_KEY_RAIL}}", "AWS_ACCESS_KEY_ID": "${{secrets.AWS_ACCESS_KEY_ID}}", "ACCESS_SECRET_KEY": "${{secrets.ACCESS_SECRET_KEY}}", "SWIFTLY_AUTH_KEY": "${{secrets.SWIFTLY_AUTH_KEY}}", "API_DB_URI": "${{secrets.API_DB_URI}}", "HASH_KEY": "${{secrets.HASH_KEY}}", "HASHING_ALGORITHM": "${{secrets.HASHING_ALGORITHM}}", "LOGZIO_TOKEN": "${{secrets.LOGZIO_TOKEN}}", "LOGZIO_URL": "https://listener.logz.io:8071", "RUNNING_ENV": "dev", "MEMCACHED_HOST": "dev-metro-api-v2.service.local","MEMCACHED_PORT":"11211"}, "ports": {"80": "HTTP"}}}' --public-endpoint '{"containerName": "fastapi","containerPort": 80,"healthCheck":{ "healthyThreshold": 2,"unhealthyThreshold": 2,"timeoutSeconds": 2,"intervalSeconds": 5,"path": "/","successCodes": "200-499"}}' - deploy-documentation: runs-on: ubuntu-latest name: Deploy Documentation to GitHub Pages @@ -108,7 +107,7 @@ jobs: run: yarn build - name: Deploy Documentation to GitHub Pages if: steps.changed-documentation.outputs.any_changed == 'true' - uses: peaceiris/actions-gh-pages@v4 + uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.METRO_GITHUB_TOKEN }} publish_dir: ./documentation/build diff --git a/fastapi/tests/readme.md b/fastapi/tests/readme.md index 55787090..fe052d8c 100644 --- a/fastapi/tests/readme.md +++ b/fastapi/tests/readme.md @@ -1,4 +1,4 @@ -# Project Name +# Metro FastAPI Unit Tests ## Setup @@ -8,9 +8,9 @@ Install the required Python packages: pip install -r requirements.txt ``` -## Running Tests +## Running all tests -This project uses `pytest` for unit testing. To run the tests, use the following command: +This project uses `pytest` for unit testing. To run all the tests, use the following command: ```bash pytest tests/test_main.py @@ -18,8 +18,24 @@ pytest tests/test_main.py This command will run all test cases in the test_main.py file. -### Load Testing -This project uses `locust` for load testing. +### Logs + +The tests will generate a log with naming in the following format: + +`test_log_YEARMONTHDAY_TIME.txt` + +That has details on the number of tests failed. + +## Endpoint Testing +We use `pytest` to test the endpoints and it can be run using + +`python test_endpoints.py` + + +## Load Testing +We use `locust` for load testing. + +> Note: Ideally, you should run on a different machine that has access to the server running our fastapi application. To run the load tests, use the following command: ```bash @@ -29,10 +45,3 @@ locust -f test_load.py -u 2000 -r 100 This command will start a swarm of 2000 users, with a hatch rate of 100 users per second, using the Locust file in your tests directory. -### Contributing -Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us. - -### License -This project is licensed under the MIT License - see the LICENSE.md file for details - -``` \ No newline at end of file diff --git a/fastapi/tests/run_tests.py b/fastapi/tests/run_tests.py index e98af52f..274dc7a1 100644 --- a/fastapi/tests/run_tests.py +++ b/fastapi/tests/run_tests.py @@ -6,7 +6,7 @@ def run_tests(): log_file_name = f'test_log_{timestamp}.txt' with open(log_file_name, 'w') as f: print("Running unit tests...", file=f) - result = subprocess.run(["pytest", "-v", "test_main.py"], stdout=f, text=True) + result = subprocess.run(["pytest", "-v", "test_endpoints.py"], stdout=f, text=True) if result.returncode == 0: print("Unit tests check has passed", file=f) else: diff --git a/fastapi/tests/test_main.py b/fastapi/tests/test_endpoints.py similarity index 100% rename from fastapi/tests/test_main.py rename to fastapi/tests/test_endpoints.py