Skip to content

Commit

Permalink
Modify travis test tasks
Browse files Browse the repository at this point in the history
- Use pytest for running tests
- Fix lint errors
  • Loading branch information
sloria committed Oct 27, 2016
1 parent 393f76d commit 17e0e3d
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 83 deletions.
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"esnext": true,
"predef": ["window", "document"],
"browser": true,
"validthis": true
"validthis": true,
"loopfunc": true
}
1 change: 0 additions & 1 deletion api/collections/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from rest_framework import serializers as ser
from rest_framework import exceptions
from modularodm.exceptions import ValidationValueError
from framework.exceptions import PermissionsError
from website.exceptions import NodeStateError

Expand Down
2 changes: 0 additions & 2 deletions framework/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-

from django.utils import timezone
import uuid

from django.utils import timezone
Expand Down
3 changes: 0 additions & 3 deletions framework/sessions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-

from datetime import datetime
import httplib as http
import urllib
import urlparse
Expand All @@ -15,7 +13,6 @@
from werkzeug.local import LocalProxy

from framework.flask import redirect
from framework.mongo import database
from framework.sessions.model import Session
from framework.sessions.utils import remove_session
from website import settings
Expand Down
3 changes: 1 addition & 2 deletions osf/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def __iter__(self):
if hasattr(item, 'wrapped'):
yield item.wrapped()
else:
yield item

yield item

def sort(self, *fields):
# Fields are passed in as e.g. [('title', 1), ('date_created', -1)]
Expand Down
16 changes: 0 additions & 16 deletions osf/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,22 +701,6 @@ def create(cls, username, password, fullname):
user.set_password(password)
return user

def verify_password_token(self, token):
"""
Verify that the password reset token for this user is valid.
:param token: the token in verification key
:return `True` if valid, otherwise `False`
"""

if token and self.verification_key_v2:
try:
return (self.verification_key_v2['token'] == token and
self.verification_key_v2['expires'] > timezone.utcnow())
except AttributeError:
return False
return False

