Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #60 from makyo/coveralls
Browse files Browse the repository at this point in the history
Add Coveralls, Tox
  • Loading branch information
makyo committed Nov 21, 2016
2 parents e64804e + 4550a7b commit ee7208f
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 72 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
@@ -0,0 +1,3 @@
[report]
show_missing = True
skip_covered = True
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -2,4 +2,5 @@
*.db
.coverage
*~
.venv
venv
.tox
13 changes: 7 additions & 6 deletions .travis.yml
@@ -1,8 +1,9 @@
language: python

python:
python:
- "2.7"

install: "pip install -r pip-requirements.txt"

script: make check
- "3.5"
install: "pip install -r requirements.txt"
script:
- make rawcheck
after_success:
- ./run-coveralls.sh
52 changes: 33 additions & 19 deletions Makefile
@@ -1,43 +1,57 @@
SQLITE=sqlite3
LOCAL_DB=ideawheel.db
DB_SCHEMA=schema.sql
VIRTUALENV=venv

help:
@echo 'Usage:'
@echo ' make deps installs dependencies'
@echo ' make basedb sets up an empty local database'
@echo ' make devserver starts the development server'
@echo ' make check run tests and lint'
@echo ' make test run the tests'
@echo ' make lint run flake8 for pep8 linting'
@echo ' make clean removes compiled files'
@echo ' make help displays this message'

deps:
pip install -r pip-requirements.txt
@echo ' make deps installs dependencies'
@echo ' make basedb sets up an empty local database'
@echo ' make devserver starts the development server in tox (py35)'
@echo ' make check run tests and lint in tox (py27 and py35)'
@echo ' make rawdevserver starts the development server in a virtualenv'
@echo ' make rawcheck run tests and lint in a virtualenv'
@echo ' make rawtest run the tests in a virtualenv'
@echo ' make rawlint run flake8 for pep8 linting in a virtualenv'
@echo ' make clean removes compiled files and virtual environments'
@echo ' make help displays this message'

deps: $(VIRTUALENV)
$(VIRTUALENV)/bin/pip install -r requirements.txt

basedb: $(LOCAL_DB)

$(LOCAL_DB): $(DB_SCHEMA)
rm -f $(LOCAL_DB)
$(SQLITE) $(LOCAL_DB) < $(DB_SCHEMA)

check:
tox

devserver:
python ideawheel.py
tox -e devenv

rawdevserver: $(VIRTUALENV)
$(VIRTUALENV)/bin/python ideawheel.py

devfixtures: basedb
for i in `find fixtures/dev/*.sql | sort`; do $(SQLITE) $(LOCAL_DB) < $$i; done

check: test lint
rawcheck: rawlint rawtest

test:
@nosetests --verbosity=2 --with-coverage --cover-package=ideawheel,models,views
@rm .coverage
rawtest: $(VIRTUALENV)
coverage erase
nosetests --verbosity=2 --with-coverage --cover-package=ideawheel,models,views

lint:
@flake8 --show-source ideawheel.py ideawheel_tests.py models views
rawlint: $(VIRTUALENV)
flake8 --config=tox.ini

clean:
rm -rf .tox $(VIRTUALENV)
find . -name '*.py[co]' -exec rm -f {} \;

.PHONY: help deps basedb devfixtures devserver check test lint clean
$(VIRTUALENV):
virtualenv $(VIRTUALENV)
$(VIRTUALENV)/bin/pip install -r requirements.txt

.PHONY: help deps basedb devfixtures devserver check test lint rawdevserver rawcheck rawtest rawlint clean
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -3,6 +3,7 @@ ideawheel

