Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a few model tests to demonstrate attribute behavior; use assertEq…
…uals to fit codebase style
  • Loading branch information
boydjj committed Feb 8, 2013
1 parent 6c3748d commit f4be5f7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
30 changes: 30 additions & 0 deletions tests/mock_django/models/tests.py
@@ -1,3 +1,4 @@
from mock import MagicMock
from mock_django.models import ModelMock
from unittest2 import TestCase

Expand All @@ -6,8 +7,37 @@ class Model(object):
id = '1'
pk = '2'

def foo(self):
pass

def bar(self):
return 'bar'


class ModelMockTestCase(TestCase):
def test_pk_alias(self):
mock = ModelMock(Model)
self.assertEquals(mock.id, mock.pk)

def test_only_model_attrs_exist(self):
"""
ModelMocks have only the members that the Model has.
"""
mock = ModelMock(Model)
self.assertRaises(AttributeError, lambda x: x.baz, mock)

def test_model_attrs_are_mocks(self):
"""
ModelMock members are Mocks, not the actual model members.
"""
mock = ModelMock(Model)
self.assertNotEquals(mock.bar(), 'bar')
self.assertIsInstance(mock, MagicMock)

def test_attrs_are_not_identical(self):
"""
Each member of a ModelMock is unique.
"""
mock = ModelMock(Model)
self.assertIsNot(mock.foo, mock.bar)
self.assertIsNot(mock.foo, mock.id)
12 changes: 6 additions & 6 deletions tests/mock_django/query/tests.py
Expand Up @@ -21,22 +21,22 @@ def test_qs_generator_inequality(self):
Each QuerySet-returning method's return value is unique.
"""
qs = QuerySetMock(None, 1, 2, 3)
self.assertNotEqual(qs.all(), qs.filter())
self.assertNotEqual(qs.filter(), qs.order_by())
self.assertNotEquals(qs.all(), qs.filter())
self.assertNotEquals(qs.filter(), qs.order_by())

def test_qs_yield_equality(self):
"""
The generators may not the same, but they do produce the same output.
The generators may not be the same, but they do produce the same output.
"""
qs = QuerySetMock(None, 1, 2, 3)
self.assertEqual(list(qs.all()), list(qs.filter()))
self.assertEquals(list(qs.all()), list(qs.filter()))

def test_qs_method_takes_arg(self):
"""
QS-returning methods are impotent, but they do take args.
"""
qs = QuerySetMock(None, 1, 2, 3)
self.assertEqual(list(qs.order_by('something')), [1, 2, 3])
self.assertEquals(list(qs.order_by('something')), [1, 2, 3])

def test_raises_exception_when_evaluated(self):
"""
Expand All @@ -55,7 +55,7 @@ def test_raises_exception_when_accessed(self):
# Test reserved methods
def test_count_is_scalar(self):
qs = QuerySetMock(None, 1, 2, 3)
self.assertEqual(qs.count(), 3)
self.assertEquals(qs.count(), 3)

def test_exists_is_boolean(self):
qs = QuerySetMock(None)
Expand Down

0 comments on commit f4be5f7

Please sign in to comment.