Best Python code snippet using localstack_python
test_serializers.py
Source:test_serializers.py
...13 assert serializer.is_valid() is True14 assert serializer.data == data15 assert serializer.validated_data == OrderedDict([('start_time', '2021-03-28T08:00:00-0200'),16 ('end_time', '2021-03-29T08:00:01-0200')])17 self.assertIsInstance(serializer.validate_content(data['start_time']), datetime.datetime)18 assert str(serializer.validate_content(data['start_time'])) == '2021-03-28 08:00:00-02:00'19 self.assertIsInstance(serializer.validate_content(data['end_time']), datetime.datetime)20 assert str(serializer.validate_content(data['end_time'])) == '2021-03-29 08:00:01-02:00'21 self.assertIsInstance(serializer.count_seconds_for_start_date(22 serializer.validate_content(data['start_time']),23 serializer.validate_content(data['end_time'])), int)24 assert serializer.count_seconds_for_start_date(25 serializer.validate_content(data['start_time']),26 serializer.validate_content(data['end_time'])) == 027 self.assertIsInstance(serializer.count_business_seconds(28 serializer.validate_content(data['start_time']),29 serializer.validate_content(data['end_time'])), int)30 assert serializer.count_business_seconds(31 serializer.validate_content(data['start_time']),32 serializer.validate_content(data['end_time'])) == 133 assert serializer.errors == {}34 def test_serialized_date_range_2(self):35 data = {36 'start_time': '2021-03-29T08:00:00-0200',37 'end_time': '2021-03-29T08:00:01-0200',38 }39 serializer = BusinessSecondsSerializer(data=data)40 assert serializer.is_valid() is True41 assert serializer.data == data42 assert serializer.validated_data == OrderedDict([('start_time', '2021-03-29T08:00:00-0200'),43 ('end_time', '2021-03-29T08:00:01-0200')])44 self.assertIsInstance(serializer.validate_content(data['start_time']), datetime.datetime)45 assert str(serializer.validate_content(data['start_time'])) == '2021-03-29 08:00:00-02:00'46 self.assertIsInstance(serializer.validate_content(data['end_time']), datetime.datetime)47 assert str(serializer.validate_content(data['end_time'])) == '2021-03-29 08:00:01-02:00'48 self.assertIsInstance(serializer.count_seconds_for_start_date(49 serializer.validate_content(data['start_time']),50 serializer.validate_content(data['end_time'])), int)51 assert serializer.count_seconds_for_start_date(52 serializer.validate_content(data['start_time']),53 serializer.validate_content(data['end_time'])) == 154 self.assertIsInstance(serializer.count_business_seconds(55 serializer.validate_content(data['start_time']),56 serializer.validate_content(data['end_time'])), int)57 assert serializer.count_business_seconds(58 serializer.validate_content(data['start_time']),59 serializer.validate_content(data['end_time'])) == 160 assert serializer.errors == {}61 def test_serialized_date_range_3(self):62 data = {63 'start_time': '2021-03-29T08:00:00-0200',64 'end_time': '2021-03-29T17:00:00-0200',65 }66 serializer = BusinessSecondsSerializer(data=data)67 assert serializer.is_valid() is True68 assert serializer.data == data69 assert serializer.validated_data == OrderedDict([('start_time', '2021-03-29T08:00:00-0200'),70 ('end_time', '2021-03-29T17:00:00-0200')])71 self.assertIsInstance(serializer.validate_content(data['start_time']), datetime.datetime)72 assert str(serializer.validate_content(data['start_time'])) == '2021-03-29 08:00:00-02:00'73 self.assertIsInstance(serializer.validate_content(data['end_time']), datetime.datetime)74 assert str(serializer.validate_content(data['end_time'])) == '2021-03-29 17:00:00-02:00'75 self.assertIsInstance(serializer.count_seconds_for_start_date(76 serializer.validate_content(data['start_time']),77 serializer.validate_content(data['end_time'])), int)78 assert serializer.count_seconds_for_start_date(79 serializer.validate_content(data['start_time']),80 serializer.validate_content(data['end_time'])) == 3240081 self.assertIsInstance(serializer.count_business_seconds(82 serializer.validate_content(data['start_time']),83 serializer.validate_content(data['end_time'])), int)84 assert serializer.count_business_seconds(85 serializer.validate_content(data['start_time']),86 serializer.validate_content(data['end_time'])) == 3240087 assert serializer.errors == {}88 def test_serialized_date_range_4(self):89 data = {90 'start_time': '2021-03-29T09:00:00-0200',91 'end_time': '2021-03-29T13:30:00-0200',92 }93 serializer = BusinessSecondsSerializer(data=data)94 assert serializer.is_valid() is True95 assert serializer.data == data96 assert serializer.validated_data == OrderedDict([('start_time', '2021-03-29T09:00:00-0200'),97 ('end_time', '2021-03-29T13:30:00-0200')])98 self.assertIsInstance(serializer.validate_content(data['start_time']), datetime.datetime)99 assert str(serializer.validate_content(data['start_time'])) == '2021-03-29 09:00:00-02:00'100 self.assertIsInstance(serializer.validate_content(data['end_time']), datetime.datetime)101 assert str(serializer.validate_content(data['end_time'])) == '2021-03-29 13:30:00-02:00'102 self.assertIsInstance(serializer.count_seconds_for_start_date(103 serializer.validate_content(data['start_time']),104 serializer.validate_content(data['end_time'])), int)105 assert serializer.count_seconds_for_start_date(106 serializer.validate_content(data['start_time']),107 serializer.validate_content(data['end_time'])) == 16200108 self.assertIsInstance(serializer.count_business_seconds(109 serializer.validate_content(data['start_time']),110 serializer.validate_content(data['end_time'])), int)111 assert serializer.count_business_seconds(112 serializer.validate_content(data['start_time']),113 serializer.validate_content(data['end_time'])) == 16200114 assert serializer.errors == {}115 def test_serialized_date_range_5(self):116 data = {117 'start_time': '2021-03-29T07:00:00-0200',118 'end_time': '2021-03-30T18:00:00-0200',119 }120 serializer = BusinessSecondsSerializer(data=data)121 assert serializer.is_valid() is True122 assert serializer.data == data123 assert serializer.validated_data == OrderedDict([('start_time', '2021-03-29T07:00:00-0200'),124 ('end_time', '2021-03-30T18:00:00-0200')])125 self.assertIsInstance(serializer.validate_content(data['start_time']), datetime.datetime)126 assert str(serializer.validate_content(data['start_time'])) == '2021-03-29 07:00:00-02:00'127 self.assertIsInstance(serializer.validate_content(data['end_time']), datetime.datetime)128 assert str(serializer.validate_content(data['end_time'])) == '2021-03-30 18:00:00-02:00'129 self.assertIsInstance(serializer.count_seconds_for_start_date(130 serializer.validate_content(data['start_time']),131 serializer.validate_content(data['end_time'])), int)132 assert serializer.count_seconds_for_start_date(133 serializer.validate_content(data['start_time']),134 serializer.validate_content(data['end_time'])) == 32400135 self.assertIsInstance(serializer.count_business_seconds(136 serializer.validate_content(data['start_time']),137 serializer.validate_content(data['end_time'])), int)138 assert serializer.count_business_seconds(139 serializer.validate_content(data['start_time']),140 serializer.validate_content(data['end_time'])) == 64800141 assert serializer.errors == {}142 def test_serialized_date_range_6(self):143 data = {144 'start_time': '2021-03-29T07:00:00-0200',145 'end_time': '2021-03-31T18:00:00-0200',146 }147 serializer = BusinessSecondsSerializer(data=data)148 assert serializer.is_valid() is True149 assert serializer.data == data150 assert serializer.validated_data == OrderedDict([('start_time', '2021-03-29T07:00:00-0200'),151 ('end_time', '2021-03-31T18:00:00-0200')])152 self.assertIsInstance(serializer.validate_content(data['start_time']), datetime.datetime)153 assert str(serializer.validate_content(data['start_time'])) == '2021-03-29 07:00:00-02:00'154 self.assertIsInstance(serializer.validate_content(data['end_time']), datetime.datetime)155 assert str(serializer.validate_content(data['end_time'])) == '2021-03-31 18:00:00-02:00'156 self.assertIsInstance(serializer.count_seconds_for_start_date(157 serializer.validate_content(data['start_time']),158 serializer.validate_content(data['end_time'])), int)159 assert serializer.count_seconds_for_start_date(160 serializer.validate_content(data['start_time']),161 serializer.validate_content(data['end_time'])) == 32400162 self.assertIsInstance(serializer.count_business_seconds(163 serializer.validate_content(data['start_time']),164 serializer.validate_content(data['end_time'])), int)165 assert serializer.count_business_seconds(166 serializer.validate_content(data['start_time']),167 serializer.validate_content(data['end_time'])) == 97200168 assert serializer.errors == {}169 def test_serialized_date_range_7(self):170 data = {171 'start_time': '2021-03-29T07:00:00-0200',172 'end_time': '2021-04-01T18:00:00-0200',173 }174 serializer = BusinessSecondsSerializer(data=data)175 assert serializer.is_valid() is True176 assert serializer.data == data177 assert serializer.validated_data == OrderedDict([('start_time', '2021-03-29T07:00:00-0200'),178 ('end_time', '2021-04-01T18:00:00-0200')])179 self.assertIsInstance(serializer.validate_content(data['start_time']), datetime.datetime)180 assert str(serializer.validate_content(data['start_time'])) == '2021-03-29 07:00:00-02:00'181 self.assertIsInstance(serializer.validate_content(data['end_time']), datetime.datetime)182 assert str(serializer.validate_content(data['end_time'])) == '2021-04-01 18:00:00-02:00'183 self.assertIsInstance(serializer.count_seconds_for_start_date(184 serializer.validate_content(data['start_time']),185 serializer.validate_content(data['end_time'])), int)186 assert serializer.count_seconds_for_start_date(187 serializer.validate_content(data['start_time']),188 serializer.validate_content(data['end_time'])) == 32400189 self.assertIsInstance(serializer.count_business_seconds(190 serializer.validate_content(data['start_time']),191 serializer.validate_content(data['end_time'])), int)192 assert serializer.count_business_seconds(193 serializer.validate_content(data['start_time']),194 serializer.validate_content(data['end_time'])) == 129600195 assert serializer.errors == {}196 def test_serialized_date_range_8(self):197 data = {198 'start_time': '2021-03-29T07:00:00-0200',199 'end_time': '2021-04-02T18:00:00-0200',200 }201 serializer = BusinessSecondsSerializer(data=data)202 assert serializer.is_valid() is True203 assert serializer.data == data204 assert serializer.validated_data == OrderedDict([('start_time', '2021-03-29T07:00:00-0200'),205 ('end_time', '2021-04-02T18:00:00-0200')])206 self.assertIsInstance(serializer.validate_content(data['start_time']), datetime.datetime)207 assert str(serializer.validate_content(data['start_time'])) == '2021-03-29 07:00:00-02:00'208 self.assertIsInstance(serializer.validate_content(data['end_time']), datetime.datetime)209 assert str(serializer.validate_content(data['end_time'])) == '2021-04-02 18:00:00-02:00'210 self.assertIsInstance(serializer.count_seconds_for_start_date(211 serializer.validate_content(data['start_time']),212 serializer.validate_content(data['end_time'])), int)213 assert serializer.count_seconds_for_start_date(214 serializer.validate_content(data['start_time']),215 serializer.validate_content(data['end_time'])) == 32400216 self.assertIsInstance(serializer.count_business_seconds(217 serializer.validate_content(data['start_time']),218 serializer.validate_content(data['end_time'])), int)219 assert serializer.count_business_seconds(220 serializer.validate_content(data['start_time']),221 serializer.validate_content(data['end_time'])) == 162000222 assert serializer.errors == {}223 def test_serialized_date_range_9(self):224 data = {225 'start_time': '2021-03-29T07:00:00-0200',226 'end_time': '2021-04-03T18:00:00-0200',227 }228 serializer = BusinessSecondsSerializer(data=data)229 assert serializer.is_valid() is True230 assert serializer.data == data231 assert serializer.validated_data == OrderedDict([('start_time', '2021-03-29T07:00:00-0200'),232 ('end_time', '2021-04-03T18:00:00-0200')])233 self.assertIsInstance(serializer.validate_content(data['start_time']), datetime.datetime)234 assert str(serializer.validate_content(data['start_time'])) == '2021-03-29 07:00:00-02:00'235 self.assertIsInstance(serializer.validate_content(data['end_time']), datetime.datetime)236 assert str(serializer.validate_content(data['end_time'])) == '2021-04-03 18:00:00-02:00'237 self.assertIsInstance(serializer.count_seconds_for_start_date(238 serializer.validate_content(data['start_time']),239 serializer.validate_content(data['end_time'])), int)240 assert serializer.count_seconds_for_start_date(241 serializer.validate_content(data['start_time']),242 serializer.validate_content(data['end_time'])) == 32400243 self.assertIsInstance(serializer.count_business_seconds(244 serializer.validate_content(data['start_time']),245 serializer.validate_content(data['end_time'])), int)246 assert serializer.count_business_seconds(247 serializer.validate_content(data['start_time']),248 serializer.validate_content(data['end_time'])) == 162000249 assert serializer.errors == {}250 def test_serialized_empty_start_date(self):251 data = {252 'start_time': '',253 'end_time': '2021-04-03T18:00:00-0200',254 }255 serializer = BusinessSecondsSerializer(data=data)256 assert serializer.is_valid() is False257 assert serializer.data == data258 assert serializer.validated_data == {}259 assert serializer.errors == {'start_time': [ErrorDetail(string='This field may not be blank.',260 code='blank')]}261 def test_serialized_empty_end_date(self):262 data = {...
test_html_validator.py
Source:test_html_validator.py
...12 self.validator.set_check_nesting(nesting)13 def test_missing_closing_tag(self):14 self.setup(False, False, False)15 # correct tag closing test16 self.validator.validate_content("<div></div>")17 self.validator.validate_content("<body><div></div></body>")18 # incorrect tag closing tests19 with self.assertRaises(MissingClosingTagError):20 self.validator.validate_content("<body><div></div>")21 with self.assertRaises(MissingClosingTagError):22 self.validator.validate_content("<body><div></body>")23 # void tags (tags that don't need to be closed24 self.validator.validate_content("<base>")25 self.validator.validate_content("<base/>")26 self.validator.validate_content("<meta>")27 self.validator.validate_content("<meta/>")28 self.validator.validate_content("<body><meta></body>")29 self.validator.validate_content("<body><meta/></body>")30 def test_invalid_tag(self):31 self.setup(False, False, False)32 # correct tag test33 self.validator.validate_content("<body></body>")34 # incorrect tag test35 with self.assertRaises(InvalidTagError):36 self.validator.validate_content("<jibberjabber></jibberjabber>")37 with self.assertRaises(InvalidTagError):38 self.validator.validate_content("<body></jibberjabber>")39 with self.assertRaises(InvalidTagError):40 self.validator.validate_content("<jibberjabber></body>")41 # script tag is also seen as an invalid tag42 with self.assertRaises(InvalidTagError):43 self.validator.validate_content("<script>")44 with self.assertRaises(InvalidTagError):45 self.validator.validate_content("<noscript>")46 def test_invalid_attribute(self):47 self.setup(True, True, False)48 # correct attribute test49 self.validator.validate_content("<html lang='en'></html>")50 # incorrect attribute test51 with self.assertRaises(InvalidAttributeError):52 self.validator.validate_content("<html style=''></html>")53 def test_missing_required_attribute(self):54 self.setup(True, False, False)55 # correct attributes test56 self.validator.validate_content("<img src='' />")57 pass58 # incorrect (missing) required attributes test59 with self.assertRaises(MissingRequiredAttributesError):60 self.validator.validate_content("<img/>")61 with self.assertRaises(MissingRequiredAttributesError):62 self.validator.validate_content("<body><img/></body>")63 def test_missing_recommended_attribute(self):64 self.setup(False, True, False)65 # correct recommended attribute test66 self.validator.validate_content("<html lang='en'></html>")67 # incorrect (missing) recommended attribute test68 with self.assertRaises(Warnings): # throws a MissingRecommendedAttributeError but it is collected as Warnings69 self.validator.validate_content("<html></html>")70 with self.assertRaises(Warnings):71 self.validator.validate_content("<html><html><html></html></html></html>")72 def test_nesting(self):73 self.setup(False, False, True)74 # correct nesting (partial html is also valid, wrapping everything in <html> and <body> is not needed)75 self.validator.validate_content("<html><head></head><body></body></html>")76 # partial html77 self.validator.validate_content("<head></head><body></body>")78 # partial html with nesting79 self.validator.validate_content("<table><tr><td></td></tr></table>")80 # nesting with multiple elements that require the same parent81 self.validator.validate_content("<html><table><caption></caption><tr><td></td></tr></table></html>")82 # partial html83 self.validator.validate_content("<tr></tr>")84 # list85 self.validator.validate_content("<ol><li><ul><li>Text</li></ul></li></ol>")86 # incorrect nesting87 with self.assertRaises(UnexpectedTagError):88 self.validator.validate_content("<body><html><html></body>")89 with self.assertRaises(UnexpectedTagError):90 self.validator.validate_content("<html><html></html></html>")91 with self.assertRaises(UnexpectedTagError):92 self.validator.validate_content("<ol><ul><ul></ol>")93 def test_void_tags(self):94 self.setup(False, False, False)95 # correct96 self.validator.validate_content("<base>")97 self.validator.validate_content("<meta>")98 self.validator.validate_content("<meta/>")99 self.validator.validate_content("<body><meta></body>")100 # incorrect101 with self.assertRaises(NoSelfClosingTagError):102 self.validator.validate_content("<head/>")103 with self.assertRaises(NoSelfClosingTagError):104 self.validator.validate_content("<html><body/></html>")105 with self.assertRaises(UnexpectedClosingTagError):106 self.validator.validate_content("<body><img src='The picture of a cat' alt='cat.png'></img></body>")107 def test_unique_ids(self):108 self.setup(False, False, False)109 # correct110 self.validator.validate_content("<img id='img1'><img id='img2'>")111 # incorrect112 with self.assertRaises(DuplicateIdError):113 self.validator.validate_content("<img id='img1'><img id='img1'>")114 def test_values(self):115 self.setup(False, False, False)116 # correct117 self.validator.validate_content("<img src='image.jpg'>")118 self.validator.validate_content("<body class='t e s t'></body>")119 # incorrect120 with self.assertRaises(AttributeValueError):121 self.validator.validate_content("<body id=''></body>")122 with self.assertRaises(AttributeValueError):123 self.validator.validate_content("<body id='t e s t'></body>")124 with self.assertRaises(AttributeValueError):125 self.validator.validate_content("<body class=''></body>")126 with self.assertRaises(AttributeValueError):127 self.validator.validate_content("<body id='t e s t'></body>")128 with self.assertRaises(AttributeValueError):...
test_validate_content.py
Source:test_validate_content.py
...5 content = b"""position,symbol60.2,ETH70.3,XRP80.1,BTC"""9 validate_content(content)10 def test_decode_error(self):11 content = b"""\xff"""12 with self.assertRaisesRegex(ValidationError, 'decode failed'):13 validate_content(content)14 def test_read_csv_error(self):15 content = b'"'16 with self.assertRaisesRegex(ValidationError, 'read_csv failed'):17 validate_content(content)18 def test_empty(self):19 content = b"""symbol,not_found20"""21 with self.assertRaisesRegex(ValidationError, 'empty'):22 validate_content(content)23 def test_position_not_found(self):24 content = b"""symbol,not_found25BTC,0.1"""26 with self.assertRaisesRegex(ValidationError, 'position column not found'):27 validate_content(content)28 def test_symbol_not_found(self):29 content = b"""not_found,position30BTC,0.1"""31 with self.assertRaisesRegex(ValidationError, 'symbol column not found'):32 validate_content(content)33 def test_column_count(self):34 content = b"""symbol,position,extra35BTC,0.1,0.2"""36 with self.assertRaisesRegex(ValidationError, 'column count must be 2'):37 validate_content(content)38 def test_contains_nan(self):39 content = b"""symbol,position40BTC,"""41 with self.assertRaisesRegex(ValidationError, 'contains NaN'):42 validate_content(content)43 def test_duplicated_symbol(self):44 content = b"""symbol,position45BTC,0.146BTC,0.1"""47 with self.assertRaisesRegex(ValidationError, 'duplicated symbol'):48 validate_content(content)49 def test_contains_non_number(self):50 content = b"""symbol,position51BTC,non_number"""52 with self.assertRaisesRegex(ValidationError, 'contains non number'):53 validate_content(content)54 def test_contains_inf(self):55 content = b"""symbol,position56BTC,inf"""57 with self.assertRaisesRegex(ValidationError, 'contains inf'):58 validate_content(content)59 def test_contains_neg_inf(self):60 content = b"""symbol,position61BTC,-inf"""62 with self.assertRaisesRegex(ValidationError, 'contains inf'):63 validate_content(content)64 def test_position_sum(self):65 content = b"""symbol,position66BTC,-0.567ETH,0.6"""68 with self.assertRaisesRegex(ValidationError, 'sum of abs\(position\) must be in \[-1, 1\]'):69 validate_content(content)70 def test_invalid_symbol(self):71 content = b"""symbol,position72 BTC,0.1"""73 with self.assertRaisesRegex(ValidationError, 'invalid symbol'):...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!