def set_password(self, raw_password, notify=True):
"""Set the password for this user to the hash of ``raw_password``.
If this is a new user, we're done. If this is a password change,
Expand Down
1 change: 0 additions & 1 deletion osf/utils/datetime_aware_jsonfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from django.contrib.postgres import lookups
from django.contrib.postgres.fields.jsonb import JSONField
from django.core.serializers.json import DjangoJSONEncoder
from django.db.models import QuerySet

from osf.exceptions import ValidationError
from psycopg2.extras import Json
Expand Down
5 changes: 0 additions & 5 deletions osf_tests/requirements.txt

This file was deleted.

2 changes: 2 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Requirements that are used in the development environment only

# Testing
pytest==2.9.2
pytest-django==2.9.1
nose
factory-boy==2.7.0
webtest-plus==0.3.3
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[flake8]
ignore = E501,E127,E128,E265,E301,E302,E266,E731,N803,N806
max-line-length = 100
exclude = .git,.ropeproject,.tox,docs,setup.py,env,venv,models/migrations,api_tests/*,tests/*,scripts/*,src,website/uploads/,website/static/**/*,website/settings/*,framework/forms/*,website/addons/*/tests/*,env,venv,node_modules,admin/static/*
exclude = .git,.ropeproject,.tox,docs,setup.py,env,venv,models/migrations,osf_tests/*,api_tests/*,tests/*,scripts/*,src,website/uploads/,website/static/**/*,website/settings/*,framework/forms/*,website/addons/*/tests/*,env,venv,node_modules,admin/static/*,osf/management/,osf/migrations,addons/

[wheel]
universal = 1
57 changes: 29 additions & 28 deletions tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from invoke import Collection

from website import settings
from utils import pip_install, bin_prefix
from .utils import pip_install, bin_prefix

logging.getLogger('invoke').setLevel(logging.CRITICAL)

Expand All @@ -25,13 +25,6 @@
WHEELHOUSE_PATH = os.environ.get('WHEELHOUSE')
CONSTRAINTS_PATH = os.path.join(HERE, 'requirements', 'constraints.txt')

try:
__import__('rednose')
except ImportError:
TEST_CMD = 'nosetests'
else:
TEST_CMD = 'nosetests --rednose'

ns = Collection()

try:
Expand Down Expand Up @@ -507,26 +500,33 @@ def requirements(ctx, base=False, addons=False, release=False, dev=False, metric


@task
def test_module(ctx, module=None, verbosity=2):
def test_module(ctx, module=None):
"""Helper for running tests.
"""
# Allow selecting specific submodule
module_fmt = ' '.join(module) if isinstance(module, list) else module
args = ' --verbosity={0} -s {1}'.format(verbosity, module_fmt)
# Use pty so the process buffers "correctly"
ctx.run(bin_prefix(TEST_CMD) + args, pty=True)

import pytest
args = ['-s']
modules = [module] if isinstance(module, basestring) else module
args.extend(modules)
retcode = pytest.main(args)
sys.exit(retcode)

# TODO: Add to this list when more modules are ported for djangosf compat
CORE_TESTS = [
'tests/test_views.py',
]
@task
def test_osf(ctx):
"""Run the OSF test suite."""
test_module(ctx, module='tests/')
test_module(ctx, module=CORE_TESTS)


API_TESTS = [
'api_tests',
]
@task
def test_api(ctx):
"""Run the API test suite."""
test_module(ctx, module='api_tests/')
test_module(ctx, module=API_TESTS)


@task
Expand All @@ -549,15 +549,14 @@ def test_varnish(ctx):
proc.kill()


ADDON_TESTS = [
'addons/',
]
@task
def test_addons(ctx):
"""Run all the tests in the addons directory.
"""
modules = []
for addon in settings.ADDONS_REQUESTED:
module = os.path.join(settings.BASE_PATH, 'addons', addon)
modules.append(module)
test_module(ctx, module=modules)
test_module(ctx, module=ADDON_TESTS)


@task
Expand All @@ -571,18 +570,19 @@ def test(ctx, all=False, syntax=False):

test_osf(ctx)
test_api(ctx)
test_admin(ctx)
# TODO: Enable admin tests
# test_admin(ctx)

if all:
test_addons(ctx)
karma(ctx, single=True, browsers='PhantomJS')

# TODO: Remove me when osf_tests are moved to osf-models repo
OSF_MODELS_TESTS = [
'osf_tests',
]
@task
def test_osf_models(ctx):
import pytest
retcode = pytest.main(['osf_tests'])
sys.exit(retcode)
test_module(ctx, OSF_MODELS_TESTS)

@task
def test_js(ctx):
Expand Down Expand Up @@ -610,7 +610,8 @@ def test_travis_else(ctx):
flake(ctx)
jshint(ctx)
test_api(ctx)
test_admin(ctx)
# TODO: Enable admin tests
# test_admin(ctx)


@task
Expand Down
1 change: 0 additions & 1 deletion website/files/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def copy_files(src, target_node, parent=None, name=None):
if src.is_file and src.versions.exists():
cloned.versions.add(*src.versions.all())


if not src.is_file:
for child in src.children:
copy_files(child, target_node, parent=cloned)
Expand Down
22 changes: 0 additions & 22 deletions website/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,6 @@ def new_bookmark_collection(user):
return collection


def new_collection(title, user):
"""Create a new folder project.
:param str title: Node title
:param User user: User object
:return Node: Created node
"""
title = strip_html(title.strip())

node = Node(
title=title,
creator=user,
category='project',
is_collection=True
)

node.save()

return node


def new_private_link(name, user, nodes, anonymous):
"""Create a new private link.
Expand Down

0 comments on commit 17e0e3d

Please sign in to comment.