[![Build
Status](https://travis-ci.org/OpenFurry/ideawheel.svg?branch=master)](https://travis-ci.org/OpenFurry/ideawheel)
[![Coverage Status](https://coveralls.io/repos/github/OpenFurry/ideawheel/badge.svg?branch=master)](https://coveralls.io/github/OpenFurry/ideawheel?branch=master)

A wheel of ideas for creators. Build ideas up from stubs and then post creative
works inspired by those ideas to share with other creators.
Expand Down
3 changes: 3 additions & 0 deletions ideawheel.py
Expand Up @@ -79,12 +79,14 @@ def generate_csrf_token():
session['_csrf_token'] = hashlib.sha1(os.urandom(40)).hexdigest()
return session.get('_csrf_token', '')


app.jinja_env.globals['csrf_token'] = generate_csrf_token


def user_type_to_text(user_type):
return app.config['USER_TYPES'][user_type]


app.jinja_env.globals['user_type_to_text'] = user_type_to_text


Expand All @@ -93,6 +95,7 @@ def user_type_to_text(user_type):
def default():
return render_template('index.html')


# Register blueprints
app.register_blueprint(content_posting.mod)
app.register_blueprint(idea_building.mod)
Expand Down
47 changes: 24 additions & 23 deletions ideawheel_tests.py
Expand Up @@ -71,7 +71,7 @@ def test_register(self):
email='TestEmail@example.com',
hp=''
), follow_redirects=True)
self.assertIn('All fields are required', result.data)
self.assertIn(b'All fields are required', result.data)

# Missing field
result = self.app.post('/register', data=dict(
Expand All @@ -81,7 +81,7 @@ def test_register(self):
email='',
hp=''
), follow_redirects=True)
self.assertIn('All fields are required', result.data)
self.assertIn(b'All fields are required', result.data)

# Honeypot with data
result = self.app.post('/register', data=dict(
Expand All @@ -91,35 +91,35 @@ def test_register(self):
email='TestEmail@example.com',
hp='Actually a spammer'
), follow_redirects=True)
self.assertIn('All fields are required', result.data)
self.assertIn(b'All fields are required', result.data)

# Success
result = self.create_user()
self.assertIn('Logged in as <a href="/user/TestUser">TestUser</a>',
self.assertIn(b'Logged in as <a href="/user/TestUser">TestUser</a>',
result.data)

# Duplicate user
result = self.create_user()
self.assertIn('That username or email is already in use', result.data)
self.assertIn(b'That username or email is already in use', result.data)

def test_login(self):
self.create_user()

# Success
result = self.login()
self.assertIn('Logout', result.data)
self.assertIn(b'Logout', result.data)

# Bad user/pass
result = self.login('Bad', 'User')
self.assertIn('Incorrect username or password', result.data)
self.assertIn(b'Incorrect username or password', result.data)

def test_logout(self):
self.create_user()
self.login()

# Success
result = self.logout()
self.assertIn('Login', result.data)
self.assertIn(b'Login', result.data)

def test_edit_and_view_profile(self):
self.create_user()
Expand All @@ -128,10 +128,10 @@ def test_edit_and_view_profile(self):
self.login()
result = self.app.get('/user/TestUser')
expected = [
'~TestUser',
'thinker of grand ideas',
'user',
'No information provided'
b'~TestUser',
b'thinker of grand ideas',
b'user',
b'No information provided'
]
for e in expected:
self.assertIn(e, result.data)
Expand All @@ -147,10 +147,10 @@ def test_edit_and_view_profile(self):
new_password2=''
), follow_redirects=True)
expected = [
'New name',
'New artist type',
'user',
'New blurb'
b'New name',
b'New artist type',
b'user',
b'New blurb'
]
for e in expected:
self.assertIn(e, result.data)
Expand All @@ -170,7 +170,7 @@ def test_edit_and_view_profile(self):
new_password='',
new_password2=''
), follow_redirects=True)
self.assertIn('Edited by admin', result.data)
self.assertIn(b'Edited by admin', result.data)
self.logout()

# Permission denied editing someone else's profile
Expand All @@ -186,7 +186,7 @@ def test_edit_and_view_profile(self):
), follow_redirects=True)
self.assertEqual(result.status_code, 403)
result = self.app.get('/user/Admin')
self.assertNotIn('Edited by non-admin', result.data)
self.assertNotIn(b'Edited by non-admin', result.data)
self.logout()

# Permission denied when logged out
Expand Down Expand Up @@ -215,7 +215,7 @@ def test_create_stub(self):
result = self.app.post('/stub/create', data=dict(
stub_text='Sample stub text',
), follow_redirects=True)
self.assertIn('Stub created', result.data)
self.assertIn(b'Stub created', result.data)

self.create_user(username='Staff', password='Staff',
email='Admin@example.com')
Expand All @@ -225,22 +225,23 @@ def test_create_stub(self):
result = self.app.post('/stub/create', data=dict(
stub_text='Sample stub text',
), follow_redirects=True)
self.assertIn('Stub created', result.data)
self.assertIn(b'Stub created', result.data)

def test_random_stub(self):
# This assumes that the randomness of SQLite works, focusing instead on
# displaying the random stub.
self.login()
self.create_stub('A stub without a link')
result = self.app.get('/idea')
self.assertIn('A stub without a link', result.data)
self.assertIn(b'A stub without a link', result.data)

def test_random_stub_with_link(self):
self.login()
self.create_stub('A stub with a link', link='the link itself')
result = self.app.get('/idea')
self.assertIn('A stub with a link', result.data)
self.assertIn('the link itself', result.data)
self.assertIn(b'A stub with a link', result.data)
self.assertIn(b'the link itself', result.data)


if __name__ == '__main__':
unittest.main()
11 changes: 0 additions & 11 deletions pip-requirements.txt

This file was deleted.

19 changes: 19 additions & 0 deletions requirements.txt
@@ -0,0 +1,19 @@
click==6.6
coverage==4.0.3
flake8==3.2.0
Flask==0.11.1
Flask-Markdown==0.3
itsdangerous==0.24
Jinja2==2.8
Markdown==2.6.7
MarkupSafe==0.23
mccabe==0.5.2
nose==1.3.7
py-bcrypt==0.4
pycodestyle==2.2.0
pyflakes==1.3.0
python-coveralls==2.9.0
PyYAML==3.12
requests==2.12.1
six==1.10.0
Werkzeug==0.11.11
9 changes: 9 additions & 0 deletions run-coveralls.sh
@@ -0,0 +1,9 @@
#!/bin/bash

echo "$TRAVIS_PYTHON_VERSION"
if [ "$TRAVIS_PYTHON_VERSION" == "3.5" ] ; then
echo "Running coveralls..."
coveralls
else
echo "Skipping coveralls."
fi
17 changes: 17 additions & 0 deletions tox.ini
@@ -0,0 +1,17 @@
[tox]
envlist = 2.7,3.5
skipsdist = True

[testenv]
deps = -rrequirements.txt
commands =
flake8
coverage erase
nosetests --verbosity=2 --with-coverage --cover-package=ideawheel,models,views

[testenv:devenv]
basepython = python3.5
commands = python ideawheel.py

[flake8]
exclude = .git,.tox,venv

0 comments on commit ee7208f

Please sign in to comment.