How to use test_to_python method in Kiwi

Best Python code snippet using Kiwi_python

test_fields.py

Source: test_fields.py Github

copy

Full Screen

...7 URLField,8)9from szczypiorek.exceptions import ValidatorError10class BooleanFieldTestCase(TestCase):11 def test_to_python(self):12 assert BooleanField().to_python('X', 'True') is True13 assert BooleanField().to_python('X', 'TRUE') is True14 assert BooleanField().to_python('X', 'False') is False15 assert BooleanField().to_python('X', 'FALse') is False16 def test_to_python__allow_null(self):17 f = BooleanField(allow_null=True)18 assert f.to_python('X', None) is None19 def test_to_python__not_allow_null(self):20 f = BooleanField(allow_null=False)21 try:22 f.to_python('X', None)23 except ValidatorError as e:24 assert e.args[0] == 'env.X: Null value are not allowed'25 else:26 raise AssertionError('should raise error')27 def test_to_python__not_valid(self):28 f = BooleanField()29 try:30 f.to_python('X', 'WHAT')31 except ValidatorError as e:32 assert e.args[0] == 'env.X: Cannot cast WHAT to boolean'33 else:34 raise AssertionError('should raise error')35class CharFieldTestCase(TestCase):36 def test_to_python(self):37 assert CharField().to_python('X', 'Hi there') == 'Hi there'38 assert CharField().to_python('X', 'cześć') == 'cześć'39 def test_to_python__allow_null(self):40 f = CharField(allow_null=True)41 assert f.to_python('X', None) is None42 def test_to_python__not_allow_null(self):43 f = CharField(allow_null=False)44 try:45 f.to_python('X', None)46 except ValidatorError as e:47 assert e.args[0] == 'env.X: Null value are not allowed'48 else:49 raise AssertionError('should raise error')50 def test_to_python__not_valid(self):51 cases = [52 (53 CharField(min_length=2),54 'h',55 'env.X: Text "h" is too short. min length: 2',56 ),57 (58 CharField(max_length=4),59 'hello',60 'env.X: Text "hello" is too long. max length: 4',61 ),62 (63 CharField(min_length=3, max_length=4),64 'hi',65 'env.X: Text "hi" is too short. min length: 3',66 ),67 ]68 for f, text, message in cases:69 try:70 f.to_python('X', text)71 except ValidatorError as e:72 assert e.args[0] == message73 else:74 raise AssertionError('should raise error')75class FloatFieldTestCase(TestCase):76 def test_to_python(self):77 assert FloatField().to_python('X', '12') == 12.078 assert FloatField().to_python('X', '14.5') == 14.579 def test_to_python__allow_null(self):80 f = FloatField(allow_null=True)81 assert f.to_python('X', None) is None82 def test_to_python__not_allow_null(self):83 f = FloatField(allow_null=False)84 try:85 f.to_python('X', None)86 except ValidatorError as e:87 assert e.args[0] == 'env.X: Null value are not allowed'88 else:89 raise AssertionError('should raise error')90 def test_to_python__not_valid(self):91 f = FloatField()92 try:93 f.to_python('X', 'WHAT')94 except ValidatorError as e:95 assert e.args[0] == 'env.X: Cannot cast WHAT to float'96 else:97 raise AssertionError('should raise error')98class IntegerFieldTestCase(TestCase):99 def test_to_python(self):100 assert IntegerField().to_python('X', '12') == 12101 assert IntegerField().to_python('X', '14.5') == 14102 def test_to_python__allow_null(self):103 f = IntegerField(allow_null=True)104 assert f.to_python('X', None) is None105 def test_to_python__not_allow_null(self):106 f = IntegerField(allow_null=False)107 try:108 f.to_python('X', None)109 except ValidatorError as e:110 assert e.args[0] == 'env.X: Null value are not allowed'111 else:112 raise AssertionError('should raise error')113 def test_to_python__not_valid(self):114 f = IntegerField()115 try:116 f.to_python('X', 'WHAT')117 except ValidatorError as e:118 assert e.args[0] == 'env.X: Cannot cast WHAT to integer'119 else:120 raise AssertionError('should raise error')121class URLFieldTestCase(TestCase):122 def test_to_python(self):123 assert URLField().to_python(124 'X', 'http:/​/​127.0.0.1') == 'http:/​/​127.0.0.1'125 assert URLField().to_python(126 'X', 'ws:/​/​hi.org:123') == 'ws:/​/​hi.org:123'127 assert URLField().to_python(128 'X', 'ftp:/​/​hi.org') == 'ftp:/​/​hi.org'129 def test_to_python__allow_null(self):130 f = URLField(allow_null=True)131 assert f.to_python('X', None) is None132 def test_to_python__not_allow_null(self):133 f = URLField(allow_null=False)134 try:135 f.to_python('X', None)136 except ValidatorError as e:...

Full Screen

Full Screen

test_compound.py

Source: test_compound.py Github

copy

Full Screen

