From bfeb979a22235d17358984efff568c9b5e1df155 Mon Sep 17 00:00:00 2001 From: Jon Cotton Date: Mon, 27 Feb 2012 16:05:58 -0800 Subject: [PATCH 1/9] Add a test for all() on GFKQuerySet and MergeQuerySet. --- armstrong/core/arm_wells/tests/querysets.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/armstrong/core/arm_wells/tests/querysets.py b/armstrong/core/arm_wells/tests/querysets.py index 8a97c35..c75f2c3 100644 --- a/armstrong/core/arm_wells/tests/querysets.py +++ b/armstrong/core/arm_wells/tests/querysets.py @@ -24,10 +24,12 @@ def setUp(self): for i in range(self.number_of_extra_stories): self.extra_stories.append(generate_random_story()) - def test_raises_NotImplementedError_on_exclude(self): + def test_raises_NotImplementedError_on_all_and_exclude(self): + gfk_qs = GenericForeignKeyQuerySet(self.well.nodes.all()\ + .select_related()) + with self.assertRaises(NotImplementedError): + gfk_qs.all() 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 +52,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()) @@ -178,9 +179,11 @@ def setUp(self): generate_random_image() self.qs_b = Image.objects.all() - def test_raises_NotImplementedError_on_exclude(self): + def test_raises_NotImplementedError_on_all_and_exclude(self): + merge_qs = MergeQuerySet(self.qs_a, self.qs_b) + with self.assertRaises(NotImplementedError): + merge_qs.all() with self.assertRaises(NotImplementedError): - merge_qs = MergeQuerySet(self.qs_a, self.qs_b) merge_qs.exclude() def test_raises_NotImplementedError_on_misc_functions(self): From 7b173b8548fd7872a4026c23387e84aea002df43 Mon Sep 17 00:00:00 2001 From: Jon Cotton Date: Fri, 9 Mar 2012 13:54:57 -0800 Subject: [PATCH 2/9] Clean up _utils.TestCase. - make it use the base ArmstrongTestCase - move the setUp() and assertInContext() methods out of the base class and into the class they are used in - remove an unnecessary WellViewTestCase class --- armstrong/core/arm_wells/tests/_utils.py | 24 +++++-------------- .../tests/arm_wells_support/tests.py | 3 +-- armstrong/core/arm_wells/tests/views.py | 18 +++++++++----- 3 files changed, 19 insertions(+), 26 deletions(-) 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/tests.py b/armstrong/core/arm_wells/tests/arm_wells_support/tests.py index ec40b78..f6bc777 100644 --- a/armstrong/core/arm_wells/tests/arm_wells_support/tests.py +++ b/armstrong/core/arm_wells/tests/arm_wells_support/tests.py @@ -1,7 +1,6 @@ import random -from django.test import TestCase - +from .._utils import TestCase from .models import Story diff --git a/armstrong/core/arm_wells/tests/views.py b/armstrong/core/arm_wells/tests/views.py index 26ed240..e2ea6c8 100644 --- a/armstrong/core/arm_wells/tests/views.py +++ b/armstrong/core/arm_wells/tests/views.py @@ -15,21 +15,27 @@ from ..views import QuerySetBackedWellView -class WellViewTestCase(TestCase): +class SimpleWellViewTest(TestCase): + view_class = SimpleWellView + 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", "well_title": self.well.title, } + 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) + def test_raises_exception_without_template_name_param(self): kwargs = self.default_kwargs() del kwargs["template_name"] From eeddab11a076ae3abd99fae2ca9ab13057dad670 Mon Sep 17 00:00:00 2001 From: Jon Cotton Date: Fri, 9 Mar 2012 13:58:14 -0800 Subject: [PATCH 3/9] Tidy imports. Remove unused imports. Some PEP8 spacing. --- .../tests/arm_wells_support/models.py | 2 ++ armstrong/core/arm_wells/tests/managers.py | 4 +-- armstrong/core/arm_wells/tests/models.py | 4 +-- armstrong/core/arm_wells/tests/query.py | 13 +++++----- armstrong/core/arm_wells/tests/querysets.py | 25 +++++++++++-------- armstrong/core/arm_wells/tests/views.py | 17 ++++++------- 6 files changed, 32 insertions(+), 33 deletions(-) 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/managers.py b/armstrong/core/arm_wells/tests/managers.py index cb98e8c..ecee387 100644 --- a/armstrong/core/arm_wells/tests/managers.py +++ b/armstrong/core/arm_wells/tests/managers.py @@ -1,9 +1,7 @@ import datetime 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 c75f2c3..37e1082 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) @@ -105,7 +107,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( @@ -117,14 +119,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() @@ -163,7 +165,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): diff --git a/armstrong/core/arm_wells/tests/views.py b/armstrong/core/arm_wells/tests/views.py index e2ea6c8..490ed64 100644 --- a/armstrong/core/arm_wells/tests/views.py +++ b/armstrong/core/arm_wells/tests/views.py @@ -1,18 +1,15 @@ +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 -from ..views import QuerySetBackedWellView +from ..views import SimpleWellView, QuerySetBackedWellView class SimpleWellViewTest(TestCase): From 099b2662a74e76ae9eed55d00042e1e70290aad3 Mon Sep 17 00:00:00 2001 From: Jon Cotton Date: Fri, 9 Mar 2012 14:01:41 -0800 Subject: [PATCH 4/9] Include a sanity test that was orphaned. --- armstrong/core/arm_wells/tests/__init__.py | 1 + armstrong/core/arm_wells/tests/arm_wells_support/tests.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/armstrong/core/arm_wells/tests/__init__.py b/armstrong/core/arm_wells/tests/__init__.py index 755a0ce..ff10c31 100644 --- a/armstrong/core/arm_wells/tests/__init__.py +++ b/armstrong/core/arm_wells/tests/__init__.py @@ -3,3 +3,4 @@ from .query import * from .querysets import * from .views import * +from .arm_wells_support.tests import * 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 f6bc777..fd32173 100644 --- a/armstrong/core/arm_wells/tests/arm_wells_support/tests.py +++ b/armstrong/core/arm_wells/tests/arm_wells_support/tests.py @@ -9,4 +9,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") From 331b1ab7417644cae917da41fe7ebafac4265abb Mon Sep 17 00:00:00 2001 From: Jon Cotton Date: Mon, 12 Mar 2012 12:55:52 -0700 Subject: [PATCH 5/9] Feedback from the PR. Restoring significant import whitespace, using Django TestCase in support test, and leaving that support test out of the package testing. --- armstrong/core/arm_wells/tests/__init__.py | 1 - armstrong/core/arm_wells/tests/arm_wells_support/tests.py | 3 ++- armstrong/core/arm_wells/tests/managers.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/armstrong/core/arm_wells/tests/__init__.py b/armstrong/core/arm_wells/tests/__init__.py index ff10c31..755a0ce 100644 --- a/armstrong/core/arm_wells/tests/__init__.py +++ b/armstrong/core/arm_wells/tests/__init__.py @@ -3,4 +3,3 @@ from .query import * from .querysets import * from .views import * -from .arm_wells_support.tests import * 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 fd32173..244c642 100644 --- a/armstrong/core/arm_wells/tests/arm_wells_support/tests.py +++ b/armstrong/core/arm_wells/tests/arm_wells_support/tests.py @@ -1,6 +1,7 @@ import random -from .._utils import TestCase +from django.test import TestCase + from .models import Story diff --git a/armstrong/core/arm_wells/tests/managers.py b/armstrong/core/arm_wells/tests/managers.py index ecee387..d95c90b 100644 --- a/armstrong/core/arm_wells/tests/managers.py +++ b/armstrong/core/arm_wells/tests/managers.py @@ -1,6 +1,7 @@ import datetime from ._utils import TestCase + from ..models import WellType, Well From 0f81a07871a67c06a66cc1befdf7e672b0b24bc0 Mon Sep 17 00:00:00 2001 From: Jon Cotton Date: Mon, 12 Mar 2012 12:56:58 -0700 Subject: [PATCH 6/9] Moving `assertInContext` to armstrong.dev in armstrong.dev PR #9. --- armstrong/core/arm_wells/tests/views.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/armstrong/core/arm_wells/tests/views.py b/armstrong/core/arm_wells/tests/views.py index 490ed64..4c5f0e7 100644 --- a/armstrong/core/arm_wells/tests/views.py +++ b/armstrong/core/arm_wells/tests/views.py @@ -26,13 +26,6 @@ def default_kwargs(self): "well_title": self.well.title, } - 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) - def test_raises_exception_without_template_name_param(self): kwargs = self.default_kwargs() del kwargs["template_name"] From f0522308ca069ac109e1261119c411968581774a Mon Sep 17 00:00:00 2001 From: Jon Cotton Date: Tue, 13 Mar 2012 10:37:36 -0700 Subject: [PATCH 7/9] Updating required versions of `armstrong.dev` and `django-reversion`. `armstrong.dev` now has the `assertInContext` method. `django-reversion` should be at 1.4, same as the package.json file and same as armstrong.core.arm_context --- requirements/base.txt | 2 +- requirements/dev.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements/base.txt b/requirements/base.txt index 277b7f2..4d89a3c 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,3 +1,3 @@ django>=1.3 -django-reversion==1.3.3 +django-reversion==1.4 armstrong.hatband diff --git a/requirements/dev.txt b/requirements/dev.txt index e42bd55..4f413b0 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,2 +1,2 @@ -r ./base.txt -armstrong.dev>=1.4 +armstrong.dev>=1.11.0 From 70934ff72a7599654492944832a69f6408ff91a4 Mon Sep 17 00:00:00 2001 From: Jon Cotton Date: Tue, 13 Mar 2012 13:58:19 -0700 Subject: [PATCH 8/9] Separate tests for `all()` and `exclude()` --- armstrong/core/arm_wells/tests/querysets.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/armstrong/core/arm_wells/tests/querysets.py b/armstrong/core/arm_wells/tests/querysets.py index 37e1082..119ba0b 100644 --- a/armstrong/core/arm_wells/tests/querysets.py +++ b/armstrong/core/arm_wells/tests/querysets.py @@ -26,11 +26,15 @@ 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_and_exclude(self): + 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.exclude() @@ -182,10 +186,13 @@ def setUp(self): generate_random_image() self.qs_b = Image.objects.all() - def test_raises_NotImplementedError_on_all_and_exclude(self): + 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.exclude() From 5fde6e7e0f02fbe3e18d58a4acdad1c43e47a16b Mon Sep 17 00:00:00 2001 From: Jon Cotton Date: Tue, 13 Mar 2012 16:01:37 -0700 Subject: [PATCH 9/9] Removing the requirements/base.txt file. --- requirements/base.txt | 3 --- requirements/dev.txt | 1 - 2 files changed, 4 deletions(-) delete mode 100644 requirements/base.txt diff --git a/requirements/base.txt b/requirements/base.txt deleted file mode 100644 index 4d89a3c..0000000 --- a/requirements/base.txt +++ /dev/null @@ -1,3 +0,0 @@ -django>=1.3 -django-reversion==1.4 -armstrong.hatband diff --git a/requirements/dev.txt b/requirements/dev.txt index 4f413b0..e2c883d 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,2 +1 @@ --r ./base.txt armstrong.dev>=1.11.0