forked from pythonindia/junction
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test): add test setup using py.test
- refractor settings to be top-level module. - make junction as top level module, changes imports to be more explicit - add py.test fixtures - client - divide the tests into `integration` and `unit` with corresponding folders - add basic url integration test. Breaking: - location of wsgi is changed from `junction.junction.wsgi` to `wsgi`, this should be taken care while deployment in production. - `manage.py` lives on the top-level, instead of i level deep.
- Loading branch information
Saurabh Kumar
committed
Jan 6, 2015
1 parent
48a66f4
commit 351073a
Showing
28 changed files
with
260 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[pytest] | ||
DJANGO_SETTINGS_MODULE = settings | ||
python_paths = . | ||
norecursedirs = .tox .git */migrations/* */static/* docs venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import print_function | ||
|
||
# Standard Library | ||
import sys | ||
|
||
if "test" in sys.argv: | ||
print("\033[1;91mNo django tests.\033[0m") | ||
print("Try: \033[1;33mpy.test\033[0m") | ||
sys.exit(0) | ||
|
||
from .common import * # noqa | ||
|
||
try: | ||
from .dev import * # noqa | ||
from .prod import * # noqa | ||
except ImportError: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# -*- coding: utf-8 -*- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# -*- coding: utf-8 -*- | ||
# Standard Library | ||
import os | ||
|
||
# Third Party Stuff | ||
import django | ||
# import pytest | ||
|
||
from .fixtures import * # noqa | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") | ||
|
||
|
||
def pytest_configure(config): | ||
django.setup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# -*- coding: utf-8 -*- | ||
# Standard Library | ||
import functools | ||
|
||
# Third Party Stuff | ||
import mock | ||
import pytest | ||
|
||
|
||
class Object: | ||
pass | ||
|
||
|
||
@pytest.fixture | ||
def object(): | ||
return Object() | ||
|
||
|
||
class PartialMethodCaller: | ||
def __init__(self, obj, **partial_params): | ||
self.obj = obj | ||
self.partial_params = partial_params | ||
|
||
def __getattr__(self, name): | ||
return functools.partial(getattr(self.obj, name), **self.partial_params) | ||
|
||
|
||
@pytest.fixture | ||
def client(): | ||
from django.test.client import Client | ||
|
||
class _Client(Client): | ||
def login(self, user=None, backend="django.contrib.auth.backends.ModelBackend", **credentials): | ||
if user is None: | ||
return super(_Client, self).login(**credentials) | ||
|
||
with mock.patch('django.contrib.auth.authenticate') as authenticate: | ||
user.backend = backend | ||
authenticate.return_value = user | ||
return super(_Client, self).login(**credentials) | ||
|
||
@property | ||
def json(self): | ||
return PartialMethodCaller(obj=self, content_type='application/json;charset="utf-8"') | ||
|
||
return _Client() | ||
|
||
|
||
@pytest.fixture | ||
def outbox(): | ||
from django.core import mail | ||
|
||
return mail.outbox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# -*- coding: utf-8 -*- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pytest | ||
from django.core.urlresolvers import reverse | ||
|
||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
def test_public_urls(client): | ||
|
||
public_urls = [ | ||
reverse('pages:homepage'), | ||
'/nimda/login/', | ||
] | ||
|
||
for url in public_urls: | ||
response = client.get(url) | ||
assert response.status_code == 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# -*- coding: utf-8 -*- |
Oops, something went wrong.