Skip to content

Commit

Permalink
Merge pull request #327 from DemocracyClub/move_to_tox_and_pytest
Browse files Browse the repository at this point in the history
Move to tox and pytest
  • Loading branch information
symroe authored Jan 25, 2018
2 parents 3b5670f + 7f13503 commit 2076de7
Show file tree
Hide file tree
Showing 21 changed files with 127 additions and 58 deletions.
15 changes: 15 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[run]
branch = True
source =

auth_helpers
bulk_adding
cached_counts
candidates
compat
elections
moderation_queue
official_documents
results
tasks
uk_results
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ __pycache__
/mysite/settings/local.py
/mysite/static/jsi18n
.DS_Store
.tox
.cache
21 changes: 9 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,29 @@ addons:

cache:
pip: true
ccache: true
directories:
- /home/travis/virtualenv
- $HOME/.pip-cache/
before_cache:
- rm -f .tox/py34-django19/log/*.log
- rm -f .tox/py35-django19/log/*.log
- rm -f .cache/pip/log/*.log

- $HOME/.tox/
- .tox
env:
- ES_VERSION=2.3.1 ES_DOWNLOAD_URL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/${ES_VERSION}/elasticsearch-${ES_VERSION}.tar.gz

install:
- pip install tox coveralls tox-travis
# Install ES
- wget -nc ${ES_DOWNLOAD_URL}
- tar -xzf elasticsearch-${ES_VERSION}.tar.gz
- ./elasticsearch-${ES_VERSION}/bin/elasticsearch &
# Make sure pip is at the latest version:
- pip install -U pip
# Now install the rest of the required Python packages:
- CFLAGS="-O0" pip install -r requirements.txt
- pip install python-coveralls
- ./manage.py compilemessages

script:
- wget -q --waitretry=1 --retry-connrefused -T 10 -O - http://127.0.0.1:9200
- ./run-tests --coverage
- tox
after_success:
- coveralls
before_cache:
- rm -f .tox/py27-django19/log/*.log
- rm -f .tox/py34-django19/log/*.log
- rm -f .tox/py35-django19/log/*.log
- rm -f .cache/pip/log/*.log
2 changes: 0 additions & 2 deletions bulk_adding/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@

from official_documents.models import OfficialDocument

from nose.plugins.attrib import attr
from candidates.tests import factories
from candidates.tests.uk_examples import UK2015ExamplesMixin


@attr(country='uk')
class TestBulkAdding(TestUserMixin, UK2015ExamplesMixin, WebTest):

def setUp(self):
Expand Down
5 changes: 3 additions & 2 deletions candidates/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.core.urlresolvers import reverse
from django.utils.feedgenerator import Atom1Feed
from django.utils.translation import ugettext_lazy as _
from django.conf import settings

from .models import LoggedAction

Expand Down Expand Up @@ -50,7 +51,7 @@ def get_author(self, logged_action):


class RecentChangesFeed(ChangesMixin, Feed):
site_name = Site.objects.get_current().name
site_name = settings.SITE_NAME
title = _("{site_name} recent changes").format(site_name=site_name)
description = _("Changes to {site_name} candidates").format(site_name=site_name)
link = "/feeds/changes.xml"
Expand Down Expand Up @@ -88,7 +89,7 @@ def item_link(self, item):


class NeedsReviewFeed(ChangesMixin, Feed):
site_name = Site.objects.get_current().name
site_name = settings.SITE_NAME
title = _('{site_name} changes for review').format(site_name=site_name)
link = '/feeds/needs-review.xml'
feed_type = Atom1Feed
Expand Down
2 changes: 0 additions & 2 deletions candidates/tests/test_upcoming_elections_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from django.conf import settings
from django.utils.six.moves.urllib_parse import urljoin

from nose.plugins.attrib import attr
from django_webtest import WebTest

from candidates.tests.factories import (
Expand Down Expand Up @@ -52,7 +51,6 @@ def fake_requests_for_every_election(url, *args, **kwargs):
})


@attr(country='uk')
@patch('elections.uk.geo_helpers.requests')
class TestUpcomingElectionsAPI(UK2015ExamplesMixin, WebTest):
def setUp(self):
Expand Down
3 changes: 0 additions & 3 deletions elections/uk/tests/test_country_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

from django.test import TestCase

from nose.plugins.attrib import attr

from candidates.election_specific import additional_merge_actions
from candidates.tests import factories

@attr(country='uk')
class TestUKSpecificOverride(TestCase):

@patch('elections.uk.lib.additional_merge_actions')
Expand Down
3 changes: 0 additions & 3 deletions elections/uk/tests/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

from django.test import TestCase

from nose.plugins.attrib import attr

from candidates.models import PersonExtra, PersonRedirect
from candidates.tests import factories
from candidates.tests.uk_examples import UK2015ExamplesMixin


@attr(country='uk')
class CSVTests(UK2015ExamplesMixin, TestCase):

def setUp(self):
Expand Down
2 changes: 0 additions & 2 deletions elections/uk/tests/test_custom_merge.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django_webtest import WebTest
from nose.plugins.attrib import attr
from popolo.models import Person

from candidates.tests import factories
Expand All @@ -10,7 +9,6 @@
from uk_results.models import CandidateResult, PostElectionResult, ResultSet


@attr(country='uk')
class TestUKResultsPreserved(TestUserMixin, UK2015ExamplesMixin, WebTest):

def setUp(self):
Expand Down
3 changes: 0 additions & 3 deletions elections/uk/tests/test_person_view.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from nose.plugins.attrib import attr

from candidates.tests.person_view_shared_tests_mixin import PersonViewSharedTestsMixin


@attr(country='uk')
class TestPersonView(PersonViewSharedTestsMixin):
pass
3 changes: 0 additions & 3 deletions elections/uk/tests/test_post_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
from moderation_queue.models import SuggestedPostLock
from official_documents.models import OfficialDocument

from nose.plugins.attrib import attr

from candidates.models import PostExtraElection
from candidates.tests.auth import TestUserMixin
from candidates.tests.uk_examples import UK2015ExamplesMixin


@attr(country='uk')
class TestConstituencyDetailView(TestUserMixin, UK2015ExamplesMixin, WebTest):

def test_suggest_post_lock_offered_with_document_when_unlocked(self):
Expand Down
2 changes: 0 additions & 2 deletions moderation_queue/tests/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from io import BytesIO
from django_webtest import WebTest
from mock import patch
from nose.plugins.attrib import attr

from popolo.models import Person
from ..models import QueuedImage, PHOTO_REVIEWERS_GROUP_NAME, SuggestedPostLock
Expand Down Expand Up @@ -506,7 +505,6 @@ def test_suggested_lock_review_view_with_suggestions(self):
self.assertContains(response, '<h3>')


@attr(country='uk')
class SOPNReviewRequiredTest(UK2015ExamplesMixin, TestUserMixin, WebTest):

def test_sopn_review_view_no_reviews(self):
Expand Down
15 changes: 10 additions & 5 deletions mysite/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def root(*path):
ALLOWED_HOSTS = []

SITE_ID = 1
SITE_NAME = "Democracy Club Candidates"

# Google analytics settings:
GOOGLE_ANALYTICS_ACCOUNT = None
Expand Down Expand Up @@ -85,7 +86,6 @@ def root(*path):
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django_nose',
'django_extensions',
'pipeline',
'statici18n',
Expand Down Expand Up @@ -304,8 +304,6 @@ def root(*path):
}


TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'

SOURCE_HINTS = (
u"Please don't quote third-party candidate sites \u2014 ",
u"we prefer URLs of news stories or official candidate pages."
Expand All @@ -316,7 +314,7 @@ def root(*path):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'ynr',
'NAME': '',
# Note that there are various comments on the web
# suggesting that settings CONN_MAX_AGE != 0 is a bad
# idea when eventlet or gevent workers are being used.
Expand Down Expand Up @@ -427,5 +425,12 @@ def root(*path):
fg="red"
))

if len(sys.argv) > 1 and sys.argv[1] in ['test']:
def _is_running_tests():
if len(sys.argv) > 1 and sys.argv[1] in ['test']:
return True
if os.environ.get('RUN_ENV') == 'test':
return True
return False

if _is_running_tests():
from .testing import * # noqa
40 changes: 40 additions & 0 deletions mysite/settings/local.example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Only set this to True in development environments
DEBUG = True

# Set this to a long random string and keep it secret
# This is a handy tool:
# https://www.miniwebtool.com/django-secret-key-generator/
SECRET_KEY = None

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '',
'USER': '',
'PASSWORD': '',
},
}

# A tuple of tuples containing (Full name, email address)
ADMINS = ()

# **** Other settings that might be useful to change locally

# ALLOWED_HOSTS = ['*']
# INTERNAL_IPS = ['127.0.0.1', 'localhost', ]

# CACHES = {
# "default": {
# "BACKEND": "django.core.cache.backends.dummy.DummyCache",
# }
# }


# **** Settings that might be useful in production

# STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
# SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# ACCOUNT_DEFAULT_HTTP_PROTOCOL = 'https'
# RAVEN_CONFIG = {
# 'dsn': ''
# }
11 changes: 1 addition & 10 deletions mysite/settings/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


DATABASES['default']['CONN_MAX_AGE'] = 0
SITE_NAME = "example.com"

CACHES = {
'default': {
Expand All @@ -15,16 +16,6 @@
]

RUNNING_TESTS = True
NOSE_ARGS = [
'--nocapture',
'--with-yanc',
# There are problems with OpenCV on Travis, so don't even try to
# import moderation_queue/faces.py
'--ignore-files=faces',
'--ignore-files=mysite/settings/testing.py',
'--with-doctest'
]


SECRET_KEY = "just here for testing"

Expand Down
3 changes: 3 additions & 0 deletions mysite/settings/travis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .testing import * # noqa

DATABASES['default']['NAME'] = 'postgres'
11 changes: 11 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[pytest]
norecursedirs = .tox /locale /static
DJANGO_SETTINGS_MODULE = mysite.settings.base

pep8ignore =
.tox *

env =
RUN_ENV=test


14 changes: 10 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ beautifulsoup4==4.4.1
bleach==1.4.1
certifi==2015.04.28
cffi==1.5.0
coverage==3.7.1
coverage>=3.6
cryptography==1.2.3
decorator==4.0.4
Django>=1.9,<1.10
Expand All @@ -13,12 +13,12 @@ django-cors-headers==1.1.0
django-date-extensions==1.1.0
django-crispy-forms==1.6.0
django-debug-toolbar==1.9
django-debug-toolbar-template-timings
django-extensions==1.6.1
django-filter==0.13
django-haystack==2.5.1
django-markdown-deux==1.0.5
django-model-utils==2.3.1
django-nose==1.4.4
django-notifications-hq==1.0.0
django-pipeline==1.6.8
-e git+https://github.com/mysociety/django-popolo@update-with-better-migrations-redux#egg=mysociety-django-popolo
Expand Down Expand Up @@ -46,18 +46,23 @@ lxml==3.4.1
mock==1.0.1
mysociety-django-images==0.0.5
ndg-httpsclient==0.4.0
nose==1.3.7
numpy==1.9.1
oauthlib==0.7.2
path.py==8.1.1
pexpect==3.3
pickleshare==0.5
Pillow==3.2.0
psycopg2==2.5.4
psycopg2==2.7.1
pyasn1==0.1.9
pycparser==2.14
pygeocoder==1.2.5
pyOpenSSL==0.15.1
pytest
pytest-cov
pytest-django
pytest-env
pytest-flakes
pytest-pep8
python-dateutil==2.4.2
python-magic==0.4.6
python-memcached==1.54
Expand All @@ -71,6 +76,7 @@ simplegeneric==0.8.1
six==1.10.0
sorl-thumbnail==12.3
sqlparse==0.1.15
tox
traitlets==4.0.0
Unidecode==0.4.17
urllib3==1.13
Expand Down
Loading

0 comments on commit 2076de7

Please sign in to comment.