Skip to content

Commit

Permalink
Fully migrated to Python 3. 100% test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Dart committed Apr 19, 2020
1 parent 364df9e commit 2599b6f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 14 deletions.
3 changes: 2 additions & 1 deletion formstorm/FormElement.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from itertools import chain
from django.db.models import Q
from six import text_type


class FormElement(object):
Expand All @@ -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

Expand Down
5 changes: 3 additions & 2 deletions formstorm/FormTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions tests/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[run]
branch = true
omit = fstest/wsgi.py, manage.py
source = .

[report]
show_missing = true
2 changes: 1 addition & 1 deletion tests/fstestapp/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
from django.apps import AppConfig


class Test2Config(AppConfig):
class FSTestAppConfig(AppConfig):
name = 'fstestapp'
9 changes: 0 additions & 9 deletions tests/fstestapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
9 changes: 9 additions & 0 deletions tests/fstestapp/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -49,3 +57,4 @@ def setUp(self):

def test_book_form(self):
self.theBookFormTest.run()

2 changes: 1 addition & 1 deletion tests/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down

0 comments on commit 2599b6f

Please sign in to comment.