summaryrefslogtreecommitdiff
path: root/ishtar_common/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r--ishtar_common/tests.py45
1 files changed, 31 insertions, 14 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index a91a0ba58..eca722670 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -34,7 +34,7 @@ from django.db import connection, transaction
from django.template.defaultfilters import slugify
from django.test import TestCase as BaseTestCase
from django.test.client import Client
-from django.test.simple import DjangoTestSuiteRunner
+from django.test.runner import DiscoverRunner
from ishtar_common import models
from ishtar_common import forms_common
@@ -72,14 +72,22 @@ class OOOGenerationTest(TestCase):
def create_superuser():
username = 'username4277'
password = 'dcbqj756456!@%'
+ q = User.objects.filter(username=username)
+ if q.count():
+ return username, password, q.all()[0]
user = User.objects.create_superuser(username, "nomail@nomail.com",
password)
+ user.set_password(password)
+ user.save()
return username, password, user
def create_user():
username = 'username678'
- password = 'dcbqj756456!@%'
+ password = 'dcbqj756aaa456!@%'
+ q = User.objects.filter(username=username)
+ if q.count():
+ return username, password, q.all()[0]
user = User.objects.create_user(username, email="nomail2@nomail.com")
user.set_password(password)
user.save()
@@ -91,10 +99,9 @@ class TestCase(BaseTestCase):
super(TestCase, self)._pre_setup()
if settings.USE_SPATIALITE_FOR_TESTS:
return
- c = connection.cursor()
- for view in [CRBulkView, FirstBaseFindView, BFBulkView, FBulkView]:
- c.execute(view.CREATE_SQL)
- transaction.commit_unless_managed()
+ with connection.cursor() as c:
+ for view in [CRBulkView, FirstBaseFindView, BFBulkView, FBulkView]:
+ c.execute(view.CREATE_SQL)
class CommandsTestCase(TestCase):
@@ -149,15 +156,15 @@ class WizardTestFormData(object):
test(test_object, final_step_response)
-class ManagedModelTestRunner(DjangoTestSuiteRunner):
+class ManagedModelTestRunner(DiscoverRunner):
"""
Test runner that automatically makes all unmanaged models in your Django
project managed for the duration of the test run, so that one doesn't need
to execute the SQL manually to create them.
"""
def setup_test_environment(self, *args, **kwargs):
- from django.db.models.loading import get_models
- self.unmanaged_models = [m for m in get_models()
+ from django.apps import apps
+ self.unmanaged_models = [m for m in apps.get_models()
if not m._meta.managed]
for m in self.unmanaged_models:
m._meta.managed = True
@@ -295,8 +302,15 @@ class AccessControlTest(TestCase):
user, created = User.objects.get_or_create(username='myusername')
user.is_superuser = True
user.save()
- ishtar_user = models.IshtarUser.objects.get(username=user.username)
+ ishtar_user = models.IshtarUser.objects.get(
+ user_ptr__username='myusername')
self.assertIn(admin, ishtar_user.person.person_types.all())
+ user = ishtar_user.user_ptr
+ user.is_superuser = False
+ user.save()
+ ishtar_user = models.IshtarUser.objects.get(
+ user_ptr__username='myusername')
+ self.assertNotIn(admin, ishtar_user.person.person_types.all())
class AdminGenTypeTest(TestCase):
@@ -319,11 +333,14 @@ class AdminGenTypeTest(TestCase):
module_name = 'ishtar_common'
def setUp(self):
- password = 'mypassword'
- my_admin = User.objects.create_superuser(
- 'myuser', 'myemail@test.com', password)
+ self.password = 'mypassword'
+ self.username = "myuser"
+ user = User.objects.create_superuser(
+ self.username, 'myemail@test.com', self.password)
+ user.set_password(self.password)
+ user.save()
self.client = Client()
- self.client.login(username=my_admin.username, password=password)
+ self.client.login(username=self.username, password=self.password)
def test_listing_and_detail(self):
for model in self.models: