Skip to content
This repository has been archived by the owner on May 7, 2022. It is now read-only.

Commit

Permalink
nosetests! Compat breaking change. Switched all validator to not incl…
Browse files Browse the repository at this point in the history
…ude the Validator suffix
  • Loading branch information
icook committed Oct 20, 2013
1 parent e011abf commit d18350a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 72 deletions.
38 changes: 19 additions & 19 deletions src/yota/tests/test_form.py
Expand Up @@ -64,7 +64,7 @@ class TForm(yota.Form):

t = EntryNode()
_t_valid = yota.Check(
MinLengthValidator(5, message="Darn"), 't')
MinLength(5, message="Darn"), 't')

test = TForm()
assert(isinstance(test.start, EntryNode))
Expand Down Expand Up @@ -148,8 +148,8 @@ class BForm(yota.Form):
def test_blueprint_validators(self):
""" ensure events get transferred properly """
class TForm(yota.Form):
main = EntryNode(validators=MinLengthValidator(5))
other_name_val = Check(MinLengthValidator(10), "main")
main = EntryNode(validators=MinLength(5))
other_name_val = Check(MinLength(10), "main")

class BForm(yota.Form):
test4 = Blueprint(TForm)
Expand All @@ -164,7 +164,7 @@ class BForm(yota.Form):
def test_error_header(self):
""" tests the validate method use of success_header_generate """
class TForm(yota.Form):
t = EntryNode(validators=RequiredValidator())
t = EntryNode(validators=Required())

def error_header_generate(self, errors):
self.start.add_error({'message': 'This is a very specific error'})
Expand Down Expand Up @@ -210,14 +210,14 @@ def success_json_generate(self):
def test_validator_shorthand(self):
""" Properly test many flexible shorthands """
nl = [
MinLengthValidator(5),
(MinLengthValidator(5), ),
[MinLengthValidator(5), ],
MinLength(5),
(MinLength(5), ),
[MinLength(5), ],
[],
Check(MinLengthValidator(5), 't'),
[Check(MinLengthValidator(5), 't'), ],
[Check(MinLengthValidator(5), 't'), MinLengthValidator(5)],
(Check(MinLengthValidator(5)), MinLengthValidator(5)),
Check(MinLength(5), 't'),
[Check(MinLength(5), 't'), ],
[Check(MinLength(5), 't'), MinLength(5)],
(Check(MinLength(5)), MinLength(5)),
]
# Since we're going to resolve the Checks again, easier to duplicate
# them
Expand Down Expand Up @@ -292,9 +292,9 @@ class TForm(yota.Form):
def test_insert_validator(self):
""" insert functions test plus special cases """
test = yota.Form()
tch = Check(RequiredValidator(), 't')
tch2 = Check(MinLengthValidator(5), 't')
tch3 = Check(MaxLengthValidator(5), 't')
tch = Check(Required(), 't')
tch2 = Check(MinLength(5), 't')
tch3 = Check(MaxLength(5), 't')
self.assertRaises(TypeError, test.insert_validator, ' ')
test.insert_validator(tch)
assert(test._validation_list[0] is tch)
Expand Down Expand Up @@ -336,7 +336,7 @@ def test_json_validation(self):

class TForm(yota.Form):
t = EntryNode()
_t_valid = yota.Check(RequiredValidator(message="Darn"), 't')
_t_valid = yota.Check(Required(message="Darn"), 't')

