Skip to content

Commit 1d9609f

Browse files
authored
Merge pull request #5 from mjhea0/updated-master
bump dependencies, lint, update readme
2 parents 4fd719c + e399d12 commit 1d9609f

File tree

16 files changed

+86
-70
lines changed

16 files changed

+86
-70
lines changed

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.7.0
1+
3.8.0

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# base image
2-
FROM python:3.7.0-alpine
2+
FROM python:3.8.0-alpine
33

44
# set working directory
55
RUN mkdir -p /usr/src/app
@@ -10,3 +10,6 @@ ADD ./requirements.txt /usr/src/app/requirements.txt
1010

1111
# install requirements
1212
RUN pip install -r requirements.txt
13+
14+
# copy project
15+
COPY . /usr/src/app

LICENSE

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
The MIT License (MIT)
2-
Copyright (c) 2018 Michael Herman
1+
MIT License
32

4-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3+
Copyright (c) 2019 Michael Herman
54

6-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
711

8-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Spin up the containers:
1010
$ docker-compose up -d --build
1111
```
1212

13-
Open your browser to http://localhost:5004 to view the app or to http://localhost:9181 to view the RQ dashboard.
13+
Open your browser to http://localhost:5004 to view the app or to http://localhost:9181 to view the RQ dashboard.
1414

15-
### Want to learn how to build this?
15+
### Want to learn how to build this?
1616

1717
Check out the [post](https://testdriven.io/asynchronous-tasks-with-flask-and-redis-queue).

docker-compose.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ services:
77
image: web
88
container_name: web
99
ports:
10-
- '5004:5000'
10+
- 5004:5000
1111
command: python manage.py run -h 0.0.0.0
1212
volumes:
1313
- .:/usr/src/app
@@ -28,12 +28,14 @@ services:
2828
- redis
2929

3030
redis:
31-
image: redis:4.0.11-alpine
31+
image: redis:5.0.7-alpine
3232

3333
dashboard:
3434
build: ./project/dashboard
3535
image: dashboard
3636
container_name: dashboard
3737
ports:
38-
- '9181:9181'
38+
- 9181:9181
3939
command: rq-dashboard -H redis
40+
depends_on:
41+
- redis

manage.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@
1717
@cli.command()
1818
def test():
1919
"""Runs the unit tests without test coverage."""
20-
tests = unittest.TestLoader().discover('project/tests', pattern='test*.py')
20+
tests = unittest.TestLoader().discover("project/tests", pattern="test*.py")
2121
result = unittest.TextTestRunner(verbosity=2).run(tests)
2222
if result.wasSuccessful():
2323
return 0
2424
return 1
2525

2626

27-
@cli.command('run_worker')
27+
@cli.command("run_worker")
2828
def run_worker():
29-
redis_url = app.config['REDIS_URL']
29+
redis_url = app.config["REDIS_URL"]
3030
redis_connection = redis.from_url(redis_url)
3131
with Connection(redis_connection):
32-
worker = Worker(app.config['QUEUES'])
32+
worker = Worker(app.config["QUEUES"])
3333
worker.work()
3434

3535

36-
if __name__ == '__main__':
36+
if __name__ == "__main__":
3737
cli()

project/dashboard/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.7.0-alpine
1+
FROM python:3.8.0-alpine
22

33
RUN pip install rq-dashboard
44

project/server/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from flask import Flask
77
from flask_bootstrap import Bootstrap
88

9-
109
# instantiate the extensions
1110
bootstrap = Bootstrap()
1211

@@ -16,22 +15,23 @@ def create_app(script_info=None):
1615
# instantiate the app
1716
app = Flask(
1817
__name__,
19-
template_folder='../client/templates',
20-
static_folder='../client/static'
18+
template_folder="../client/templates",
19+
static_folder="../client/static",
2120
)
2221

2322
# set config
24-
app_settings = os.getenv('APP_SETTINGS')
23+
app_settings = os.getenv("APP_SETTINGS")
2524
app.config.from_object(app_settings)
2625

2726
# set up extensions
2827
bootstrap.init_app(app)
2928

3029
# register blueprints
3130
from project.server.main.views import main_blueprint
31+
3232
app.register_blueprint(main_blueprint)
3333

3434
# shell context for flask cli
35-
app.shell_context_processor({'app': app})
35+
app.shell_context_processor({"app": app})
3636

3737
return app

project/server/config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
# project/server/config.py
22

33
import os
4+
45
basedir = os.path.abspath(os.path.dirname(__file__))
56

67

78
class BaseConfig(object):
89
"""Base configuration."""
10+
911
WTF_CSRF_ENABLED = True
10-
REDIS_URL = 'redis://redis:6379/0'
11-
QUEUES = ['default']
12+
REDIS_URL = "redis://redis:6379/0"
13+
QUEUES = ["default"]
1214

1315

1416
class DevelopmentConfig(BaseConfig):
1517
"""Development configuration."""
18+
1619
WTF_CSRF_ENABLED = False
1720

1821

1922
class TestingConfig(BaseConfig):
2023
"""Testing configuration."""
24+
2125
TESTING = True
2226
WTF_CSRF_ENABLED = False
2327
PRESERVE_CONTEXT_ON_EXCEPTION = False

project/server/main/views.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,47 @@
33

44
import redis
55
from rq import Queue, Connection
6-
from flask import render_template, Blueprint, jsonify, \
7-
request, current_app
6+
from flask import render_template, Blueprint, jsonify, request, current_app
87

98
from project.server.main.tasks import create_task
109

10+
main_blueprint = Blueprint("main", __name__,)
1111

12-
main_blueprint = Blueprint('main', __name__,)
1312

14-
15-
@main_blueprint.route('/', methods=['GET'])
13+
@main_blueprint.route("/", methods=["GET"])
1614
def home():
17-
return render_template('main/home.html')
15+
return render_template("main/home.html")
1816

1917

20-
@main_blueprint.route('/tasks', methods=['POST'])
18+
@main_blueprint.route("/tasks", methods=["POST"])
2119
def run_task():
22-
task_type = request.form['type']
23-
with Connection(redis.from_url(current_app.config['REDIS_URL'])):
20+
task_type = request.form["type"]
21+
with Connection(redis.from_url(current_app.config["REDIS_URL"])):
2422
q = Queue()
2523
task = q.enqueue(create_task, task_type)
2624
response_object = {
27-
'status': 'success',
28-
'data': {
29-
'task_id': task.get_id()
25+
"status": "success",
26+
"data": {
27+
"task_id": task.get_id()
3028
}
3129
}
3230
return jsonify(response_object), 202
3331

3432

35-
@main_blueprint.route('/tasks/<task_id>', methods=['GET'])
33+
@main_blueprint.route("/tasks/<task_id>", methods=["GET"])
3634
def get_status(task_id):
37-
with Connection(redis.from_url(current_app.config['REDIS_URL'])):
35+
with Connection(redis.from_url(current_app.config["REDIS_URL"])):
3836
q = Queue()
3937
task = q.fetch_job(task_id)
4038
if task:
4139
response_object = {
42-
'status': 'success',
43-
'data': {
44-
'task_id': task.get_id(),
45-
'task_status': task.get_status(),
46-
'task_result': task.result,
47-
}
40+
"status": "success",
41+
"data": {
42+
"task_id": task.get_id(),
43+
"task_status": task.get_status(),
44+
"task_result": task.result,
45+
},
4846
}
4947
else:
50-
response_object = {'status': 'error'}
48+
response_object = {"status": "error"}
5149
return jsonify(response_object)

project/tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# project/server/tests/__init__.py
1+
# project/tests/__init__.py

project/tests/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# project/server/tests/base.py
1+
# project/tests/base.py
22

33

44
from flask_testing import TestCase
@@ -9,9 +9,8 @@
99

1010

1111
class BaseTestCase(TestCase):
12-
1312
def create_app(self):
14-
app.config.from_object('project.server.config.TestingConfig')
13+
app.config.from_object("project.server.config.TestingConfig")
1514
return app
1615

1716
def setUp(self):

project/tests/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# tests/helpers.py
1+
# project/tests/helpers.py

project/tests/test__config.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# project/server/tests/test__config.py
1+
# project/tests/test__config.py
22

33

44
import unittest
@@ -12,29 +12,27 @@
1212

1313

1414
class TestDevelopmentConfig(TestCase):
15-
1615
def create_app(self):
17-
app.config.from_object('project.server.config.DevelopmentConfig')
16+
app.config.from_object("project.server.config.DevelopmentConfig")
1817
return app
1918

2019
def test_app_is_development(self):
21-
self.assertFalse(current_app.config['TESTING'])
22-
self.assertTrue(app.config['DEBUG'] is True)
23-
self.assertTrue(app.config['WTF_CSRF_ENABLED'] is False)
20+
self.assertFalse(current_app.config["TESTING"])
21+
self.assertTrue(app.config["DEBUG"] is True)
22+
self.assertTrue(app.config["WTF_CSRF_ENABLED"] is False)
2423
self.assertFalse(current_app is None)
2524

2625

2726
class TestTestingConfig(TestCase):
28-
2927
def create_app(self):
30-
app.config.from_object('project.server.config.TestingConfig')
28+
app.config.from_object("project.server.config.TestingConfig")
3129
return app
3230

3331
def test_app_is_testing(self):
34-
self.assertTrue(current_app.config['TESTING'])
35-
self.assertTrue(app.config['DEBUG'] is True)
36-
self.assertTrue(app.config['WTF_CSRF_ENABLED'] is False)
32+
self.assertTrue(current_app.config["TESTING"])
33+
self.assertTrue(app.config["DEBUG"] is True)
34+
self.assertTrue(app.config["WTF_CSRF_ENABLED"] is False)
3735

3836

39-
if __name__ == '__main__':
37+
if __name__ == "__main__":
4038
unittest.main()

project/tests/test_main.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# project/server/tests/test_main.py
1+
# project/tests/test_main.py
22

33

44
import unittest
@@ -7,12 +7,11 @@
77

88

99
class TestMainBlueprint(BaseTestCase):
10-
1110
def test_index(self):
1211
# Ensure Flask is setup.
13-
response = self.client.get('/', follow_redirects=True)
12+
response = self.client.get("/", follow_redirects=True)
1413
self.assertEqual(response.status_code, 200)
1514

1615

17-
if __name__ == '__main__':
16+
if __name__ == "__main__":
1817
unittest.main()

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Flask==1.0.2
1+
Flask==1.1.1
22
Flask-Bootstrap==3.3.7.1
33
Flask-Testing==0.7.1
44
Flask-WTF==0.14.2
5-
redis==2.10.6
6-
rq==0.12.0
5+
redis==3.3.11
6+
rq==1.1.0

0 commit comments

Comments
 (0)