diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..026432e --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,26 @@ +version: 2.1 +orbs: + gcp-gcr: circleci/gcp-gcr@0.6.1 + cloudrun: circleci/gcp-cloud-run@1.0.0 +jobs: + build_test: + docker: + - image: circleci/python:3.7.4 + steps: + - checkout + - run: + name: Install Python Dependencies + command: | + echo 'export PATH=~$PATH:~/.local/bin' >> $BASH_ENV && source $BASH_ENV + pip install --user -r requirements.txt + - run: + name: Run Tests + command: | + pytest +workflows: + build_test_deploy: + jobs: + - build_test + + + #Tests diff --git a/requirements.txt b/requirements.txt index 5a4a2b9..d037089 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ flask -python-dotenv \ No newline at end of file +python-dotenv +pytest diff --git a/test_app.py b/test_app.py new file mode 100644 index 0000000..a667424 --- /dev/null +++ b/test_app.py @@ -0,0 +1,63 @@ +import pytest +from flask import Flask +from app_service import AppService + +@pytest.fixture +def app(): + app = Flask(__name__) + app.config['TESTING'] = True + return app + +@pytest.fixture +def client(app): + return app.test_client() + +def test_home_route(client): + response = client.get('/') + assert response.status_code == 200 + assert b"App Works!!!" in response.data + +def test_get_tasks(client): + appService = AppService() + expected_response = appService.get_tasks() + + response = client.get('/api/tasks') + assert response.status_code == 200 + assert response.get_json() == expected_response + +def test_create_task(client): + appService = AppService() + new_task = { + 'id': 4, + 'name': 'task4', + 'description': 'This is task 4' + } + expected_response = appService.create_task(new_task) + + response = client.post('/api/task', json=new_task) + assert response.status_code == 200 + assert response.get_json() == expected_response + +# Similarly, write tests for update_task and delete_task routes + +def test_update_task(client): + appService = AppService() + updated_task = { + 'id': 1, + 'name': 'task1_updated', + 'description': 'This is the updated task 1' + } + expected_response = appService.update_task(updated_task) + + response = client.put('/api/task', json=updated_task) + assert response.status_code == 200 + assert response.get_json() == expected_response + +def test_delete_task(client): + appService = AppService() + task_id_to_delete = 1 + expected_response = appService.delete_task(task_id_to_delete) + + response = client.delete(f'/api/task/{task_id_to_delete}') + assert response.status_code == 200 + assert response.get_json() == expected_response