Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix unittest

  • Loading branch information...
commit f0c25e067e54a32e386b6a2db58fdaab2b753868 1 parent 54e5689
@ikeikeikeike authored
View
19 tests/base/tests/count.py
@@ -4,23 +4,26 @@
TestServerTestCase,
get_client
)
+from .utils import FixtureMixin
+
+
+class CountTestCase(FixtureMixin, TestServerTestCase):
-class CountTestCase(TestServerTestCase):
def setUp(self):
self.start_test_server()
self.client = get_client()
+ super(CountTestCase, self).setUp()
def tearDown(self):
self.stop_test_server()
def test_count1(self):
- num = self.client.inbox_message_many.objects.count()
+ num = self.client.message.objects.count()
self.assertTrue(-1 < num)
self.assertTrue(isinstance(num, int))
-# def test_count2(self):
-# # TODO: fixture
-# nums = self.client.inbox_message_many.objects.filter(id__in=xrange(0, 12))
-# num = nums.count()
-# assert 11 == num
-# assert isinstance(num, int)
+ def test_count2(self):
+ nums = self.client.message.objects.filter(id__in=xrange(0, 12))
+ num = nums.count()
+ assert 11 == num
+ assert isinstance(num, int)
View
5 tests/base/tests/exists.py
@@ -4,12 +4,15 @@
TestServerTestCase,
get_client
)
+from .utils import FixtureMixin
-class ExistsTestCase(TestServerTestCase):
+
+class ExistsTestCase(FixtureMixin, TestServerTestCase):
def setUp(self):
self.start_test_server()
self.client = get_client()
+ super(ExistsTestCase, self).setUp()
def tearDown(self):
self.stop_test_server()
View
5 tests/base/tests/foreignkey.py
@@ -4,20 +4,21 @@
TestServerTestCase,
get_client
)
+from .utils import FixtureMixin
-class ForeignkeyTestCase(TestServerTestCase):
+class ForeignkeyTestCase(FixtureMixin, TestServerTestCase):
def setUp(self):
self.start_test_server()
self.client = get_client()
+ super(ForeignkeyTestCase, self).setUp()
def tearDown(self):
self.stop_test_server()
# TODO: input prepend data
def test_foreignkey1(self):
-
if 0 < self.client.inbox_message.objects.count():
self.assertTrue(self.client.inbox_message.objects.all()[0].message.id)
self.assertTrue(self.client.inbox_message.objects.all()[1].message.id)
View
4 tests/base/tests/latest.py
@@ -2,13 +2,15 @@
TestServerTestCase,
get_client
)
+from .utils import FixtureMixin
-class LatestTestCase(TestServerTestCase):
+class LatestTestCase(FixtureMixin, TestServerTestCase):
def setUp(self):
self.start_test_server()
self.client = get_client()
+ super(LatestTestCase, self).setUp()
def tearDown(self):
self.stop_test_server()
View
12 tests/base/tests/lazy.py
@@ -2,21 +2,21 @@
TestServerTestCase,
get_client
)
+from .utils import FixtureMixin
-class LazyTestCase(TestServerTestCase):
+class LazyTestCase(FixtureMixin, TestServerTestCase):
def setUp(self):
self.start_test_server()
self.client = get_client()
+ super(LazyTestCase, self).setUp()
def tearDown(self):
self.stop_test_server()
- # TODO: input prepend data
def test_lazy1(self):
fl = self.client.inbox_message_many.objects.filter()
- if 0 < len(fl):
- self.assertTrue(fl)
- for f in fl:
- self.assertTrue(f)
+ self.assertTrue(fl)
+ for f in fl:
+ self.assertTrue(f)
View
5 tests/base/tests/len.py
@@ -2,13 +2,15 @@
TestServerTestCase,
get_client
)
+from .utils import FixtureMixin
-class LenTestCase(TestServerTestCase):
+class LenTestCase(FixtureMixin, TestServerTestCase):
def setUp(self):
self.start_test_server()
self.client = get_client()
+ super(LenTestCase, self).setUp()
def tearDown(self):
self.stop_test_server()
@@ -17,7 +19,6 @@ def test_len1(self):
message = self.client.message.objects.all()
self.assertTrue(len(message) == self.client.message.objects.count())
-
def test_len2(self):
message = self.client.message.objects.all()
self.assertTrue(len(message) == self.client.message.objects.all().count())
View
4 tests/base/tests/many_to_many.py
@@ -18,6 +18,7 @@ def tearDown(self):
self.stop_test_server()
def test_many1(self):
+ assert False
for i in xrange(99, 110):
try:
many = self.client.inbox_message_many.objects.get(id=i)
@@ -27,6 +28,7 @@ def test_many1(self):
self.assertTrue(True)
def test_many2(self):
+ assert False
nums = xrange(99, 110)
for i, num in zip(self.client.inbox_message_many.objects.filter(id__in=nums), nums):
self.assertTrue(i.inbox_message)
@@ -34,6 +36,7 @@ def test_many2(self):
def test_many3(self):
+ assert False
nums = xrange(99, 102)
for i, num in zip(self.client.inbox_message_many.objects.filter(id__in=nums), nums):
self.assertTrue(i.inbox_message.all())
@@ -41,6 +44,7 @@ def test_many3(self):
def test_many4(self):
+ assert False
for i in self.client.inbox_message_many.objects.all():
self.assertTrue(i)
View
27 tests/base/tests/model.py
@@ -103,6 +103,24 @@ def test_save3(self):
for message in self.client.message.objects.filter(id__in=xrange(20, 33)):
self.assertTrue(message.subject == subject)
self.assertTrue(message.body == body)
+
+ def test_object_save1(self):
+ """ object save
+ """
+ for i in xrange(0, 12):
+ message = self.client.message()
+ message.subject = id_generator()
+ message.body = id_generator()
+ message.save()
+
+ inbox = self.client.inbox()
+ inbox.did = id_generator()
+ inbox.save()
+
+ inbox_message = self.client.inbox_message()
+ inbox_message.message = message
+ inbox_message.inbox = inbox
+ inbox_message.save() # TODO: save success
def test_save_rel1(self):
""" relation """
@@ -113,11 +131,10 @@ def test_save_rel1(self):
def test_save_many1(self):
""" many to many """
- # subject = ""
- # body = ""
- # message = self.client.inbox_message_many(inbox_message=inbox_message)
- # message.save()
-
+# inbox_message_many = self.client.inbox_message_many()
+# inbox_message_many.inbox_message = inbox_message
+# inbox_message_many.save()
+
def test_delete1(self):
subject = "subject delete 1"
body = "body delete 1"
View
18 tests/base/tests/paginator.py
@@ -3,6 +3,7 @@
TestServerTestCase,
get_client
)
+from .utils import id_generator
class PaginatorTestCase(TestServerTestCase):
@@ -10,6 +11,21 @@ class PaginatorTestCase(TestServerTestCase):
def setUp(self):
self.start_test_server()
self.client = get_client()
+ for i in xrange(0, 100):
+ message = self.client.message()
+ message.subject = id_generator()
+ message.body = id_generator()
+ message.save()
+
+ inbox = self.client.inbox()
+ inbox.did = id_generator()
+ inbox.save()
+
+ inbox_message = self.client.inbox_message()
+ inbox_message.message = message.resource_uri
+ inbox_message.inbox = inbox.resource_uri
+ inbox_message.save()
+
def tearDown(self):
self.stop_test_server()
@@ -17,7 +33,7 @@ def tearDown(self):
def test_paginator(self):
message = self.client.message.objects.all()
- p = Paginator(message, 10)
+ p = Paginator(message,25)
self.assertTrue(p.count)
self.assertTrue(p.num_pages)
self.assertTrue(p.page_range)
View
27 tests/base/tests/utils.py
@@ -1,5 +1,30 @@
import string
import random
+
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
- return ''.join(random.choice(chars) for x in range(size))
+ return ''.join(random.choice(chars) for x in range(size))
+
+
+class FixtureMixin(object):
+
+ def setUp(self):
+ super(FixtureMixin, self).setUp()
+ for i in xrange(0, 12):
+ message = self.client.message()
+ message.subject = id_generator()
+ message.body = id_generator()
+ message.save()
+
+ inbox = self.client.inbox()
+ inbox.did = id_generator()
+ inbox.save()
+
+ inbox_message = self.client.inbox_message()
+ inbox_message.message = message.resource_uri
+ inbox_message.inbox = inbox.resource_uri
+ inbox_message.save()
+
+# inbox_message_many = self.client.inbox_message_many()
+# inbox_message_many.inbox_message = inbox_message.resource_uri
+# inbox_message_many.save()
View
2  tox.ini
@@ -16,7 +16,7 @@ setenv =
deps =
pytest
django
- django-tastypie
+ git+git://github.com/toastdriven/django-tastypie.git
commands =
django-admin.py test base --settings=settings_base
Please sign in to comment.
Something went wrong with that request. Please try again.