-
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.
- Loading branch information
Showing
11 changed files
with
261 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# .coveragerc to control coverage.py | ||
[run] | ||
branch = True | ||
source = dj_web_rich_object | ||
omit = | ||
dj_web_rich_object/tests/* | ||
dj_web_rich_object/functional_tests* | ||
|
||
[report] | ||
# Regexes for lines to exclude from consideration | ||
exclude_lines = | ||
# Have to re-enable the standard pragma | ||
pragma: no cover | ||
noqa: | ||
|
||
# Don't complain about missing debug-only code: | ||
def __repr__ | ||
def __str__ | ||
if self\.debug | ||
|
||
# Don't complain if tests don't hit defensive assertion code: | ||
raise AssertionError | ||
raise NotImplementedError | ||
|
||
# Don't complain if non-runnable code isn't run: | ||
if 0: | ||
if __name__ == .__main__.: | ||
__all__ | ||
import | ||
deprecated_warning | ||
in_development_warning | ||
|
||
ignore_errors = True | ||
|
||
[html] | ||
directory = coverage_html_report |
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,40 @@ | ||
language: python | ||
|
||
python: | ||
- "2.7" | ||
|
||
env: | ||
matrix: | ||
- DJANGO=1.8 | ||
- DJANGO=1.9 | ||
- DJANGO=1.10 | ||
- DJANGO=master | ||
|
||
install: | ||
- TOX_ENV=py${TRAVIS_PYTHON_VERSION}-django${DJANGO} | ||
- pip install tox | ||
|
||
script: | ||
- tox -e $TOX_ENV | ||
|
||
after_success: | ||
- tox -e $TOX_ENV -- pip install coveralls | ||
- tox -e $TOX_ENV -- coveralls $COVERALLS_OPTION | ||
|
||
matrix: | ||
fast_finish: true | ||
include: | ||
- python: "2.7" | ||
env: ENV=lint | ||
before_script: TOX_ENV=lint | ||
after_success: true | ||
- python: "2.7" | ||
env: ENV=docs | ||
before_script: TOX_ENV=docs | ||
after_success: true | ||
- python: "2.7" | ||
env: ENV=functional | ||
before_script: TOX_ENV=functional | ||
install: pip install tox | ||
allow_failures: | ||
- env: ENV=docs |
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,30 @@ | ||
from django.test import TestCase | ||
from web_rich_object import functional_tests as utils | ||
from dj_web_rich_object import models | ||
|
||
|
||
def gen_test(url, wro_attrs): | ||
def func(self): | ||
wro = models.WebRichObject.objects.create_from_url(url) | ||
# Test attrs | ||
attrs = {k: getattr(wro, k) for k, v in wro_attrs.iteritems() if hasattr(wro, k)} | ||
expected_attrs = {k: v for k, v in wro_attrs.iteritems() if hasattr(wro, k)} | ||
self.assertEqual(attrs, expected_attrs) | ||
# Test widget | ||
widget = wro.get_widget() | ||
return func | ||
|
||
|
||
class MetaFunctionalTest(type): | ||
def __new__(mcls, name, bases, attrs): | ||
for url, wro_attrs in utils.TEST_URLS: | ||
func_name = 'test_' + utils.NOT_ALPHA_REG.sub('_', url) | ||
func_name = utils.UNDERSCORE_REG.sub('_', func_name)[:100] | ||
func = gen_test(url, wro_attrs) | ||
attrs[func_name] = func | ||
return type.__new__(mcls, name, bases, attrs) | ||
|
||
|
||
class FunctionalTest(TestCase): | ||
__metaclass__ = MetaFunctionalTest | ||
maxDiff = None |
This file was deleted.
Oops, something went wrong.
Empty file.
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,42 @@ | ||
""" | ||
Configuration and launcher for Django Web Rich Object tests. | ||
""" | ||
import os | ||
import tempfile | ||
import dj_database_url | ||
|
||
DEBUG = False | ||
|
||
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
TESTAPP_DIR = os.path.join(BASE_DIR, 'testapp/') | ||
|
||
ADMINS = ( | ||
('ham', 'foo@bar'), | ||
) | ||
ALLOWED_HOSTS = ['*'] | ||
MIDDLEWARE_CLASSES = () | ||
ROOT_URLCONF = 'dbbackup.tests.testapp.urls' | ||
SECRET_KEY = "it's a secret to everyone" | ||
SITE_ID = 1 | ||
MEDIA_ROOT = os.environ.get('MEDIA_ROOT') or tempfile.mkdtemp() | ||
INSTALLED_APPS = ( | ||
'dj_web_rich_object', | ||
) | ||
|
||
DATABASE = dj_database_url.config(default='sqlite:///%s' % | ||
tempfile.mktemp()) | ||
DATABASES = {'default': DATABASE} | ||
|
||
CACHES = { | ||
'default': { | ||
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', | ||
} | ||
} | ||
|
||
SERVER_EMAIL = 'wro@test.org' | ||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'APP_DIRS': True, | ||
}, | ||
] |
Empty file.
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,41 @@ | ||
from django.test import TestCase | ||
from web_rich_object.tests import utils | ||
from web_rich_object import api | ||
from dj_web_rich_object import models | ||
|
||
|
||
class WebRichObjectTest(TestCase, utils.BaseWebRichObjectTestCase): | ||
def test_create_from_url(self): | ||
base_wro = api.WebRichObject(self.url) | ||
wro = models.WebRichObject.objects.create_from_url(self.url) | ||
self.assertEqual(wro.title, base_wro.title) | ||
self.assertEqual(wro.url, base_wro.url) | ||
self.assertEqual(wro.base_url, base_wro.base_url) | ||
self.assertEqual(wro.site_name, base_wro.site_name) | ||
self.assertEqual(wro.image, base_wro.image) | ||
self.assertEqual(wro.type, base_wro.type) | ||
self.assertEqual(wro.subtype, base_wro.subtype) | ||
self.assertEqual(wro.description, base_wro.description) | ||
self.assertEqual(wro.author, base_wro.author) | ||
test_create_from_url.mock_attrs = { | ||
'return_value.read.return_value': '<html><meta property="og:title" content="foo"/></html>', | ||
'return_value.info.return_value.__dict__': utils.HTML_RESPONSE_INFO, | ||
} | ||
|
||
def test_create_or_update_from_url(self): | ||
models.WebRichObject.objects.create_from_url(self.url) | ||
models.WebRichObject.objects.create_or_update_from_url(self.url) | ||
self.assertEqual(models.WebRichObject.objects.count(), 1) | ||
test_create_or_update_from_url.mock_attrs = { | ||
'return_value.read.return_value': '', | ||
'return_value.info.return_value.__dict__': utils.UNKNOW_RESPONSE_INFO, | ||
} | ||
|
||
def test_get_widget(self): | ||
wro = models.WebRichObject.objects.create_from_url(self.url) | ||
widget = wro.get_widget() | ||
self.assertIsInstance(widget, str) | ||
test_get_widget.mock_attrs = { | ||
'return_value.read.return_value': '', | ||
'return_value.info.return_value.__dict__': utils.UNKNOW_RESPONSE_INFO, | ||
} |
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,6 @@ | ||
dj-database-url | ||
coverage | ||
xhtml2pdf==0.2b1 | ||
html5lib==1.0b8 | ||
mock | ||
coverage |
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,24 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
import django | ||
from django.conf import settings | ||
from django.core.management import execute_from_command_line | ||
|
||
|
||
def main(argv=None): | ||
os.environ['DJANGO_SETTINGS_MODULE'] = 'dj_web_rich_object.tests.settings' | ||
argv = argv or [] | ||
if len(argv) <= 1: | ||
from django.test.utils import get_runner | ||
if django.VERSION >= (1, 7): | ||
django.setup() | ||
TestRunner = get_runner(settings) | ||
test_runner = TestRunner() | ||
result = test_runner.run_tests(["dj_web_rich_object.tests"]) | ||
return result | ||
execute_from_command_line(argv) | ||
|
||
if __name__ == '__main__': | ||
sys.exit(bool(main(sys.argv))) |
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,42 @@ | ||
[tox] | ||
envlist = | ||
py{2.7,3.4,3.5,pypy,pypy3}-django{1.8,1.9,1.10,master}, | ||
lint, | ||
docs, | ||
functional | ||
|
||
[testenv] | ||
passenv = * | ||
basepython = | ||
py2.7: python2.7 | ||
py3.4: python3.4 | ||
py3.5: python3.5 | ||
pypypy: pypy | ||
pypypy3: pypy3 | ||
deps = | ||
-rrequirements-tests.txt | ||
django1.8: Django>=1.8,<1.9 | ||
django1.9: Django>=1.9,<1.10 | ||
django1.10: Django>=1.10,<1.11 | ||
djangomaster: https://github.com/django/django/archive/master.zip | ||
commands = {posargs:coverage run runtests.py} | ||
|
||
[testenv:lint] | ||
basepython = python | ||
deps = | ||
prospector | ||
commands = prospector dj_web_rich_object -0 | ||
|
||
[testenv:docs] | ||
basepython = python | ||
whitelist_externals=make | ||
deps = -rrequirements-docs.txt | ||
commands = make docs | ||
|
||
[testenv:functional] | ||
passenv = * | ||
deps = | ||
-rrequirements-tests.txt | ||
Django | ||
basepython = python | ||
commands = {posargs:coverage run runtests.py test dj_web_rich_object.functional_tests} |