...8 def test_repr(self):9 r = repr(self.validator)10 self.assertFalse('validatorArgs' in r)11 self.assertTrue('validators=[]' in r)12 def test_to_python(self):13 self.assertRaises(NotImplementedError,14 self.validator.to_python, 1)15 def test_from_python(self):16 self.assertRaises(NotImplementedError,17 self.validator.from_python, 1)18 def test_clone(self):19 clone = self.validator()20 self.assertEqual(type(clone), type(self.validator))21class TestAllCompoundValidator(unittest.TestCase):22 def setUp(self):23 self.validator = compound.All(24 validators=[DictConverter({2: 1}), DictConverter({3: 2})])25 def test_repr(self):26 r = repr(self.validator)27 self.assertFalse('validatorArgs' in r)28 self.assertEqual(r.count('DictConverter'), 2)29 def test_to_python(self):30 self.assertEqual(self.validator.to_python(3), 1)31 def test_from_python(self):32 self.assertEqual(self.validator.from_python(1), 3)33 def test_clone(self):34 clone = self.validator()35 self.assertEqual(clone.to_python(3), 1)36class TestAnyCompoundValidator(unittest.TestCase):37 def setUp(self):38 self.validator = compound.Any(39 validators=[DictConverter({2: 'c'}), DictConverter({2: 'b'}),40 DictConverter({1: 'b'})])41 def test_repr(self):42 r = repr(self.validator)43 self.assertFalse('validatorArgs' in r)44 self.assertEqual(r.count('DictConverter'), 3)45 def test_to_python(self):46 # Should stop before 'c' coming from the right.47 self.assertEqual(self.validator.to_python(2), 'b')48 def test_from_python(self):49 # Should stop before 1 coming from the left.50 self.assertEqual(self.validator.from_python('b'), 2)51 def test_to_python_error(self):52 try:53 self.validator.to_python(3)54 except Invalid as e:55 self.assertTrue('Enter a value from: 2' in str(e))56 else:57 self.fail('Invalid should be raised when no validator succeeds.')58 def test_clone(self):59 clone = self.validator()60 self.assertEqual(clone.to_python(2), 'b')61class TestPipeCompoundValidator(unittest.TestCase):62 def setUp(self):63 self.validator = compound.Pipe(64 validators=[DictConverter({1: 2}), DictConverter({2: 3})])65 def test_repr(self):66 r = repr(self.validator)67 self.assertFalse('validatorArgs' in r)68 self.assertEqual(r.count('DictConverter'), 2)69 def test_to_python(self):70 self.assertEqual(self.validator.to_python(1), 3)71 def test_from_python(self):72 self.assertEqual(self.validator.from_python(3), 1)73 def test_clone(self):74 clone = self.validator()...

Full Screen

Full Screen

test_form.py

Source: test_form.py Github

copy

Full Screen

...7 v = DateTimeValidator(format=rfc3339.RFC3339_wo_Timezone)8 dt = datetime.datetime.now()9 self.assertEquals(v.from_python(dt,None),dt.strftime(rfc3339.RFC3339_wo_Timezone))10 11 def test_to_python(self):12 v = DateTimeValidator(format=rfc3339.RFC3339_wo_Timezone)13 dt = datetime.datetime.now()14 v.to_python(dt.strftime(rfc3339.RFC3339_wo_Timezone),None)15 self.assertRaises(Invalid,v.to_python,'iuytrewq',None)16 17class TestStringListValidator(unittest.TestCase):18 def test_from_python(self):19 v = StringListValidator()20 self.assertEquals(v.from_python(['1','2','3'],None),"1, 2, 3")21 22 def test_to_python(self):23 v = StringListValidator()24 self.assertEquals(v.to_python("1, 2, 3, ",None),['1','2','3'])25 self.assertRaises(Invalid,v.to_python,None,None)26 27class TestUniqueUserName(unittest.TestCase):28 def setUp(self):29 from columns.model import User30 tmp = User.from_dict(dict(31 id=1,32 name=u'test_user',33 open_id=None,34 fb_id=None,35 twitter_id=None,36 type=1,37 profile=None,38 ))39 try:40 tmp.save()41 except:42 pass43 44 def tearDown(self):45 from columns.model import User, meta46 meta.Session.query(User).delete()47 meta.Session.close()48 49 def test_to_python(self):50 v = UniqueUserName()51 self.assertEquals(v.to_python('test_user2',None),'test_user2')52 self.assertRaises(Invalid,v.to_python,'test_user',None)53 54class TestHTMLValidator(unittest.TestCase):55 def test_to_python(self):56 v = HTMLValidator()57 self.assertEquals(v.to_python('<p>test_user2</​p>',None),'<p>test_user2</​p>')58 self.assertEquals(v.to_python('<a>test_user2',None),'<a>test_user2</​a>')...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

April 2020 Platform Updates: New Browser, Better Performance &#038; Much Much More!

Howdy testers! If you’re reading this article I suggest you keep a diary & a pen handy because we’ve added numerous exciting features to our cross browser testing cloud and I am about to share them with you right away!

A Detailed Guide To Xamarin Testing

Xamarin is an open-source framework that offers cross-platform application development using the C# programming language. It helps to simplify your overall development and management of cross-platform software applications.

Migrating Test Automation Suite To Cypress 10

There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.

Dec’22 Updates: The All-New LT Browser 2.0, XCUI App Automation with HyperExecute, And More!

Greetings folks! With the new year finally upon us, we’re excited to announce a collection of brand-new product updates. At LambdaTest, we strive to provide you with a comprehensive test orchestration and execution platform to ensure the ultimate web and mobile experience.

Top 17 Resources To Learn Test Automation

Lack of training is something that creates a major roadblock for a tester. Often, testers working in an organization are all of a sudden forced to learn a new framework or an automation tool whenever a new project demands it. You may be overwhelmed on how to learn test automation, where to start from and how to master test automation for web applications, and mobile applications on a new technology so soon.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kiwi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful