Skip to content

Commit

Permalink
Merge pull request coagulant#44 from hovel/fix_tests
Browse files Browse the repository at this point in the history
fix tests
  • Loading branch information
GeyseR committed Dec 7, 2015
2 parents 3ac4b26 + 9074f55 commit 2afc81b
Show file tree
Hide file tree
Showing 26 changed files with 302 additions and 92 deletions.
72 changes: 66 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,70 @@
*.pyc
.coverage
.ve
.cache
reports
coverage.xml
nosetests.xml
pylint.out
distribute-*.tar.gz
docs/.*/
docs/.*/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Translations
#*.mo
#*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# PyCharm
.idea/

*.db
*.sqlite3
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
language: python
sudo: false
python:
- "2.7"
env:
- DJANGO="Django==1.7" DB=mysql
- DJANGO="Django==1.8" DB=mysql
- DJANGO="Django>=1.7,<1.8" DB=sqlite
- DJANGO="Django>=1.8,<1.9" DB=sqlite
- DJANGO="Django>=1.9,<1.10" DB=sqlite
install:
- export PYTHONPATH=./django_any/:$PYTHONPATH
- pip install -U $DJANGO
- pip install -r tests/requirements.pip --use-mirrors
- pip install -r tests/requirements.pip
script:
- python tests/manage.py test
- python tests/manage.py test django_any
7 changes: 3 additions & 4 deletions django_any/contrib/auth.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-
from django.contrib.auth.models import User, Permission, Group
from django_any import any_model
from django_any.models import any_model

def any_user(password=None, permissions=[], groups=[], **kwargs):
"""
Shortcut for creating Users
Permissions could be a list of permission names
If not specified, creates active, non superuser
If not specified, creates active, non superuser
and non staff user
"""

Expand All @@ -32,7 +32,6 @@ def any_user(password=None, permissions=[], groups=[], **kwargs):

if password:
user.set_password(password)

user.save()
return user

5 changes: 4 additions & 1 deletion django_any/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,10 @@ def any_genericipaddress_field(field, **kwargs):
raise Exception('Unexpected validators')

if protocol == 'ipv4':
return any_ipaddress_field(field)
if django.VERSION < (1, 9):
return any_ipaddress_field(field)
else:
return any_genericipaddress_field(field)
if protocol == 'ipv6':
nums = [str(xunit.any_string(hexdigits, min_length=4, max_length=4)) for _ in xrange(0, 8)]
return ":".join(nums)
Expand Down
24 changes: 15 additions & 9 deletions django_any/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8; mode: django -*-
from django.conf.urls.defaults import patterns, include
import django
from django.conf.urls import url
from django.contrib import admin
from django.contrib.auth.models import User
from django.test import TestCase
Expand Down Expand Up @@ -29,12 +30,17 @@ class TestForm(forms.Form):

return HttpResponse(template.render(context))


urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
(r'^view/', view),
)

if django.VERSION < (1, 9):
from django.conf.urls import patterns, include
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^view/', view),
)
else:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^view/', view),
]

class DjangoAnyClient(TestCase):
urls = 'django_any.tests.test_client'
Expand All @@ -43,7 +49,8 @@ def setUp(self):
self.client = Client()

def test_login_as_super_user(self):
self.assertTrue(self.client.login_as(is_superuser=True))
# TODO make test page which will not require is_staff like /admin
self.assertTrue(self.client.login_as(is_superuser=True, is_staff=True))

response = self.client.get('/admin/')
self.assertEquals(200, response.status_code)
Expand All @@ -59,4 +66,3 @@ def test_login_as_failed(self):
def test_post_any_data(self):
response = self.client.post_any_data('/view/')
self.assertRedirects(response, '/view/')

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.db import models
from django.contrib.auth.models import User
from django.test import TestCase
from django_any import any_model
from django_any.models import any_model
from django_any.contrib.auth import any_user


Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# -*- coding: utf-8; -*-
import django
from django.db import models
from django.test import TestCase
import datetime
from decimal import Decimal
from django_any.contrib.default import any_model_with_defaults
from django.db.models.fields import NOT_PROVIDED
from django.core.files.base import ContentFile
from django_any.tests.model_creation_simple import SimpleModel
from django_any.tests.test_model_creation_simple import SimpleModel


class SimpleModelWithDefaults(models.Model):
Expand All @@ -20,7 +21,10 @@ class SimpleModelWithDefaults(models.Model):
email_field = models.EmailField(default='admin@dev.null')
float_field = models.FloatField(default=0.7)
integer_field = models.IntegerField(default=42)
ip_field = models.IPAddressField(default='127.0.0.1')
if django.VERSION < (1, 9):
ip_field = models.IPAddressField(default='127.0.0.1')
else:
ip_field = models.GenericIPAddressField(default='127.0.0.1')
null_boolead_field = models.NullBooleanField(default=None)
positive_integer_field = models.PositiveIntegerField(default=4)
small_integer = models.PositiveSmallIntegerField(default=1)
Expand Down
2 changes: 1 addition & 1 deletion django_any/tests/test_custom_seed.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8; mode: django -*-
from django.db import models
from django.test import TestCase
from django_any import any_field
from django_any.models import any_field
from django_any.test import WithTestDataSeed, with_seed, without_random_seed


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
from django.test import TestCase
from django.db import models
from django_any import any_field
from django_any.models import any_field

class AttrChoices(TestCase):
def test_one_case_selection(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.core.exceptions import ValidationError
from django.db import models
from django.test import TestCase
from django_any import any_model
from django_any.models import any_model


class ModelWithConstraint(models.Model):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
"""
Create models will all fields with simply to generate values
"""
import django
from django.db import models
from django.test import TestCase
from django_any import any_model
from django_any.models import any_model

class SimpleModel(models.Model):
big_integer_field = models.BigIntegerField()
Expand All @@ -17,7 +18,10 @@ class SimpleModel(models.Model):
email_field = models.EmailField()
float_field = models.FloatField()
integer_field = models.IntegerField()
ip_field = models.IPAddressField()
if django.VERSION < (1, 9):
ip_field = models.IPAddressField()
else:
ip_field = models.GenericIPAddressField()
null_boolead_field = models.NullBooleanField()
positive_integer_field = models.PositiveIntegerField()
small_integer = models.PositiveSmallIntegerField()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
from django.db import models
from django.test import TestCase
from django_any import any_model
from django_any.models import any_model

class MySlugField(models.SlugField):
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"""
Test model creation with GenericForeignKey
"""
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.test import TestCase
from django_any import any_model
from django_any.models import any_model


class RelatedContentModel(models.Model):
Expand All @@ -19,7 +19,7 @@ class ModelWithGenericRelation(models.Model):
tag = models.SlugField()
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
content_object = GenericForeignKey('content_type', 'object_id')

class Meta:
app_label = 'django_any'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.core.exceptions import ValidationError
from django.db import models
from django.test import TestCase
from django_any import any_model
from django_any.models import any_model


def validate_even(value):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
from django.db import models
from django.test import TestCase
from django_any import any_model
from django_any.models import any_model

class ModelUploadToString(models.Model):
file_field = models.FileField(upload_to='sample_subdir')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
from django.db import models
from django.test import TestCase
from django_any import any_model
from django_any.models import any_model


class RelatedModel(models.Model):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
from django.db import models
from django.test import TestCase
from django_any import any_model
from django_any.models import any_model


class OneToOneRelated(models.Model):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.db import models
from django.db.models import Q
from django.test import TestCase
from django_any import any_model
from django_any.models import any_model


class QObjectRelated(models.Model):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8; mode: django -*-
from django.db import models
from django.test import TestCase
from django_any import any_model
from django_any.models import any_model


class Redefined(models.Model):
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import codecs
import os
from setuptools import setup
os.environ['DJANGO_SETTINGS_MODULE'] = "tests.settings"
os.environ['DJANGO_SETTINGS_MODULE'] = "testproject.settings"

read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read()

Expand Down Expand Up @@ -33,4 +33,3 @@
'Framework :: Django',
]
)

24 changes: 6 additions & 18 deletions tests/manage.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from os import path
import shutil, sys, subprocess
import os
import sys

PROJECT_ROOT = path.dirname(path.abspath(path.dirname(__file__)))

sys.path.insert(0, PROJECT_ROOT)
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings")

# run django
from django.core.management import execute_manager
try:
import tests.settings
except ImportError:
import sys
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory")
sys.exit(1)
from django.core.management import execute_from_command_line

if __name__ == "__main__":
if len(sys.argv) == 1:
sys.argv += ['test'] + list(tests.settings.PROJECT_APPS)
execute_manager(tests.settings)
execute_from_command_line(sys.argv)

0 comments on commit 2afc81b

Please sign in to comment.