Fix tests
This commit is contained in:
parent
8afeca1b5d
commit
4bfa9bbcaa
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,6 @@
|
|||
.cache
|
||||
.coverage
|
||||
.eggs
|
||||
.env
|
||||
__pycache__
|
||||
afpy.egg-info
|
||||
|
|
10
Makefile
10
Makefile
|
@ -1,15 +1,14 @@
|
|||
export PROJECT_NAME = afpy
|
||||
|
||||
VENV = $(PWD)/.env
|
||||
PIP = $(VENV)/bin/pip
|
||||
PYTHON = $(VENV)/bin/python
|
||||
FLASK = $(VENV)/bin/flask
|
||||
PYTEST = $(VENV)/bin/pytest
|
||||
|
||||
all: install serve
|
||||
|
||||
install:
|
||||
test -d $(VENV) || virtualenv $(VENV)
|
||||
$(PIP) install --upgrade --no-cache pip setuptools -e .
|
||||
$(PIP) install --upgrade --no-cache pip setuptools -e .[test]
|
||||
|
||||
clean:
|
||||
rm -fr dist
|
||||
|
@ -19,5 +18,8 @@ clean:
|
|||
check-outdated:
|
||||
$(PIP) list --outdated --format=columns
|
||||
|
||||
test:
|
||||
$(PYTEST) tests.py --flake8 --isort --cov=afpy --cov=tests
|
||||
|
||||
serve:
|
||||
$(VENV)/bin/$(PROJECT_NAME).py
|
||||
$(VENV)/bin/afpy.py
|
||||
|
|
17
afpy.py
17
afpy.py
|
@ -1,9 +1,7 @@
|
|||
from pathlib import Path
|
||||
|
||||
import docutils.core
|
||||
import docutils.writers.html5_polyglot
|
||||
import feedparser
|
||||
from flask import Flask, render_template, abort
|
||||
from flask import Flask, abort, render_template
|
||||
from jinja2 import TemplateNotFound
|
||||
|
||||
app = Flask(__name__)
|
||||
|
@ -29,11 +27,10 @@ def page_not_found(e):
|
|||
|
||||
|
||||
@app.route('/')
|
||||
@app.route('/<template_name>')
|
||||
def pages(template_name='index'):
|
||||
@app.route('/<name>')
|
||||
def pages(name='index'):
|
||||
try:
|
||||
return render_template(
|
||||
f'{template_name}.html', body_id=template_name, meetups=MEETUPS)
|
||||
return render_template(f'{name}.html', body_id=name, meetups=MEETUPS)
|
||||
except TemplateNotFound:
|
||||
abort(404)
|
||||
|
||||
|
@ -56,8 +53,6 @@ def feed(name):
|
|||
|
||||
if __name__ == '__main__':
|
||||
from sassutils.wsgi import SassMiddleware
|
||||
|
||||
app.wsgi_app = SassMiddleware(app.wsgi_app, {
|
||||
'afpy': ('sass', 'static/css', '/static/css')
|
||||
})
|
||||
app.wsgi_app = SassMiddleware(
|
||||
app.wsgi_app, {'afpy': ('sass', 'static/css', '/static/css')})
|
||||
app.run(debug=True)
|
||||
|
|
10
setup.py
10
setup.py
|
@ -1,5 +1,12 @@
|
|||
from setuptools import find_packages, setup
|
||||
|
||||
tests_requirements = [
|
||||
'pytest',
|
||||
'pytest-cov',
|
||||
'pytest-flake8',
|
||||
'pytest-isort',
|
||||
]
|
||||
|
||||
setup(
|
||||
name='afpy',
|
||||
version='0.1.dev0',
|
||||
|
@ -15,4 +22,7 @@ setup(
|
|||
'feedparser',
|
||||
],
|
||||
scripts=['afpy.py'],
|
||||
setup_requires=['pytest-runner'],
|
||||
tests_require=tests_requirements,
|
||||
extras_require={'test': tests_requirements}
|
||||
)
|
||||
|
|
19
tests.py
Normal file
19
tests.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
import pytest
|
||||
|
||||
from afpy import app
|
||||
|
||||
|
||||
def test_no_arguments():
|
||||
response = app.test_client().get('/')
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
@pytest.mark.parametrize('name', ['index', 'communaute'])
|
||||
def test_with_arguments(name):
|
||||
response = app.test_client().get(f'/{name}')
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_404():
|
||||
response = app.test_client().get('/unknown')
|
||||
assert response.status_code == 404
|
|
@ -1,38 +0,0 @@
|
|||
from functools import partial
|
||||
|
||||
import pytest
|
||||
from flask import url_for
|
||||
|
||||
import afpy
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def app():
|
||||
return afpy.app
|
||||
|
||||
|
||||
class TestPagesView:
|
||||
get_test_url = partial(url_for, 'pages')
|
||||
|
||||
def test_no_arguments(self, client):
|
||||
response = client.get(self.get_test_url())
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'template_name',
|
||||
[
|
||||
'a-propos',
|
||||
'feed',
|
||||
'rst',
|
||||
]
|
||||
)
|
||||
def test_with_arguments(self, client, template_name):
|
||||
response = client.get(self.get_test_url(template_name=template_name))
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
def test_404(self, client):
|
||||
response = client.get(self.get_test_url(template_name="bad_template_name_my_friend"))
|
||||
|
||||
assert response.status_code == 404
|
Loading…
Reference in New Issue
Block a user