test = TForm()
success, json = test.validate_json({'t': '', '_visited_names': '{"t": true}'},
Expand All @@ -349,7 +349,7 @@ def test_piecewise_submit(self):

class TForm(yota.Form):
t = EntryNode()
_t_valid = yota.Check(MinLengthValidator(5), 't')
_t_valid = yota.Check(MinLength(5), 't')

test = TForm()
success, json = test.validate_json(
Expand All @@ -365,7 +365,7 @@ def test_piecewise_novisit(self):
""" any non-visited nodes cause submission to block """
class TForm(yota.Form):
t = EntryNode()
_t_valid = yota.Check(MinLengthValidator(5), 't')
_t_valid = yota.Check(MinLength(5), 't')

test = TForm()
success, invalid = test._gen_validate(
Expand Down Expand Up @@ -411,7 +411,7 @@ def test_validate_reg(self):
class TForm(yota.Form):
t = EntryNode()
_t_valid = yota.Check(
MinLengthValidator(5, message="Darn"), 't')
MinLength(5, message="Darn"), 't')

test = TForm()
success, ret = test.validate({'t': 'adfasdfasdf'}, internal=True)
Expand All @@ -426,7 +426,7 @@ def test_non_blocking(self):
class TForm(yota.Form):
t = EntryNode()
_t_valid = yota.Check(
NonBlockingDummyValidator(), 't')
NonBlockingDummy(), 't')

test = TForm()
success, invalid = test._gen_validate({'t': 'toolong'}, internal=True)
Expand Down
2 changes: 1 addition & 1 deletion src/yota/tests/test_listeners.py
Expand Up @@ -62,7 +62,7 @@ class TForm(yota.Form):


class TForm(yota.Form):
test = EntryNode(validators=MinLengthValidator(5))
test = EntryNode(validators=MinLength(5))
event = Listener("validate_failure", test_func, "test")
test = TForm()
test.validate({'test': '1'})
Expand Down
2 changes: 1 addition & 1 deletion src/yota/tests/test_node_func.py
Expand Up @@ -125,7 +125,7 @@ def test_textarea_content(self):
""" textarea data gets passed back in correctly """
class TForm(yota.Form):
t = TextareaNode(rows='15', columns='20')
_t_long = Check(MinLengthValidator(5), 't')
_t_long = Check(MinLength(5), 't')
success, test = TForm(auto_start_close=False).validate_render({'t': 'test'})
bs = BeautifulSoup(test)
assert('test' in bs.findAll('textarea')[0].contents[0].strip())
10 changes: 5 additions & 5 deletions src/yota/tests/test_nodes.py
Expand Up @@ -54,20 +54,20 @@ def test_validate_class_attr(self):
# TODO: Needs to be reworked similar to the comprehensive test in Form
class TForm(yota.Form):
class MyNode(yota.nodes.EntryNode):
validators = MinLengthValidator(5, message="Darn")
validators = MinLength(5, message="Darn")
t = MyNode()

test = TForm()
test._parse_shorthand_validator(test.t)
assert(len(test._validation_list) > 0)
assert(isinstance(test._validation_list[0].callable,
MinLengthValidator))
MinLength))

# ensure that we can still add multiples through iterable types
class TForm2(yota.Form):
class MyNode(yota.nodes.EntryNode):
validators = [MinLengthValidator(5, message="Darn"),
MaxLengthValidator(5, message="Darn")]
validators = [MinLength(5, message="Darn"),
MaxLength(5, message="Darn")]
t = MyNode()

test = TForm2()
Expand Down Expand Up @@ -119,7 +119,7 @@ def test_data_resolver(self):
class TForm(yota.Form):
t = EntryNode()
_t_valid = yota.Check(
RequiredValidator(message="Darn"), target='t')
Required(message="Darn"), target='t')

test = TForm()
success = test._gen_validate({'t': 'testing'})
Expand Down
40 changes: 20 additions & 20 deletions src/yota/tests/test_validator.py
Expand Up @@ -28,17 +28,17 @@ def run_check(self, values, validator):

def test_unicode_validator(self):
""" make sure unicode strings don't break validators """
for val in [MinLengthValidator(5),
MaxLengthValidator(5),
RegexValidator(regex='^[a-z]*$'),
RequiredValidator(),
EmailValidator()]:
for val in [MinLength(5),
MaxLength(5),
Regex(regex='^[a-z]*$'),
Required(),
Email()]:
errors = self.run_check({'t': u"\u041f\u0440\u0438\u0432\u0435\u0442"}, val)


def test_min_required(self):
""" min validator testing, pos and neg """
meth = MinLengthValidator(5, message="Darn")
meth = MinLength(5, message="Darn")

errors = self.run_check({'t':'short'}, meth)
assert(len(errors) == 0)
Expand All @@ -47,7 +47,7 @@ def test_min_required(self):

def test_max_required(self):
""" max validator testing, pos and neg """
meth = MaxLengthValidator(5, message="Darn")
meth = MaxLength(5, message="Darn")

errors = self.run_check({'t':'shor'}, meth)
assert(len(errors) == 0)
Expand All @@ -56,7 +56,7 @@ def test_max_required(self):

