Skip to content

Commit

Permalink
Merge c3f5301 into 948eb54
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp committed Dec 20, 2018
2 parents 948eb54 + c3f5301 commit 8ade0d9
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 97 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ python:
- "3.6"
install:
- pip install -U pip setuptools
- pip install coveralls
- python setup.py install
- pip install coveralls pytest-cov
before_script:
- psql -c "create database travis_ci_test;" -U postgres
script:
- coverage run --source=misago setup.py test
- pytest --cov
after_success:
- coveralls
7 changes: 3 additions & 4 deletions dev
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ intro() {
echo
echo "Testing:"
echo
echo " ${BOLD}test${NORMAL} run tests suite."
echo " ${BOLD}test module${NORMAL} run tests suite in specified python module, eg. misago.users."
echo " ${BOLD}test${NORMAL} run tests suite using pytest."
echo
echo "Translations:"
echo
Expand Down Expand Up @@ -197,7 +196,7 @@ rebuild() {

# Run tests suite
test() {
docker-compose run --rm misago python runtests.py $1
docker-compose run --rm misago pytest "${@:2}"
}

# Make messages
Expand Down Expand Up @@ -284,7 +283,7 @@ if [[ $1 ]]; then
elif [[ $1 = "rebuild" ]]; then
rebuild $@
elif [[ $1 = "test" ]]; then
test $2
test $@
elif [[ $1 = "makemessages" ]]; then
makemessages ${2:-en}
elif [[ $1 = "makemessages_in_docker" ]]; then
Expand Down
6 changes: 3 additions & 3 deletions misago/core/tests/test_errorpages.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_social_auth_banned(self):
self.assertContains(response, "Banned in auth!", status_code=403)


def test_request(url):
def create_request(url):
request = RequestFactory().get(url)
request.cache_versions = get_cache_versions()
request.settings = DynamicSettings(request.cache_versions)
Expand All @@ -90,8 +90,8 @@ def test_request(url):
@override_settings(ROOT_URLCONF='misago.core.testproject.urlswitherrorhandlers')
class CustomErrorPagesTests(TestCase):
def setUp(self):
self.misago_request = test_request(reverse('misago:index'))
self.site_request = test_request(reverse('raise-403'))
self.misago_request = create_request(reverse('misago:index'))
self.site_request = create_request(reverse('raise-403'))

def test_shared_403_decorator(self):
"""shared_403_decorator calls correct error handler"""
Expand Down
6 changes: 3 additions & 3 deletions misago/core/tests/test_exceptionhandler_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from misago.core.middleware import ExceptionHandlerMiddleware


def test_request():
def create_request():
request = RequestFactory().get(reverse('misago:index'))
request.cache_versions = get_cache_versions()
request.settings = DynamicSettings(request.cache_versions)
Expand All @@ -28,10 +28,10 @@ def test_middleware_returns_response_for_supported_exception(self):
"""Middleware returns HttpResponse for supported exception"""
middleware = ExceptionHandlerMiddleware()
exception = Http404()
assert middleware.process_exception(test_request(), exception)
assert middleware.process_exception(create_request(), exception)

def test_middleware_returns_none_for_non_supported_exception(self):
"""Middleware returns None for non-supported exception"""
middleware = ExceptionHandlerMiddleware()
exception = TypeError()
assert middleware.process_exception(test_request(), exception) is None
assert middleware.process_exception(create_request(), exception) is None
24 changes: 0 additions & 24 deletions misago/users/tests/test_commands.py

This file was deleted.

42 changes: 19 additions & 23 deletions misago/users/tests/test_createsuperuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,29 @@

from django.contrib.auth import get_user_model
from django.core.management import call_command
from django.test import TestCase

User = get_user_model()

UserModel = get_user_model()

def test_superuser_is_created_if_input_is_valid(db):
out = StringIO()

class CreateSuperuserTests(TestCase):
def test_valid_input_creates_superuser(self):
"""command creates superuser"""
out = StringIO()
call_command(
"createsuperuser",
interactive=False,
username="test",
email="test@example.com",
password="password",
stdout=out,
)

call_command(
"createsuperuser",
interactive=False,
username="joe",
email="joe@somewhere.org",
password="Pass.123",
stdout=out,
)
command_output = out.getvalue().splitlines()[-1].strip()
user = User.objects.order_by('-id')[:1][0]

new_user = UserModel.objects.order_by('-id')[:1][0]
assert command_output == (
"Superuser #%s has been created successfully." % user.pk
)

self.assertEqual(
out.getvalue().splitlines()[-1].strip(),
'Superuser #%s has been created successfully.' % new_user.pk,
)

self.assertEqual(new_user.username, 'joe')
self.assertEqual(new_user.email, 'joe@somewhere.org')
self.assertTrue(new_user.check_password("Pass.123"))
assert user.username == "test"
assert user.email == "test@example.com"
assert user.check_password("password")
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
DJANGO_SETTINGS_MODULE = devproject.test_settings
testpaths = misago
python_files = tests.py test_*.py *_tests.py
2 changes: 2 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ markdown<2.7
misago-social-auth-app-django
pillow<4.2
psycopg2-binary<2.8
pytest
pytest-django
pytz
requests<3
unidecode<1
12 changes: 11 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#
# pip-compile --output-file requirements.txt requirements.in
#
atomicwrites==1.2.1 # via pytest
attrs==18.2.0 # via pytest
beautifulsoup4==4.6.3
bleach==2.1.4
certifi==2018.10.15 # via requests
Expand All @@ -14,21 +16,29 @@ django-mptt==0.8.7
django==1.11.16
djangorestframework==3.6.4
faker==0.8.18
funcsigs==1.0.2 # via pytest
html5lib==0.999999999
idna==2.7 # via requests
ipaddress==1.0.22 # via faker
markdown==2.6.11
misago-social-auth-app-django==2.1.0
more-itertools==4.3.0 # via pytest
oauthlib==2.1.0 # via requests-oauthlib, social-auth-core
olefile==0.46 # via pillow
pathlib2==2.3.3 # via pytest, pytest-django
pillow==4.1.1
pluggy==0.8.0 # via pytest
psycopg2-binary==2.7.5
py==1.7.0 # via pytest
pyjwt==1.6.4 # via social-auth-core
pytest-django==3.4.4
pytest==4.0.2
python-dateutil==2.7.5 # via faker
pytz==2018.7
requests-oauthlib==1.0.0 # via social-auth-core
requests==2.20.0
six==1.11.0 # via bleach, faker, html5lib, misago-social-auth-app-django, python-dateutil, social-auth-core
scandir==1.9.0 # via pathlib2
six==1.11.0 # via bleach, faker, html5lib, misago-social-auth-app-django, more-itertools, pathlib2, pytest, python-dateutil, social-auth-core
social-auth-core==1.7.0 # via misago-social-auth-app-django
sqlparse==0.2.4 # via django-debug-toolbar
text-unidecode==1.2 # via faker
Expand Down
36 changes: 0 additions & 36 deletions runtests.py

This file was deleted.

1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
install_requires=REQUIREMENTS,
packages=find_packages(exclude=EXCLUDE_FROM_PACKAGES),
include_package_data=True,
test_suite="runtests.runtests",
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Web Environment',
Expand Down

0 comments on commit 8ade0d9

Please sign in to comment.