Skip to content

test #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b72cf49
Create config.yml
CloudEngineer20 Sep 22, 2023
ee21f19
Update config.yml
CloudEngineer20 Sep 22, 2023
0b083d3
Update config.yml
CloudEngineer20 Sep 22, 2023
732ed14
Update config.yml
CloudEngineer20 Sep 22, 2023
3ebeba1
Create test
CloudEngineer20 Sep 22, 2023
a3ddff2
Rename config.yml to .circleci/config.yml
CloudEngineer20 Sep 22, 2023
6ee93b4
Update config.yml
CloudEngineer20 Sep 22, 2023
130a4c0
Update requirements.txt
CloudEngineer20 Sep 22, 2023
fa9ae47
Update and rename test to test_app,py
CloudEngineer20 Sep 22, 2023
0a13544
Create test_app,py
CloudEngineer20 Sep 22, 2023
3d4fd6b
Rename test_app,py to test_app.py
CloudEngineer20 Sep 22, 2023
776d735
Rename test_app,py to test_app.py
CloudEngineer20 Sep 22, 2023
9a77fd9
Delete .circleci/test_app.py
CloudEngineer20 Sep 22, 2023
8a1be2a
Update test_app.py
CloudEngineer20 Sep 22, 2023
816bb51
Update test_app.py
CloudEngineer20 Sep 22, 2023
af1b00b
Rename app.py to .circleci/app.py
CloudEngineer20 Sep 22, 2023
0860183
Rename app_service.py to .circleci/app_service.py
CloudEngineer20 Sep 22, 2023
a9e8633
Rename test_app.py to .circleci/test_app.py
CloudEngineer20 Sep 22, 2023
db283ad
Rename test_app.py to test_app.py
CloudEngineer20 Sep 22, 2023
f833039
Rename myapp/test_app.py to test_app.py
CloudEngineer20 Sep 22, 2023
c01f0dd
Rename .circleci/app_service.py to app_service.py
CloudEngineer20 Sep 22, 2023
2f94d13
Rename .circleci/app.py to app.py
CloudEngineer20 Sep 22, 2023
e3e3d45
Update config.yml
CloudEngineer20 Sep 23, 2023
cbcef71
Update config.yml
CloudEngineer20 Sep 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: 2.1
orbs:
gcp-gcr: circleci/[email protected]
cloudrun: circleci/[email protected]
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
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
flask
python-dotenv
python-dotenv
pytest
63 changes: 63 additions & 0 deletions test_app.py
Original file line number Diff line number Diff line change
@@ -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