diff --git a/armstrong/core/arm_wells/tests/_utils.py b/armstrong/core/arm_wells/tests/_utils.py index fed735e..76cd1fd 100644 --- a/armstrong/core/arm_wells/tests/_utils.py +++ b/armstrong/core/arm_wells/tests/_utils.py @@ -1,12 +1,12 @@ import random -from django.test import TestCase as DjangoTestCase -from django.test.client import RequestFactory - +from armstrong.dev.tests.utils.base import ArmstrongTestCase from .arm_wells_support.models import Story, StoryChild, Image -from ..models import Node -from ..models import Well -from ..models import WellType +from ..models import WellType, Well, Node + + +class TestCase(ArmstrongTestCase): + pass def generate_random_image(): @@ -52,15 +52,3 @@ def generate_random_welltype(): title = "Random Well %d" % r slug = "random-well-%d" % r return WellType.objects.create(title=title, slug=slug) - - -class TestCase(DjangoTestCase): - def setUp(self): - self.factory = RequestFactory() - - def assertInContext(self, var_name, other, template_or_context): - # TODO: support passing in a straight "context" (i.e., dict) - context = template_or_context.context_data - self.assertTrue(var_name in context, - msg="`%s` not in provided context" % var_name) - self.assertEqual(context[var_name], other) diff --git a/armstrong/core/arm_wells/tests/arm_wells_support/models.py b/armstrong/core/arm_wells/tests/arm_wells_support/models.py index a568c3e..071ec92 100644 --- a/armstrong/core/arm_wells/tests/arm_wells_support/models.py +++ b/armstrong/core/arm_wells/tests/arm_wells_support/models.py @@ -2,8 +2,10 @@ from django.contrib.contenttypes import generic from django.contrib.contenttypes.models import ContentType + class Content(models.Model): title = models.CharField(max_length=100) + def __unicode__(self): return self.title diff --git a/armstrong/core/arm_wells/tests/arm_wells_support/tests.py b/armstrong/core/arm_wells/tests/arm_wells_support/tests.py index ec40b78..244c642 100644 --- a/armstrong/core/arm_wells/tests/arm_wells_support/tests.py +++ b/armstrong/core/arm_wells/tests/arm_wells_support/tests.py @@ -10,4 +10,4 @@ def test_uses_title_when_converted_to_string(self): title = "Some Random Title %d" % random.randint(100, 200) story = Story(title=title) - self.assertEqual(title, str(story)) + self.assertEqual(title, str(story), msg="sanity check") diff --git a/armstrong/core/arm_wells/tests/managers.py b/armstrong/core/arm_wells/tests/managers.py index cb98e8c..d95c90b 100644 --- a/armstrong/core/arm_wells/tests/managers.py +++ b/armstrong/core/arm_wells/tests/managers.py @@ -2,8 +2,7 @@ from ._utils import TestCase -from ..models import Well -from ..models import WellType +from ..models import WellType, Well class WellManagerTestCase(TestCase): diff --git a/armstrong/core/arm_wells/tests/models.py b/armstrong/core/arm_wells/tests/models.py index fa71217..41cf20e 100644 --- a/armstrong/core/arm_wells/tests/models.py +++ b/armstrong/core/arm_wells/tests/models.py @@ -110,7 +110,7 @@ def test_well_supports_indexing(self): for node in well.nodes.all(): self.assertEqual(node.content_object, well.items[i]) i = i + 1 - self.assertRaises(IndexError, lambda:well.items[i]) + self.assertRaises(IndexError, lambda: well.items[i]) def test_well_supports_indexing_with_merged_queryset(self): number_of_stories = random.randint(1, 5) @@ -135,7 +135,7 @@ def test_well_supports_indexing_with_merged_queryset(self): continue self.assertEqual(story, well.items[i]) i = i + 1 - self.assertRaises(IndexError, lambda:well.items[i]) + self.assertRaises(IndexError, lambda: well.items[i]) class NodeTestCase(TestCase): diff --git a/armstrong/core/arm_wells/tests/query.py b/armstrong/core/arm_wells/tests/query.py index ce3f33e..4cd564a 100644 --- a/armstrong/core/arm_wells/tests/query.py +++ b/armstrong/core/arm_wells/tests/query.py @@ -1,12 +1,11 @@ from django.core.paginator import Paginator import random -from .arm_wells_support.models import Image, Story -from ._utils import (add_n_random_stories_to_well, add_n_random_images_to_well, - generate_random_image, generate_random_story, generate_random_well, - TestCase) - -from ..models import Node +from .arm_wells_support.models import Story +from ._utils import (TestCase, + add_n_random_stories_to_well, + generate_random_story, + generate_random_well) class SimpleMergedNodesAndQuerySetTests(TestCase): @@ -18,7 +17,7 @@ def test_merge_when_sliced_across_the_well_content_with_slice_object(self): add_n_random_stories_to_well(2, well) queryset = well.merge_with(Story.objects.all()) - sliced = [a for a in queryset[slice(1,3)]] + sliced = [a for a in queryset[slice(1, 3)]] self.assertEqual(2, len(sliced)) def test_merges_correctly_when_sliced_across_the_well_content(self): diff --git a/armstrong/core/arm_wells/tests/querysets.py b/armstrong/core/arm_wells/tests/querysets.py index 8a97c35..119ba0b 100644 --- a/armstrong/core/arm_wells/tests/querysets.py +++ b/armstrong/core/arm_wells/tests/querysets.py @@ -1,10 +1,12 @@ -from django.core.paginator import Paginator import random from .arm_wells_support.models import * -from ._utils import (add_n_random_stories_to_well, add_n_random_images_to_well, - generate_random_image, generate_random_story, generate_random_well, - TestCase) +from ._utils import (TestCase, + add_n_random_stories_to_well, + add_n_random_images_to_well, + generate_random_image, + generate_random_story, + generate_random_well) from ..querysets import (GenericForeignKeyQuerySet, MergeQuerySet, FilterException) @@ -24,10 +26,16 @@ def setUp(self): for i in range(self.number_of_extra_stories): self.extra_stories.append(generate_random_story()) + def test_raises_NotImplementedError_on_all(self): + gfk_qs = GenericForeignKeyQuerySet(self.well.nodes.all()\ + .select_related()) + with self.assertRaises(NotImplementedError): + gfk_qs.all() + def test_raises_NotImplementedError_on_exclude(self): + gfk_qs = GenericForeignKeyQuerySet(self.well.nodes.all()\ + .select_related()) with self.assertRaises(NotImplementedError): - gfk_qs = GenericForeignKeyQuerySet(self.well.nodes.all()\ - .select_related()) gfk_qs.exclude() def test_raises_NotImplementedError_on_misc_functions(self): @@ -50,7 +58,6 @@ def test_raises_AttributeError_on_unknown_attribute(self): with self.assertRaises(AttributeError): getattr(gfk_qs, "unknown_and_unknowable") - def test_gathers_all_nodes_of_one_type_with_two_queries(self): gfk_qs = GenericForeignKeyQuerySet(self.well.nodes.all()\ .select_related()) @@ -104,7 +111,7 @@ def test_does_not_ignore_same_ids_in_different_types(self): self.assertEqual(2, len(queryset)) def test_non_standard_node(self): - num_nodes = random.randint(3,5) + num_nodes = random.randint(3, 5) for i in range(num_nodes): OddNode.objects.create(baz=generate_random_story()) gfk_qs = GenericForeignKeyQuerySet( @@ -116,14 +123,14 @@ def test_non_standard_node(self): self.assertEqual(obj.__class__, Story) def test_non_standard_node_failure(self): - num_nodes = random.randint(3,5) + num_nodes = random.randint(3, 5) for i in range(num_nodes): OddNode.objects.create(baz=generate_random_story()) with self.assertRaises(ValueError): - gfk_qs = GenericForeignKeyQuerySet( - OddNode.objects.all().select_related(), - gfk='bad_field_name' - ) + GenericForeignKeyQuerySet( + OddNode.objects.all().select_related(), + gfk='bad_field_name' + ) def test_works_with_duplicate_nodes(self): well = generate_random_well() @@ -162,7 +169,8 @@ def test_non_empty_filter(self): queryset = well.items with self.assertRaises(FilterException): - self.assertEqual(3, len(queryset.filter(title__in=['foo','bar']))) + self.assertEqual(3, len(queryset.filter(title__in=['foo', 'bar']))) + class MergeQuerySetTestCase(TestCase): def setUp(self): @@ -178,9 +186,14 @@ def setUp(self): generate_random_image() self.qs_b = Image.objects.all() + def test_raises_NotImplementedError_on_all(self): + merge_qs = MergeQuerySet(self.qs_a, self.qs_b) + with self.assertRaises(NotImplementedError): + merge_qs.all() + def test_raises_NotImplementedError_on_exclude(self): + merge_qs = MergeQuerySet(self.qs_a, self.qs_b) with self.assertRaises(NotImplementedError): - merge_qs = MergeQuerySet(self.qs_a, self.qs_b) merge_qs.exclude() def test_raises_NotImplementedError_on_misc_functions(self): diff --git a/armstrong/core/arm_wells/tests/views.py b/armstrong/core/arm_wells/tests/views.py index 26ed240..4c5f0e7 100644 --- a/armstrong/core/arm_wells/tests/views.py +++ b/armstrong/core/arm_wells/tests/views.py @@ -1,29 +1,25 @@ +import random + from django.core.exceptions import ImproperlyConfigured -from django.db.models.query import QuerySet -from django.http import HttpRequest from django.test.client import RequestFactory -import fudge -import random from .arm_wells_support.models import Story -from ._utils import add_n_random_stories_to_well -from ._utils import generate_random_story -from ._utils import generate_random_well -from ._utils import TestCase +from ._utils import (TestCase, + add_n_random_stories_to_well, + generate_random_story, + generate_random_well) + +from ..views import SimpleWellView, QuerySetBackedWellView -from ..views import SimpleWellView -from ..views import QuerySetBackedWellView +class SimpleWellViewTest(TestCase): + view_class = SimpleWellView -class WellViewTestCase(TestCase): def setUp(self): - super(WellViewTestCase, self).setUp() + super(SimpleWellViewTest, self).setUp() + self.factory = RequestFactory() self.well = generate_random_well() - -class SimpleWellViewTest(WellViewTestCase): - view_class = SimpleWellView - def default_kwargs(self): return { "template_name": "index.html", diff --git a/requirements/base.txt b/requirements/base.txt deleted file mode 100644 index 277b7f2..0000000 --- a/requirements/base.txt +++ /dev/null @@ -1,3 +0,0 @@ -django>=1.3 -django-reversion==1.3.3 -armstrong.hatband diff --git a/requirements/dev.txt b/requirements/dev.txt index e42bd55..e2c883d 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,2 +1 @@ --r ./base.txt -armstrong.dev>=1.4 +armstrong.dev>=1.11.0