def test_upper(): s = Schema() s.lower_case.upper() s.validate(_sample_data()) assert_true(s.valid) assert_equals(s.lower_case.result, 'I AM THE QUIET MOUSE')
def test_contains(): s = Schema() s.some_list.contains('bravo') s.some_other_list.contains('alpha', 'bravo') s.validate(test_data) assert_true(s.valid)
def test_contains(): s = Schema() s.some_list.contains('bravo') s.some_other_list.contains('alpha', 'bravo') s.validate(test_data) assert_true(s.valid)
def test_strip(): s = Schema() s.flanking_spaces.strip() s.validate(_sample_data()) assert_true(s.valid) assert_equals(s.flanking_spaces.result, 'everybody walk the dinosaur')
def test_range(): s = Schema() s.some_number.range() s.validate({'some_number': 4}) assert_true(s.valid) s = Schema() s.some_number.range(low=1) s.validate({'some_number': 0}) assert_false(s.valid) s.reset() s.validate({'some_number': 1}) assert_true(s.valid) s.reset() s.validate({'some_number': 2}) assert_true(s.valid) s = Schema() s.some_number.range(high=5) s.validate({'some_number': 6}) assert_false(s.valid) s.reset() s.validate({'some_number': 4}) assert_true(s.valid) s = Schema() s.some_number.range(low=2, high=3) s.validate({'some_number': 2}) assert_true(s.valid)
def test_lower(): s = Schema() s.upper_case.lower() s.validate(_sample_data()) assert_true(s.valid) assert_equals(s.upper_case.result, 'i am the rawrmachine')
def test_upper(): s = Schema() s.lower_case.upper() s.validate(_sample_data()) assert_true(s.valid) assert_equals(s.lower_case.result, 'I AM THE QUIET MOUSE')
def test_removespaces(): s = Schema() s.awkward_spaces.removespaces() s.validate(_sample_data()) assert_true(s.valid) assert_equals(s.awkward_spaces.result, 'openthedoorgetonthefloorrr')
def test_konval(): test_schema = { u'name': IsName(), u'email': IsEmailAddress(), u'age': konval.types.IsType(int) } success_data = { u'name': u'Peter M. Elias', u'email': u'*****@*****.**', u'age': 37 } result = konval.validate(test_schema, success_data) assert_true(result.is_valid()) fail_data = { u'name': 123, u'email': 1243, u'age': 'fourteen' } result = konval.validate(test_schema, fail_data) assert_false(result.is_valid()) assert_is_not_none(result.get_errors())
def test_strip(): s = Schema() s.flanking_spaces.strip() s.validate(_sample_data()) assert_true(s.valid) assert_equals(s.flanking_spaces.result, 'everybody walk the dinosaur')
def test_removespaces(): s = Schema() s.awkward_spaces.removespaces() s.validate(_sample_data()) assert_true(s.valid) assert_equals(s.awkward_spaces.result, 'openthedoorgetonthefloorrr')
def test_lower(): s = Schema() s.upper_case.lower() s.validate(_sample_data()) assert_true(s.valid) assert_equals(s.upper_case.result, 'i am the rawrmachine')
def test_boolean(): s = Schema(blank='all') s.true_value.boolean() s.false_value.boolean() s.validate(test_data) assert_true(s.valid) assert_true(s.true_value.result) assert_equals(s.false_value.result, False)
def test_zero(): s = Schema() s.some_number.zero() s.validate({'some_number': 1}) assert_false(s.valid) s.reset() s.validate({'some_number': 0}) assert_true(s.valid)
def test_equal(): s = Schema() s.some_number.equal(10) s.validate({'some_number': 11}) assert_false(s.valid) s.reset() s.validate({'some_number': 10}) assert_true(s.valid)
def test_minimum(): s = Schema() s.some_number.minimum(1) s.validate({'some_number': 0}) assert_false(s.valid) s.reset() s.validate({'some_number': 1}) assert_true(s.valid)
def test_drop_keys(): s = Schema() s.some_dict.drop_keys('one', 'two') s.validate(test_data) assert_true(s.valid) assert_equals(s.some_dict.result, {'red': 'fish', 'blue': 'fish'})
def test_drop_keys(): s = Schema() s.some_dict.drop_keys('one', 'two') s.validate(test_data) assert_true(s.valid) assert_equals(s.some_dict.result, {'red': 'fish', 'blue': 'fish'})
def test_constant(): s = Schema() s.some_cst_value.constant('blue apple') s.validate({'some_cst_value': 'Roger that'}) assert_true(s.valid) assert_equals(s.some_cst_value.result, 'blue apple')
def test_maximum(): s = Schema() s.some_number.maximum(5) s.validate({'some_number': 6}) assert_false(s.valid) s.reset() s.validate({'some_number': 5}) assert_true(s.valid)
def test_boolean(): s = Schema(blank='all') s.true_value.boolean() s.false_value.boolean() s.validate(test_data) assert_true(s.valid) assert_true(s.true_value.result) assert_equals(s.false_value.result, False)
def test_create(): @object_created.connect def create_fxn(cls, o, **kwargs): o.touched_by_signal = True o = CRUDMan.create() assert_true(o.touched_by_signal) assert_is_instance(o, CRUDMan)
def test_canonize(): s = Schema() s.noncanonical_string.canonize() s.validate(_sample_data()) assert_true(s.valid) assert_equals(s.noncanonical_string.result, u'there_is_nothing_canonical_aboutmeeeeee333_see?')
def test_canonize(): s = Schema() s.noncanonical_string.canonize() s.validate(_sample_data()) assert_true(s.valid) assert_equals(s.noncanonical_string.result, u'there_is_nothing_canonical_aboutmeeeeee333_see?')
def test_datetime(): s = Schema() s.valid_datetime.datetime() s.invalid_datetime.datetime() s.validate(test_data) assert_false(s.valid) assert_true(s.valid_datetime.valid) assert_false(s.invalid_datetime.valid)
def test_datetime(): s = Schema() s.valid_datetime.datetime() s.invalid_datetime.datetime() s.validate(test_data) assert_false(s.valid) assert_true(s.valid_datetime.valid) assert_false(s.invalid_datetime.valid)
def test_time_between(): s = Schema() s.my_birthday.date().time_between(date(1988, 1, 1), date.today()) s.long_time_ago.date(format='american_scientific').time_between(date.today(), date(2055, 1, 1)) s.validate(test_data) assert_false(s.valid) assert_true(s.my_birthday.valid) assert_false(s.long_time_ago.valid)
def test_numeric(): s = Schema() s.integer_value.numeric() s.float_value.numeric() s.validate(test_data) assert_true(s.valid) assert_is_instance(s.integer_value.result, int) assert_is_instance(s.float_value.result, float)
def test_numeric(): s = Schema() s.integer_value.numeric() s.float_value.numeric() s.validate(test_data) assert_true(s.valid) assert_is_instance(s.integer_value.result, int) assert_is_instance(s.float_value.result, float)
def test_time_between(): s = Schema() s.my_birthday.date().time_between(date(1988, 1, 1), date.today()) s.long_time_ago.date(format='american_scientific').time_between( date.today(), date(2055, 1, 1)) s.validate(test_data) assert_false(s.valid) assert_true(s.my_birthday.valid) assert_false(s.long_time_ago.valid)
def test_between(): s = Schema() s.some_number.between(5, 10) s.validate({'some_number': 5}) assert_false(s.valid) s.reset() s.validate({'some_number': 6}) assert_true(s.valid) s.reset() s.validate({'some_number': 10}) assert_false(s.valid)
def test_ipv4(): s = Schema() s.valid_ipv4.ipv4() s.invalid_ipv4.ipv4() s.invalid_ipv42.ipv4() s.validate(_sample_data()) assert_true(s.valid_ipv4.valid) assert_false(s.invalid_ipv4.valid) assert_false(s.invalid_ipv42.valid)
def test_nonblank(): s = Schema() s.random_string.nonblank() s.validate(_sample_data()) assert_true(s.valid) s = Schema() s.blank_string.nonblank() s.validate(_sample_data()) assert_false(s.valid)
def test_text(): s = Schema() s.random_string.text() s.validate(_sample_data()) assert_true(s.valid) s = Schema() s.actual_numbers.text() s.validate(_sample_data()) assert_false(s.valid)
def test_regex(): s = Schema() s.numeric_string.regex(r'\d') s.validate(_sample_data()) assert_true(s.valid) s = Schema() s.alpha_string.regex(r'\d') s.validate(_sample_data()) assert_false(s.valid)
def test_decimal(): s = Schema() s.decimal_value.decimal() s.not_decimal_value.decimal() s.string_value.decimal() s.validate(test_data) assert_false(s.valid) assert_true(s.decimal_value.valid) assert_true(s.not_decimal_value.valid) assert_false(s.string_value.valid)
def test_email(): s = Schema() s.valid_email.email() s.invalid_email.email() s.invalid_email2.email() s.invalid_email3.email() s.validate(_sample_data()) assert_true(s.valid_email.valid) assert_false(s.invalid_email.valid) assert_false(s.invalid_email2.valid) assert_false(s.invalid_email3.valid)
def test_nonblank(): s = Schema() s.random_string.nonblank() s.validate(_sample_data()) assert_true(s.valid) s = Schema() s.blank_string.nonblank() s.validate(_sample_data()) assert_false(s.valid)
def test_text(): s = Schema() s.random_string.text() s.validate(_sample_data()) assert_true(s.valid) s = Schema() s.actual_numbers.text() s.validate(_sample_data()) assert_false(s.valid)
def test_time_after(): s = Schema() s.my_birthday.date().time_after(date.today()) s.far_far_away.date(format='american_scientific').time_after(date.today()) s.long_time_ago.date(format='american_scientific').time_after(date.today()) s.validate(test_data) assert_false(s.valid) assert_false(s.my_birthday.valid) assert_true(s.far_far_away.valid) assert_false(s.long_time_ago.valid)
def test_decimal(): s = Schema() s.decimal_value.decimal() s.not_decimal_value.decimal() s.string_value.decimal() s.validate(test_data) assert_false(s.valid) assert_true(s.decimal_value.valid) assert_true(s.not_decimal_value.valid) assert_false(s.string_value.valid)
def test_regex(): s = Schema() s.numeric_string.regex(r'\d') s.validate(_sample_data()) assert_true(s.valid) s = Schema() s.alpha_string.regex(r'\d') s.validate(_sample_data()) assert_false(s.valid)
def test_watch_directory(): def _cleanup(path): for f in listdir(path): p = join(path, f) if isdir(p): rmtree(p) elif f != '.nothing': unlink(p) sample_template = '' sample_directory = dirname(realpath(__file__)) + '/sample/' watch_directory = sample_directory + 'watch/' render_directory = sample_directory + 'render/' template_directory = sample_directory + 'templates/' with open(template_directory + 'haml.tmpl', 'r') as f: sample_template = f.read() condition = Condition() p = Process(target=reloader.watch_directory, args=(watch_directory, render_directory, condition)) condition.acquire() p.start() condition.wait() try: with open(watch_directory + 'test.haml', 'w') as f: f.write(sample_template) subdir = watch_directory + 'test_subdir/' try: mkdir(subdir) except OSError: if not isdir(subdir): raise with open(subdir + 'test_two.haml', 'w') as f: f.write(sample_template) sleep(1) assert_true(exists(render_directory + 'test.html')) assert_true(exists(render_directory + 'test_subdir/test_two.html')) except: raise finally: condition.release() p.terminate() p.join() sleep(1) _cleanup(watch_directory) _cleanup(render_directory)
def test_time_after(): s = Schema() s.my_birthday.date().time_after(date.today()) s.far_far_away.date(format='american_scientific').time_after(date.today()) s.long_time_ago.date(format='american_scientific').time_after(date.today()) s.validate(test_data) assert_false(s.valid) assert_false(s.my_birthday.valid) assert_true(s.far_far_away.valid) assert_false(s.long_time_ago.valid)
def test_time_before(): s = Schema() s.my_birthday.date().time_before(date.today()) s.far_far_away.date(format='american_scientific').time_before(date.today()) s.long_time_ago.date(format='american_scientific').time_before(date.today()) s.validate(test_data) assert_false(s.valid) assert_true(s.my_birthday.valid) assert_false(s.far_far_away.valid) # one day this assertion will be True :) assert_true(s.long_time_ago.valid)
def test_watch_directory(): def _cleanup(path): for f in listdir(path): p = join(path, f) if isdir(p): rmtree(p) elif f != '.nothing': unlink(p) sample_template = '' sample_directory = dirname(realpath(__file__)) + '/sample/' watch_directory = sample_directory + 'watch/' render_directory = sample_directory + 'render/' template_directory = sample_directory + 'templates/' with open(template_directory + 'haml.tmpl', 'r') as f: sample_template = f.read() condition = Condition() p = Process(target=reloader.watch_directory, args=(watch_directory, render_directory, condition)) condition.acquire() p.start() condition.wait() try: with open(watch_directory + 'test.haml', 'w') as f: f.write(sample_template) subdir = watch_directory + 'test_subdir/' try: mkdir(subdir) except OSError: if not isdir(subdir): raise with open(subdir + 'test_two.haml', 'w') as f: f.write(sample_template) sleep(1) assert_true(exists(render_directory + 'test.html')) assert_true(exists(render_directory + 'test_subdir/test_two.html')) except: raise finally: condition.release() p.terminate() p.join() sleep(1) _cleanup(watch_directory) _cleanup(render_directory)
def test_numeric_string(): s = Schema() s.numeric_string.numeric_string() s.validate(_sample_data()) assert_true(s.valid) s = Schema() s.actual_numbers.numeric_string() s.validate(_sample_data()) assert_false(s.valid)
def test_numeric_string(): s = Schema() s.numeric_string.numeric_string() s.validate(_sample_data()) assert_true(s.valid) s = Schema() s.actual_numbers.numeric_string() s.validate(_sample_data()) assert_false(s.valid)
def test_alpha(): s = Schema() s.alpha_string.alpha() s.validate(_sample_data()) assert_true(s.valid) s = Schema() s.actual_numbers.alpha() s.alnum_string.alpha() assert_false(s.valid) assert_false(s.actual_numbers.valid) assert_false(s.alnum_string.valid)
def test_slugify(): s = Schema() s.notslugified.slugify() s.alsonotslugified.slugify() s.sluggingindempotency.slugify() s.validate(_sample_data()) assert_true(s.valid) assert_equals(s.notslugified.result, u'i-am-not-slugified-omg-punctu3232ation-who-submits-data-like-this-anyway') assert_equals(s.alsonotslugified.result, u'a-use-slasshes-and-stufff-32') assert_equals(s.sluggingindempotency.result, u'already-slugged')
def test_integer(): s = Schema(strip_blank=False) s.integer_value.integer() s.float_value.integer() s.not_integer.integer() s.validate(test_data) assert_false(s.valid) assert_true(s.integer_value.valid) assert_false(s.float_value.valid) assert_false(s.not_integer.valid) assert_is_instance(s.integer_value.result, int)
def test_alpha(): s = Schema() s.alpha_string.alpha() s.validate(_sample_data()) assert_true(s.valid) s = Schema() s.actual_numbers.alpha() s.alnum_string.alpha() assert_false(s.valid) assert_false(s.actual_numbers.valid) assert_false(s.alnum_string.valid)
def test_time_before(): s = Schema() s.my_birthday.date().time_before(date.today()) s.far_far_away.date(format='american_scientific').time_before(date.today()) s.long_time_ago.date(format='american_scientific').time_before( date.today()) s.validate(test_data) assert_false(s.valid) assert_true(s.my_birthday.valid) assert_false( s.far_far_away.valid) # one day this assertion will be True :) assert_true(s.long_time_ago.valid)