def test_regex_valid(self):
""" regex validator testing, pos and neg """
meth = RegexValidator(regex='^[a-z]*$', message='darn')
meth = Regex(regex='^[a-z]*$', message='darn')

errors = self.run_check({'t':'asdlkfdfsljgdlkfj'}, meth)
assert(len(errors) == 0)
Expand All @@ -67,7 +67,7 @@ def test_regex_valid(self):

def test_url_valid(self):
""" regex validator testing, pos and neg """
meth = URLValidator(message='darn')
meth = URL(message='darn')

errors = self.run_check({'t':'http://google.com'}, meth)
assert(len(errors) == 0)
Expand All @@ -88,7 +88,7 @@ def test_url_valid(self):

def test_email(self):
""" email validator testing, all branches """
meth = EmailValidator(message="Darn")
meth = Email(message="Darn")

errors = self.run_check({'t': 'm@testing.com'}, meth)
assert(len(errors) == 0)
Expand All @@ -105,7 +105,7 @@ def test_email(self):

def test_minmax(self):
""" minmax validator testing, pos and neg """
meth = MinMaxValidator(2, 5, minmsg="Darn", maxmsg="Darn")
meth = MinMax(2, 5, minmsg="Darn", maxmsg="Darn")

errors = self.run_check({'t': 'ai'}, meth)
assert(len(errors) == 0)
Expand All @@ -116,14 +116,14 @@ def test_minmax(self):
errors = self.run_check({'t': 'asdfg'}, meth)
assert(len(errors) == 0)

meth = MinMaxValidator(2, 5)
meth = MinMax(2, 5)
errors = self.run_check({'t': 'aiadsflgkj'}, meth)
assert(len(errors) > 0)
assert("fewer" in errors[0].errors[0]['message'])

def test_password(self):
""" password validator testing, pos and neg """
meth = PasswordValidator()
meth = Password()

errors = self.run_check({'t': 'a'}, meth)
assert(len(errors) > 0)
Expand All @@ -143,7 +143,7 @@ def test_password(self):

def test_username(self):
""" username validator testing, pos and neg """
meth = UsernameValidator()
meth = Username()

errors = self.run_check({'t': 'a'}, meth)
assert(len(errors) > 0)
Expand All @@ -163,7 +163,7 @@ def test_username(self):

def test_integer(self):
""" integer validator testing, pos and neg """
meth = IntegerValidator(message="Darn")
meth = Integer(message="Darn")

errors = self.run_check({'t': '12'}, meth)
assert(len(errors) == 0)
Expand All @@ -174,7 +174,7 @@ def test_integer(self):

def test_matching(self):
""" matching validator """
meth = MatchingValidator(message="Darn")
meth = Matching(message="Darn")

errors = self.run_check({'t': 'toolong', 'b': 'notmatching'}, meth)
assert(len(errors) > 0)
Expand All @@ -183,7 +183,7 @@ def test_matching(self):

def test_strength(self):
""" password strength validator """
meth = PasswordStrengthValidator(message="Darn")
meth = PasswordStrength(message="Darn")

errors = self.run_check({'t': 'AA'}, meth)
assert('1' in errors[0].errors[0]['message'])
Expand All @@ -194,14 +194,14 @@ def test_strength(self):
errors = self.run_check({'t': 'SOme33ing%'}, meth)
assert('4' in errors[0].errors[0]['message'])

meth = PasswordStrengthValidator(message="Darn",
meth = PasswordStrength(message="Darn",
regex=["(?=.*[A-Z].*[A-Z])"])
errors = self.run_check({'t': 'SOme33ing%'}, meth)
assert('1' in errors[0].errors[0]['message'])

def test_required(self):
""" required validator """
meth = RequiredValidator(message="Darn")
meth = Required(message="Darn")

errors = self.run_check({'t': 'toolong'}, meth)
assert(len(errors) == 0)
Expand All @@ -214,7 +214,7 @@ def test_key_access_exception(self):
data """
class TForm(yota.Form):
t = EntryNode()
_t_valid = yota.Check(RequiredValidator(message="Darn"), 't')
_t_valid = yota.Check(Required(message="Darn"), 't')

test = TForm()
test.t._null_val = ['test']
Expand Down

0 comments on commit d18350a

Please sign in to comment.