Skip to content

Commit

Permalink
#28: Cleaning up a little to enable unit-testing API code. (#78)
Browse files Browse the repository at this point in the history
* Add an API test.

* Try to enable GitHub Actions.

* Try to remove the Werkzeug warning.

* Get a real quote.

* Rename package to src for now.

While pyproject.toml must contain the package name, using a name other
than "src" would require cascading changes to the submodules.

Let's leave that for a later stage, if required.

* Allow Python 3.10.

* Allow Python ^3.8.

Recent Flask requires ^3.8.

* Skip checking for requirements.txt (extra step).

* Remove requirements.txt.

* Add PyTest as a plain dependency.

* Specify Mark as the author.

* Refactor: Move server logic from main.py to src/server.py.

* Debug: Print current values.

* Remove a debug print.

* Remove CircleCI config.

Configured GitHub Actions instead.

If that isn't equivalent, we can revert.

* Untrack .envrc.

* Remove .envrc.

* Add PyLint exclusions for most common warnings.

These specific warnings were so numerous they obscured the code.

Before anyone gets to cleaning these warnings [1], let's disable them
for now just to make reading the code easier.

[1]: *If* they should ever be cleaned at all.

* Move test_api to tests/.

* Remove unneeded mock.
  • Loading branch information
kocielnik authored Jul 1, 2024
1 parent ef18b03 commit 016d944
Show file tree
Hide file tree
Showing 31 changed files with 869 additions and 91 deletions.
47 changes: 0 additions & 47 deletions .circleci/config.yml

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will install Python dependencies, and run tests with a single
# version of Python.
#
# For more information see:
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: IsThisStockGood

on:
push:
branches: [ "*" ]
pull_request:
branches: [ "*" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest==8.2.1
pip install -e .
- name: Test with pytest
run: |
pytest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ env/

# For Pycharm
.idea
.envrc
Empty file removed __init__.py
Empty file.
41 changes: 2 additions & 39 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,7 @@
import logging
from datetime import date
from flask import Flask, request, render_template
from src.DataFetcher import fetchDataForTickerSymbol

logger = logging.getLogger("IsThisStockGood")

handler = logging.StreamHandler()
handler.setLevel(logging.WARNING)

h_format = logging.Formatter('%(name)s - %(levelname)s : %(message)s')
handler.setFormatter(h_format)

logger.addHandler(handler)

app = Flask(__name__)


@app.route('/')
def homepage():
if request.environ['HTTP_HOST'].endswith('.appspot.com'): #Redirect the appspot url to the custom url
return '<meta http-equiv="refresh" content="0; url=https://isthisstockgood.com" />'

template_values = {
'page_title' : "Is This Stock Good?",
'current_year' : date.today().year,
}
return render_template('home.html', **template_values)


@app.route('/search', methods=['POST'])
def search():
if request.environ['HTTP_HOST'].endswith('.appspot.com'): #Redirect the appspot url to the custom url
return '<meta http-equiv="refresh" content="0; url=http://isthisstockgood.com" />'

ticker = request.values.get('ticker')
template_values = fetchDataForTickerSymbol(ticker)
if not template_values:
return render_template('json/error.json', **{'error' : 'Invalid ticker symbol'})
return render_template('json/stock_data.json', **template_values)
from src.server import create_app


if __name__ == '__main__':
app = create_app(fetchDataForTickerSymbol)
app.run(host='127.0.0.1', port=8080, debug=True)
Loading

0 comments on commit 016d944

Please sign in to comment.