diff --git a/formstorm/FormElement.py b/formstorm/FormElement.py index abb7a8f..4c8063b 100644 --- a/formstorm/FormElement.py +++ b/formstorm/FormElement.py @@ -1,5 +1,6 @@ from itertools import chain from django.db.models import Q +from six import text_type class FormElement(object): @@ -22,7 +23,7 @@ def build_iterator(self, ref_model, is_e2e): if type(g) is Q: ref_object = ref_model.objects.get(g) if is_e2e: # If we're doing an e2e test, reference by name. - self.good[i] = unicode(ref_object) + self.good[i] = text_type(ref_object) else: self.good[i] = ref_object.pk diff --git a/formstorm/FormTest.py b/formstorm/FormTest.py index d29b2ef..f5a4037 100644 --- a/formstorm/FormTest.py +++ b/formstorm/FormTest.py @@ -21,11 +21,12 @@ def _build_elements(self): # Filter out this class's FormElement properties if type(getattr(self, e)) is FormElement: # If this field is a fk/m2m, get the model that it points to. + form_field = self.form._meta.model._meta.get_field(e) try: # Python 3 - ref_model = self.form._meta.model._meta.get_field(e).remote_field.model + ref_model = form_field.remote_field.model except AttributeError: try: - ref_model = self.form._meta.model._meta.get_field(e).rel.to + ref_model = form_field.rel.to except AttributeError: ref_model = None diff --git a/tests/.coveragerc b/tests/.coveragerc new file mode 100644 index 0000000..644a90f --- /dev/null +++ b/tests/.coveragerc @@ -0,0 +1,7 @@ +[run] +branch = true +omit = fstest/wsgi.py, manage.py +source = . + +[report] +show_missing = true diff --git a/tests/fstestapp/apps.py b/tests/fstestapp/apps.py index d0bcc28..b41b8c3 100644 --- a/tests/fstestapp/apps.py +++ b/tests/fstestapp/apps.py @@ -4,5 +4,5 @@ from django.apps import AppConfig -class Test2Config(AppConfig): +class FSTestAppConfig(AppConfig): name = 'fstestapp' diff --git a/tests/fstestapp/models.py b/tests/fstestapp/models.py index b25cb0d..f3a8699 100644 --- a/tests/fstestapp/models.py +++ b/tests/fstestapp/models.py @@ -4,16 +4,10 @@ class Author(models.Model): name = models.CharField(max_length=100) - def __unicode__(self): - return self.name - class Genre(models.Model): name = models.CharField(max_length=100) - def __unicode__(self): - return self.name - class Book(models.Model): title = models.CharField(max_length=100, unique=True) @@ -22,6 +16,3 @@ class Book(models.Model): is_fiction = models.BooleanField(default=False) pages = models.IntegerField(default=False) genre = models.ManyToManyField(Genre) - - def __unicode__(self): - return self.title diff --git a/tests/fstestapp/test.py b/tests/fstestapp/test.py index 8fb7517..5c12933 100644 --- a/tests/fstestapp/test.py +++ b/tests/fstestapp/test.py @@ -4,6 +4,14 @@ from django.test import TestCase from .models import Author, Genre from django.db.models import Q +from django.apps import apps +from fstestapp.apps import FSTestAppConfig + + +class AppConfigTest(TestCase): + def test_apps(self): + self.assertEqual(FSTestAppConfig.name, 'fstestapp') + self.assertEqual(apps.get_app_config('fstestapp').name, 'fstestapp') class BookFormTest(FormTest): @@ -49,3 +57,4 @@ def setUp(self): def test_book_form(self): self.theBookFormTest.run() + diff --git a/tests/manage.py b/tests/manage.py index a60314d..bb039c7 100755 --- a/tests/manage.py +++ b/tests/manage.py @@ -6,7 +6,7 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fstest.settings") try: from django.core.management import execute_from_command_line - except ImportError as exc: + except ImportError: raise ImportError( "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you "