Skip to content

Commit

Permalink
Merge pull request #50 from GSA/flask-routes
Browse files Browse the repository at this point in the history
add Flask routes
  • Loading branch information
Jin-Sun-tts authored Apr 10, 2024
2 parents f4e85df + 18974f7 commit 8bdcbdc
Show file tree
Hide file tree
Showing 22 changed files with 1,078 additions and 413 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
poetry install
- name: Setup services
run: docker-compose up -d
run: docker compose up -d

- name: Run Pytest
run: set -o pipefail; poetry run pytest --junitxml=pytest.xml --cov=harvester ./tests/unit | tee pytest-coverage.txt
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ If you followed the instructions for `CKAN load testing` and `Harvester testing`
3. when there are database DDL changes, use following steps to generate migration scripts and update database:

```bash
docker-compose db up
docker-compose run app flask db migrate -m "migration description"
docker-compose run app flask db upgrade
docker compose db up
docker compose run app flask db migrate -m "migration description"
docker compose run app flask db upgrade
```

### Deployment to cloud.gov
Expand Down
25 changes: 18 additions & 7 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,31 @@
from flask_migrate import Migrate
import os
from dotenv import load_dotenv
from flask_bootstrap import Bootstrap

load_dotenv()

DATABASE_URI = os.getenv('DATABASE_URI')

def create_app():
def create_app(testing=False):
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI

if testing:
app.config['TESTING'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
else:
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv("DATABASE_URI")
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SECRET_KEY'] = os.urandom(16)
Bootstrap(app)

db.init_app(app)

# Initialize Flask-Migrate
Migrate(app, db)

from .routes import register_routes
register_routes(app)
if not testing:
Migrate(app, db)

from .routes import register_routes
register_routes(app)

return app
22 changes: 0 additions & 22 deletions app/flask-app-structure.txt

This file was deleted.

35 changes: 35 additions & 0 deletions app/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, SelectField, TextAreaField
from wtforms.validators import DataRequired, URL, ValidationError
import re

def validate_email_list(form, field):
emails = field.data.split(',')
for email in emails:
if not re.match(r"[^@]+@[^@]+\.[^@]+", email.strip()):
raise ValidationError("Invalid email address: {}".format(email))

class HarvestSourceForm(FlaskForm):
organization_id = SelectField('Organization',
choices=[], validators=[DataRequired()])
name = StringField('Name', validators=[DataRequired()])
url = StringField('URL', validators=[DataRequired(), URL()])
emails = TextAreaField('Notification_emails',
validators=[DataRequired(), validate_email_list])
frequency = SelectField('Frequency',
choices=['Manual', 'Daily', 'Weekly', 'Biweekly','Monthly'],
validators=[DataRequired()])
user_requested_frequency = StringField('User_requested_frequency',
validators=[DataRequired()])
schema_type = SelectField('Schema Type',
choices=['strict', 'other'],
validators=[DataRequired()])
source_type = SelectField('Source Type',
choices=['Datajson', 'WAF'],
validators=[DataRequired()])
submit = SubmitField('Submit')

class OrganizationForm(FlaskForm):
name = StringField('Name', validators=[DataRequired()])
logo = StringField('Logo', validators=[DataRequired()])
submit = SubmitField('Submit')
Loading

2 comments on commit 8bdcbdc

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
harvester
   __init__.py50100% 
   ckan_utils.py4222 95%
   exceptions.py420100% 
   harvest.py4256565 85%
   logger_config.py10100% 
   utils.py5799 84%
TOTAL5727687% 

Tests Skipped Failures Errors Time
34 0 💤 0 ❌ 0 🔥 6.904s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
harvester
   __init__.py50100% 
   ckan_utils.py4222 95%
   exceptions.py420100% 
   harvest.py4256565 85%
   logger_config.py10100% 
   utils.py5799 84%
TOTAL5727687% 

Tests Skipped Failures Errors Time
34 0 💤 0 ❌ 0 🔥 4.267s ⏱️

Please sign in to comment.