Skip to content

Commit

Permalink
reduced unnecessary tests, added test for None
Browse files Browse the repository at this point in the history
  • Loading branch information
anxolerd committed Aug 3, 2015
1 parent 12d9fcb commit db63ccd
Showing 1 changed file with 27 additions and 49 deletions.
76 changes: 27 additions & 49 deletions project/tests/test_type_enum.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from unittest import TestCase
from project.lib.orm.types import TypeEnum
from project.models import User, PageBlock
from random import randint
from enum import IntEnum

Expand All @@ -10,6 +9,17 @@

class TestTypeEnumConversion(TestCase):

def setUp(self):
self.testing_intenum = IntEnum(
'Custom IntEnum',
{
'val_1': -1,
'val_2': 10,
'val_3': 11,
'val_4': -3,
},
)

def positive_bind_test(self, *, typeenum):
te = typeenum
for val in te._enum:
Expand All @@ -21,37 +31,9 @@ def positive_bind_test(self, *, typeenum):
val.value,
dialect=None,
)
self.assertEqual(processed_type, processed_int)
self.assertEqual(processed_type, val.value)
self.assertEqual(processed_int, val.value)

def test_positive_bind_role(self):
te = TypeEnum(User.ROLE)
self.positive_bind_test(
typeenum=te,
)

def test_positive_bind_blocktype(self):
te = TypeEnum(PageBlock.TYPE)
self.positive_bind_test(
typeenum=te,
)

def test_positive_custom(self):
ie = IntEnum(
'Custom IntEnum',
{
'val_1': -1,
'val_2': 10,
'val_3': 11,
'val_4': -3,
},
)
te = TypeEnum(ie)
self.positive_bind_test(
typeenum=te,
)

def negative_bind_test(self, *, typeenum):
te = typeenum # alias
while True:
Expand All @@ -64,29 +46,25 @@ def negative_bind_test(self, *, typeenum):
dialect=None,
)

def test_negative_bind_role(self):
te = TypeEnum(User.ROLE)
# run several times
for i in range(16):
self.negative_bind_test(typeenum=te)

def test_negative_bind_blocktype(self):
te = TypeEnum(PageBlock.TYPE)
# run several times
for i in range(16):
self.negative_bind_test(typeenum=te)
def test_positive_custom(self):
ie = self.testing_intenum
te = TypeEnum(ie)
self.positive_bind_test(
typeenum=te,
)

def test_negative_custom(self):
ie = IntEnum(
'Custom IntEnum',
{
'val_1': -1,
'val_2': 10,
'val_3': 11,
'val_4': -3,
},
)
ie = self.testing_intenum
te = TypeEnum(ie)
self.negative_bind_test(
typeenum=te,
)

def test_none_param(self):
ie = self.testing_intenum
te = TypeEnum(ie)
processed = te.process_bind_param(
None,
dialect=None,
)
self.assertIsNone(processed)

0 comments on commit db63ccd

Please sign in to comment.