Best Python code snippet using yandex-tank
test_input_formats.py
Source:test_input_formats.py
...19 # Parse a time in a valid format, get a parsed result20 result = f.clean('13:30:05')21 self.assertEqual(result, time(13, 30, 5))22 # The parsed result does a round trip23 text = f.widget.format_value(result)24 self.assertEqual(text, '13:30:05')25 # Parse a time in a valid, but non-default format, get a parsed result26 result = f.clean('13:30')27 self.assertEqual(result, time(13, 30, 0))28 # The parsed result does a round trip to default format29 text = f.widget.format_value(result)30 self.assertEqual(text, "13:30:00")31 # ISO formats are accepted, even if not specified in formats.py32 result = f.clean('13:30:05.000155')33 self.assertEqual(result, time(13, 30, 5, 155))34 def test_localized_timeField(self):35 "Localized TimeFields act as unlocalized widgets"36 f = forms.TimeField(localize=True)37 # Parse a time in an unaccepted format; get an error38 with self.assertRaises(forms.ValidationError):39 f.clean('1:30:05 PM')40 # Parse a time in a valid format, get a parsed result41 result = f.clean('13:30:05')42 self.assertEqual(result, time(13, 30, 5))43 # The parsed result does a round trip to the same format44 text = f.widget.format_value(result)45 self.assertEqual(text, '13:30:05')46 # Parse a time in a valid format, get a parsed result47 result = f.clean('13:30')48 self.assertEqual(result, time(13, 30, 0))49 # The parsed result does a round trip to default format50 text = f.widget.format_value(result)51 self.assertEqual(text, "13:30:00")52 def test_timeField_with_inputformat(self):53 "TimeFields with manually specified input formats can accept those formats"54 f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"])55 # Parse a time in an unaccepted format; get an error56 with self.assertRaises(forms.ValidationError):57 f.clean('1:30:05 PM')58 with self.assertRaises(forms.ValidationError):59 f.clean('13:30:05')60 # Parse a time in a valid format, get a parsed result61 result = f.clean('13.30.05')62 self.assertEqual(result, time(13, 30, 5))63 # The parsed result does a round trip to the same format64 text = f.widget.format_value(result)65 self.assertEqual(text, "13:30:05")66 # Parse a time in a valid format, get a parsed result67 result = f.clean('13.30')68 self.assertEqual(result, time(13, 30, 0))69 # The parsed result does a round trip to default format70 text = f.widget.format_value(result)71 self.assertEqual(text, "13:30:00")72 def test_localized_timeField_with_inputformat(self):73 "Localized TimeFields with manually specified input formats can accept those formats"74 f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"], localize=True)75 # Parse a time in an unaccepted format; get an error76 with self.assertRaises(forms.ValidationError):77 f.clean('1:30:05 PM')78 with self.assertRaises(forms.ValidationError):79 f.clean('13:30:05')80 # Parse a time in a valid format, get a parsed result81 result = f.clean('13.30.05')82 self.assertEqual(result, time(13, 30, 5))83 # The parsed result does a round trip to the same format84 text = f.widget.format_value(result)85 self.assertEqual(text, "13:30:05")86 # Parse a time in a valid format, get a parsed result87 result = f.clean('13.30')88 self.assertEqual(result, time(13, 30, 0))89 # The parsed result does a round trip to default format90 text = f.widget.format_value(result)91 self.assertEqual(text, "13:30:00")92@override_settings(TIME_INPUT_FORMATS=["%I:%M:%S %p", "%I:%M %p"])93class CustomTimeInputFormatsTests(SimpleTestCase):94 def test_timeField(self):95 "TimeFields can parse dates in the default format"96 f = forms.TimeField()97 # Parse a time in an unaccepted format; get an error98 with self.assertRaises(forms.ValidationError):99 f.clean('13:30:05')100 # Parse a time in a valid format, get a parsed result101 result = f.clean('1:30:05 PM')102 self.assertEqual(result, time(13, 30, 5))103 # The parsed result does a round trip104 text = f.widget.format_value(result)105 self.assertEqual(text, '01:30:05 PM')106 # Parse a time in a valid, but non-default format, get a parsed result107 result = f.clean('1:30 PM')108 self.assertEqual(result, time(13, 30, 0))109 # The parsed result does a round trip to default format110 text = f.widget.format_value(result)111 self.assertEqual(text, "01:30:00 PM")112 def test_localized_timeField(self):113 "Localized TimeFields act as unlocalized widgets"114 f = forms.TimeField(localize=True)115 # Parse a time in an unaccepted format; get an error116 with self.assertRaises(forms.ValidationError):117 f.clean('13:30:05')118 # Parse a time in a valid format, get a parsed result119 result = f.clean('1:30:05 PM')120 self.assertEqual(result, time(13, 30, 5))121 # The parsed result does a round trip to the same format122 text = f.widget.format_value(result)123 self.assertEqual(text, '01:30:05 PM')124 # Parse a time in a valid format, get a parsed result125 result = f.clean('01:30 PM')126 self.assertEqual(result, time(13, 30, 0))127 # The parsed result does a round trip to default format128 text = f.widget.format_value(result)129 self.assertEqual(text, "01:30:00 PM")130 def test_timeField_with_inputformat(self):131 "TimeFields with manually specified input formats can accept those formats"132 f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"])133 # Parse a time in an unaccepted format; get an error134 with self.assertRaises(forms.ValidationError):135 f.clean('1:30:05 PM')136 with self.assertRaises(forms.ValidationError):137 f.clean('13:30:05')138 # Parse a time in a valid format, get a parsed result139 result = f.clean('13.30.05')140 self.assertEqual(result, time(13, 30, 5))141 # The parsed result does a round trip to the same format142 text = f.widget.format_value(result)143 self.assertEqual(text, "01:30:05 PM")144 # Parse a time in a valid format, get a parsed result145 result = f.clean('13.30')146 self.assertEqual(result, time(13, 30, 0))147 # The parsed result does a round trip to default format148 text = f.widget.format_value(result)149 self.assertEqual(text, "01:30:00 PM")150 def test_localized_timeField_with_inputformat(self):151 "Localized TimeFields with manually specified input formats can accept those formats"152 f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"], localize=True)153 # Parse a time in an unaccepted format; get an error154 with self.assertRaises(forms.ValidationError):155 f.clean('1:30:05 PM')156 with self.assertRaises(forms.ValidationError):157 f.clean('13:30:05')158 # Parse a time in a valid format, get a parsed result159 result = f.clean('13.30.05')160 self.assertEqual(result, time(13, 30, 5))161 # The parsed result does a round trip to the same format162 text = f.widget.format_value(result)163 self.assertEqual(text, "01:30:05 PM")164 # Parse a time in a valid format, get a parsed result165 result = f.clean('13.30')166 self.assertEqual(result, time(13, 30, 0))167 # The parsed result does a round trip to default format168 text = f.widget.format_value(result)169 self.assertEqual(text, "01:30:00 PM")170class SimpleTimeFormatTests(SimpleTestCase):171 def test_timeField(self):172 "TimeFields can parse dates in the default format"173 f = forms.TimeField()174 # Parse a time in an unaccepted format; get an error175 with self.assertRaises(forms.ValidationError):176 f.clean('1:30:05 PM')177 # Parse a time in a valid format, get a parsed result178 result = f.clean('13:30:05')179 self.assertEqual(result, time(13, 30, 5))180 # The parsed result does a round trip to the same format181 text = f.widget.format_value(result)182 self.assertEqual(text, "13:30:05")183 # Parse a time in a valid, but non-default format, get a parsed result184 result = f.clean('13:30')185 self.assertEqual(result, time(13, 30, 0))186 # The parsed result does a round trip to default format187 text = f.widget.format_value(result)188 self.assertEqual(text, "13:30:00")189 def test_localized_timeField(self):190 "Localized TimeFields in a non-localized environment act as unlocalized widgets"191 f = forms.TimeField()192 # Parse a time in an unaccepted format; get an error193 with self.assertRaises(forms.ValidationError):194 f.clean('1:30:05 PM')195 # Parse a time in a valid format, get a parsed result196 result = f.clean('13:30:05')197 self.assertEqual(result, time(13, 30, 5))198 # The parsed result does a round trip to the same format199 text = f.widget.format_value(result)200 self.assertEqual(text, "13:30:05")201 # Parse a time in a valid format, get a parsed result202 result = f.clean('13:30')203 self.assertEqual(result, time(13, 30, 0))204 # The parsed result does a round trip to default format205 text = f.widget.format_value(result)206 self.assertEqual(text, "13:30:00")207 def test_timeField_with_inputformat(self):208 "TimeFields with manually specified input formats can accept those formats"209 f = forms.TimeField(input_formats=["%I:%M:%S %p", "%I:%M %p"])210 # Parse a time in an unaccepted format; get an error211 with self.assertRaises(forms.ValidationError):212 f.clean('13:30:05')213 # Parse a time in a valid format, get a parsed result214 result = f.clean('1:30:05 PM')215 self.assertEqual(result, time(13, 30, 5))216 # The parsed result does a round trip to the same format217 text = f.widget.format_value(result)218 self.assertEqual(text, "13:30:05")219 # Parse a time in a valid format, get a parsed result220 result = f.clean('1:30 PM')221 self.assertEqual(result, time(13, 30, 0))222 # The parsed result does a round trip to default format223 text = f.widget.format_value(result)224 self.assertEqual(text, "13:30:00")225 def test_localized_timeField_with_inputformat(self):226 "Localized TimeFields with manually specified input formats can accept those formats"227 f = forms.TimeField(input_formats=["%I:%M:%S %p", "%I:%M %p"], localize=True)228 # Parse a time in an unaccepted format; get an error229 with self.assertRaises(forms.ValidationError):230 f.clean('13:30:05')231 # Parse a time in a valid format, get a parsed result232 result = f.clean('1:30:05 PM')233 self.assertEqual(result, time(13, 30, 5))234 # The parsed result does a round trip to the same format235 text = f.widget.format_value(result)236 self.assertEqual(text, "13:30:05")237 # Parse a time in a valid format, get a parsed result238 result = f.clean('1:30 PM')239 self.assertEqual(result, time(13, 30, 0))240 # The parsed result does a round trip to default format241 text = f.widget.format_value(result)242 self.assertEqual(text, "13:30:00")243@override_settings(DATE_INPUT_FORMATS=["%d/%m/%Y", "%d-%m-%Y"], USE_L10N=True)244class LocalizedDateTests(SimpleTestCase):245 def setUp(self):246 activate('de')247 def tearDown(self):248 deactivate()249 def test_dateField(self):250 "DateFields can parse dates in the default format"251 f = forms.DateField()252 # Parse a date in an unaccepted format; get an error253 with self.assertRaises(forms.ValidationError):254 f.clean('21/12/2010')255 # ISO formats are accepted, even if not specified in formats.py256 self.assertEqual(f.clean('2010-12-21'), date(2010, 12, 21))257 # Parse a date in a valid format, get a parsed result258 result = f.clean('21.12.2010')259 self.assertEqual(result, date(2010, 12, 21))260 # The parsed result does a round trip261 text = f.widget.format_value(result)262 self.assertEqual(text, '21.12.2010')263 # Parse a date in a valid, but non-default format, get a parsed result264 result = f.clean('21.12.10')265 self.assertEqual(result, date(2010, 12, 21))266 # The parsed result does a round trip to default format267 text = f.widget.format_value(result)268 self.assertEqual(text, "21.12.2010")269 def test_localized_dateField(self):270 "Localized DateFields act as unlocalized widgets"271 f = forms.DateField(localize=True)272 # Parse a date in an unaccepted format; get an error273 with self.assertRaises(forms.ValidationError):274 f.clean('21/12/2010')275 # Parse a date in a valid format, get a parsed result276 result = f.clean('21.12.2010')277 self.assertEqual(result, date(2010, 12, 21))278 # The parsed result does a round trip to the same format279 text = f.widget.format_value(result)280 self.assertEqual(text, '21.12.2010')281 # Parse a date in a valid format, get a parsed result282 result = f.clean('21.12.10')283 self.assertEqual(result, date(2010, 12, 21))284 # The parsed result does a round trip to default format285 text = f.widget.format_value(result)286 self.assertEqual(text, "21.12.2010")287 def test_dateField_with_inputformat(self):288 "DateFields with manually specified input formats can accept those formats"289 f = forms.DateField(input_formats=["%m.%d.%Y", "%m-%d-%Y"])290 # Parse a date in an unaccepted format; get an error291 with self.assertRaises(forms.ValidationError):292 f.clean('2010-12-21')293 with self.assertRaises(forms.ValidationError):294 f.clean('21/12/2010')295 with self.assertRaises(forms.ValidationError):296 f.clean('21.12.2010')297 # Parse a date in a valid format, get a parsed result298 result = f.clean('12.21.2010')299 self.assertEqual(result, date(2010, 12, 21))300 # The parsed result does a round trip to the same format301 text = f.widget.format_value(result)302 self.assertEqual(text, "21.12.2010")303 # Parse a date in a valid format, get a parsed result304 result = f.clean('12-21-2010')305 self.assertEqual(result, date(2010, 12, 21))306 # The parsed result does a round trip to default format307 text = f.widget.format_value(result)308 self.assertEqual(text, "21.12.2010")309 def test_localized_dateField_with_inputformat(self):310 "Localized DateFields with manually specified input formats can accept those formats"311 f = forms.DateField(input_formats=["%m.%d.%Y", "%m-%d-%Y"], localize=True)312 # Parse a date in an unaccepted format; get an error313 with self.assertRaises(forms.ValidationError):314 f.clean('2010-12-21')315 with self.assertRaises(forms.ValidationError):316 f.clean('21/12/2010')317 with self.assertRaises(forms.ValidationError):318 f.clean('21.12.2010')319 # Parse a date in a valid format, get a parsed result320 result = f.clean('12.21.2010')321 self.assertEqual(result, date(2010, 12, 21))322 # The parsed result does a round trip to the same format323 text = f.widget.format_value(result)324 self.assertEqual(text, "21.12.2010")325 # Parse a date in a valid format, get a parsed result326 result = f.clean('12-21-2010')327 self.assertEqual(result, date(2010, 12, 21))328 # The parsed result does a round trip to default format329 text = f.widget.format_value(result)330 self.assertEqual(text, "21.12.2010")331@override_settings(DATE_INPUT_FORMATS=["%d.%m.%Y", "%d-%m-%Y"])332class CustomDateInputFormatsTests(SimpleTestCase):333 def test_dateField(self):334 "DateFields can parse dates in the default format"335 f = forms.DateField()336 # Parse a date in an unaccepted format; get an error337 with self.assertRaises(forms.ValidationError):338 f.clean('2010-12-21')339 # Parse a date in a valid format, get a parsed result340 result = f.clean('21.12.2010')341 self.assertEqual(result, date(2010, 12, 21))342 # The parsed result does a round trip343 text = f.widget.format_value(result)344 self.assertEqual(text, '21.12.2010')345 # Parse a date in a valid, but non-default format, get a parsed result346 result = f.clean('21-12-2010')347 self.assertEqual(result, date(2010, 12, 21))348 # The parsed result does a round trip to default format349 text = f.widget.format_value(result)350 self.assertEqual(text, "21.12.2010")351 def test_localized_dateField(self):352 "Localized DateFields act as unlocalized widgets"353 f = forms.DateField(localize=True)354 # Parse a date in an unaccepted format; get an error355 with self.assertRaises(forms.ValidationError):356 f.clean('2010-12-21')357 # Parse a date in a valid format, get a parsed result358 result = f.clean('21.12.2010')359 self.assertEqual(result, date(2010, 12, 21))360 # The parsed result does a round trip to the same format361 text = f.widget.format_value(result)362 self.assertEqual(text, '21.12.2010')363 # Parse a date in a valid format, get a parsed result364 result = f.clean('21-12-2010')365 self.assertEqual(result, date(2010, 12, 21))366 # The parsed result does a round trip to default format367 text = f.widget.format_value(result)368 self.assertEqual(text, "21.12.2010")369 def test_dateField_with_inputformat(self):370 "DateFields with manually specified input formats can accept those formats"371 f = forms.DateField(input_formats=["%m.%d.%Y", "%m-%d-%Y"])372 # Parse a date in an unaccepted format; get an error373 with self.assertRaises(forms.ValidationError):374 f.clean('21.12.2010')375 with self.assertRaises(forms.ValidationError):376 f.clean('2010-12-21')377 # Parse a date in a valid format, get a parsed result378 result = f.clean('12.21.2010')379 self.assertEqual(result, date(2010, 12, 21))380 # The parsed result does a round trip to the same format381 text = f.widget.format_value(result)382 self.assertEqual(text, "21.12.2010")383 # Parse a date in a valid format, get a parsed result384 result = f.clean('12-21-2010')385 self.assertEqual(result, date(2010, 12, 21))386 # The parsed result does a round trip to default format387 text = f.widget.format_value(result)388 self.assertEqual(text, "21.12.2010")389 def test_localized_dateField_with_inputformat(self):390 "Localized DateFields with manually specified input formats can accept those formats"391 f = forms.DateField(input_formats=["%m.%d.%Y", "%m-%d-%Y"], localize=True)392 # Parse a date in an unaccepted format; get an error393 with self.assertRaises(forms.ValidationError):394 f.clean('21.12.2010')395 with self.assertRaises(forms.ValidationError):396 f.clean('2010-12-21')397 # Parse a date in a valid format, get a parsed result398 result = f.clean('12.21.2010')399 self.assertEqual(result, date(2010, 12, 21))400 # The parsed result does a round trip to the same format401 text = f.widget.format_value(result)402 self.assertEqual(text, "21.12.2010")403 # Parse a date in a valid format, get a parsed result404 result = f.clean('12-21-2010')405 self.assertEqual(result, date(2010, 12, 21))406 # The parsed result does a round trip to default format407 text = f.widget.format_value(result)408 self.assertEqual(text, "21.12.2010")409class SimpleDateFormatTests(SimpleTestCase):410 def test_dateField(self):411 "DateFields can parse dates in the default format"412 f = forms.DateField()413 # Parse a date in an unaccepted format; get an error414 with self.assertRaises(forms.ValidationError):415 f.clean('21.12.2010')416 # Parse a date in a valid format, get a parsed result417 result = f.clean('2010-12-21')418 self.assertEqual(result, date(2010, 12, 21))419 # The parsed result does a round trip to the same format420 text = f.widget.format_value(result)421 self.assertEqual(text, "2010-12-21")422 # Parse a date in a valid, but non-default format, get a parsed result423 result = f.clean('12/21/2010')424 self.assertEqual(result, date(2010, 12, 21))425 # The parsed result does a round trip to default format426 text = f.widget.format_value(result)427 self.assertEqual(text, "2010-12-21")428 def test_localized_dateField(self):429 "Localized DateFields in a non-localized environment act as unlocalized widgets"430 f = forms.DateField()431 # Parse a date in an unaccepted format; get an error432 with self.assertRaises(forms.ValidationError):433 f.clean('21.12.2010')434 # Parse a date in a valid format, get a parsed result435 result = f.clean('2010-12-21')436 self.assertEqual(result, date(2010, 12, 21))437 # The parsed result does a round trip to the same format438 text = f.widget.format_value(result)439 self.assertEqual(text, "2010-12-21")440 # Parse a date in a valid format, get a parsed result441 result = f.clean('12/21/2010')442 self.assertEqual(result, date(2010, 12, 21))443 # The parsed result does a round trip to default format444 text = f.widget.format_value(result)445 self.assertEqual(text, "2010-12-21")446 def test_dateField_with_inputformat(self):447 "DateFields with manually specified input formats can accept those formats"448 f = forms.DateField(input_formats=["%d.%m.%Y", "%d-%m-%Y"])449 # Parse a date in an unaccepted format; get an error450 with self.assertRaises(forms.ValidationError):451 f.clean('2010-12-21')452 # Parse a date in a valid format, get a parsed result453 result = f.clean('21.12.2010')454 self.assertEqual(result, date(2010, 12, 21))455 # The parsed result does a round trip to the same format456 text = f.widget.format_value(result)457 self.assertEqual(text, "2010-12-21")458 # Parse a date in a valid format, get a parsed result459 result = f.clean('21-12-2010')460 self.assertEqual(result, date(2010, 12, 21))461 # The parsed result does a round trip to default format462 text = f.widget.format_value(result)463 self.assertEqual(text, "2010-12-21")464 def test_localized_dateField_with_inputformat(self):465 "Localized DateFields with manually specified input formats can accept those formats"466 f = forms.DateField(input_formats=["%d.%m.%Y", "%d-%m-%Y"], localize=True)467 # Parse a date in an unaccepted format; get an error468 with self.assertRaises(forms.ValidationError):469 f.clean('2010-12-21')470 # Parse a date in a valid format, get a parsed result471 result = f.clean('21.12.2010')472 self.assertEqual(result, date(2010, 12, 21))473 # The parsed result does a round trip to the same format474 text = f.widget.format_value(result)475 self.assertEqual(text, "2010-12-21")476 # Parse a date in a valid format, get a parsed result477 result = f.clean('21-12-2010')478 self.assertEqual(result, date(2010, 12, 21))479 # The parsed result does a round trip to default format480 text = f.widget.format_value(result)481 self.assertEqual(text, "2010-12-21")482@override_settings(DATETIME_INPUT_FORMATS=["%I:%M:%S %p %d/%m/%Y", "%I:%M %p %d-%m-%Y"], USE_L10N=True)483class LocalizedDateTimeTests(SimpleTestCase):484 def setUp(self):485 activate('de')486 def tearDown(self):487 deactivate()488 def test_dateTimeField(self):489 "DateTimeFields can parse dates in the default format"490 f = forms.DateTimeField()491 # Parse a date in an unaccepted format; get an error492 with self.assertRaises(forms.ValidationError):493 f.clean('1:30:05 PM 21/12/2010')494 # ISO formats are accepted, even if not specified in formats.py495 self.assertEqual(f.clean('2010-12-21 13:30:05'), datetime(2010, 12, 21, 13, 30, 5))496 # Parse a date in a valid format, get a parsed result497 result = f.clean('21.12.2010 13:30:05')498 self.assertEqual(result, datetime(2010, 12, 21, 13, 30, 5))499 # The parsed result does a round trip500 text = f.widget.format_value(result)501 self.assertEqual(text, '21.12.2010 13:30:05')502 # Parse a date in a valid, but non-default format, get a parsed result503 result = f.clean('21.12.2010 13:30')504 self.assertEqual(result, datetime(2010, 12, 21, 13, 30))505 # The parsed result does a round trip to default format506 text = f.widget.format_value(result)507 self.assertEqual(text, "21.12.2010 13:30:00")508 def test_localized_dateTimeField(self):509 "Localized DateTimeFields act as unlocalized widgets"510 f = forms.DateTimeField(localize=True)511 # Parse a date in an unaccepted format; get an error512 with self.assertRaises(forms.ValidationError):513 f.clean('1:30:05 PM 21/12/2010')514 # Parse a date in a valid format, get a parsed result515 result = f.clean('21.12.2010 13:30:05')516 self.assertEqual(result, datetime(2010, 12, 21, 13, 30, 5))517 # The parsed result does a round trip to the same format518 text = f.widget.format_value(result)519 self.assertEqual(text, '21.12.2010 13:30:05')520 # Parse a date in a valid format, get a parsed result521 result = f.clean('21.12.2010 13:30')522 self.assertEqual(result, datetime(2010, 12, 21, 13, 30))523 # The parsed result does a round trip to default format524 text = f.widget.format_value(result)525 self.assertEqual(text, "21.12.2010 13:30:00")526 def test_dateTimeField_with_inputformat(self):527 "DateTimeFields with manually specified input formats can accept those formats"528 f = forms.DateTimeField(input_formats=["%H.%M.%S %m.%d.%Y", "%H.%M %m-%d-%Y"])529 # Parse a date in an unaccepted format; get an error530 with self.assertRaises(forms.ValidationError):531 f.clean('2010-12-21 13:30:05 13:30:05')532 with self.assertRaises(forms.ValidationError):533 f.clean('1:30:05 PM 21/12/2010')534 with self.assertRaises(forms.ValidationError):535 f.clean('13:30:05 21.12.2010')536 # Parse a date in a valid format, get a parsed result537 result = f.clean('13.30.05 12.21.2010')538 self.assertEqual(result, datetime(2010, 12, 21, 13, 30, 5))539 # The parsed result does a round trip to the same format540 text = f.widget.format_value(result)541 self.assertEqual(text, "21.12.2010 13:30:05")542 # Parse a date in a valid format, get a parsed result543 result = f.clean('13.30 12-21-2010')544 self.assertEqual(result, datetime(2010, 12, 21, 13, 30))545 # The parsed result does a round trip to default format546 text = f.widget.format_value(result)547 self.assertEqual(text, "21.12.2010 13:30:00")548 def test_localized_dateTimeField_with_inputformat(self):549 "Localized DateTimeFields with manually specified input formats can accept those formats"550 f = forms.DateTimeField(input_formats=["%H.%M.%S %m.%d.%Y", "%H.%M %m-%d-%Y"], localize=True)551 # Parse a date in an unaccepted format; get an error552 with self.assertRaises(forms.ValidationError):553 f.clean('2010-12-21 13:30:05')554 with self.assertRaises(forms.ValidationError):555 f.clean('1:30:05 PM 21/12/2010')556 with self.assertRaises(forms.ValidationError):557 f.clean('13:30:05 21.12.2010')558 # Parse a date in a valid format, get a parsed result559 result = f.clean('13.30.05 12.21.2010')560 self.assertEqual(result, datetime(2010, 12, 21, 13, 30, 5))561 # The parsed result does a round trip to the same format562 text = f.widget.format_value(result)563 self.assertEqual(text, "21.12.2010 13:30:05")564 # Parse a date in a valid format, get a parsed result565 result = f.clean('13.30 12-21-2010')566 self.assertEqual(result, datetime(2010, 12, 21, 13, 30))567 # The parsed result does a round trip to default format568 text = f.widget.format_value(result)569 self.assertEqual(text, "21.12.2010 13:30:00")570@override_settings(DATETIME_INPUT_FORMATS=["%I:%M:%S %p %d/%m/%Y", "%I:%M %p %d-%m-%Y"])571class CustomDateTimeInputFormatsTests(SimpleTestCase):572 def test_dateTimeField(self):573 "DateTimeFields can parse dates in the default format"574 f = forms.DateTimeField()575 # Parse a date in an unaccepted format; get an error576 with self.assertRaises(forms.ValidationError):577 f.clean('2010-12-21 13:30:05')578 # Parse a date in a valid format, get a parsed result579 result = f.clean('1:30:05 PM 21/12/2010')580 self.assertEqual(result, datetime(2010, 12, 21, 13, 30, 5))581 # The parsed result does a round trip582 text = f.widget.format_value(result)583 self.assertEqual(text, '01:30:05 PM 21/12/2010')584 # Parse a date in a valid, but non-default format, get a parsed result585 result = f.clean('1:30 PM 21-12-2010')586 self.assertEqual(result, datetime(2010, 12, 21, 13, 30))587 # The parsed result does a round trip to default format588 text = f.widget.format_value(result)589 self.assertEqual(text, "01:30:00 PM 21/12/2010")590 def test_localized_dateTimeField(self):591 "Localized DateTimeFields act as unlocalized widgets"592 f = forms.DateTimeField(localize=True)593 # Parse a date in an unaccepted format; get an error594 with self.assertRaises(forms.ValidationError):595 f.clean('2010-12-21 13:30:05')596 # Parse a date in a valid format, get a parsed result597 result = f.clean('1:30:05 PM 21/12/2010')598 self.assertEqual(result, datetime(2010, 12, 21, 13, 30, 5))599 # The parsed result does a round trip to the same format600 text = f.widget.format_value(result)601 self.assertEqual(text, '01:30:05 PM 21/12/2010')602 # Parse a date in a valid format, get a parsed result603 result = f.clean('1:30 PM 21-12-2010')604 self.assertEqual(result, datetime(2010, 12, 21, 13, 30))605 # The parsed result does a round trip to default format606 text = f.widget.format_value(result)607 self.assertEqual(text, "01:30:00 PM 21/12/2010")608 def test_dateTimeField_with_inputformat(self):609 "DateTimeFields with manually specified input formats can accept those formats"610 f = forms.DateTimeField(input_formats=["%m.%d.%Y %H:%M:%S", "%m-%d-%Y %H:%M"])611 # Parse a date in an unaccepted format; get an error612 with self.assertRaises(forms.ValidationError):613 f.clean('13:30:05 21.12.2010')614 with self.assertRaises(forms.ValidationError):615 f.clean('2010-12-21 13:30:05')616 # Parse a date in a valid format, get a parsed result617 result = f.clean('12.21.2010 13:30:05')618 self.assertEqual(result, datetime(2010, 12, 21, 13, 30, 5))619 # The parsed result does a round trip to the same format620 text = f.widget.format_value(result)621 self.assertEqual(text, "01:30:05 PM 21/12/2010")622 # Parse a date in a valid format, get a parsed result623 result = f.clean('12-21-2010 13:30')624 self.assertEqual(result, datetime(2010, 12, 21, 13, 30))625 # The parsed result does a round trip to default format626 text = f.widget.format_value(result)627 self.assertEqual(text, "01:30:00 PM 21/12/2010")628 def test_localized_dateTimeField_with_inputformat(self):629 "Localized DateTimeFields with manually specified input formats can accept those formats"630 f = forms.DateTimeField(input_formats=["%m.%d.%Y %H:%M:%S", "%m-%d-%Y %H:%M"], localize=True)631 # Parse a date in an unaccepted format; get an error632 with self.assertRaises(forms.ValidationError):633 f.clean('13:30:05 21.12.2010')634 with self.assertRaises(forms.ValidationError):635 f.clean('2010-12-21 13:30:05')636 # Parse a date in a valid format, get a parsed result637 result = f.clean('12.21.2010 13:30:05')638 self.assertEqual(result, datetime(2010, 12, 21, 13, 30, 5))639 # The parsed result does a round trip to the same format640 text = f.widget.format_value(result)641 self.assertEqual(text, "01:30:05 PM 21/12/2010")642 # Parse a date in a valid format, get a parsed result643 result = f.clean('12-21-2010 13:30')644 self.assertEqual(result, datetime(2010, 12, 21, 13, 30))645 # The parsed result does a round trip to default format646 text = f.widget.format_value(result)647 self.assertEqual(text, "01:30:00 PM 21/12/2010")648class SimpleDateTimeFormatTests(SimpleTestCase):649 def test_dateTimeField(self):650 "DateTimeFields can parse dates in the default format"651 f = forms.DateTimeField()652 # Parse a date in an unaccepted format; get an error653 with self.assertRaises(forms.ValidationError):654 f.clean('13:30:05 21.12.2010')655 # Parse a date in a valid format, get a parsed result656 result = f.clean('2010-12-21 13:30:05')657 self.assertEqual(result, datetime(2010, 12, 21, 13, 30, 5))658 # The parsed result does a round trip to the same format659 text = f.widget.format_value(result)660 self.assertEqual(text, "2010-12-21 13:30:05")661 # Parse a date in a valid, but non-default format, get a parsed result662 result = f.clean('12/21/2010 13:30:05')663 self.assertEqual(result, datetime(2010, 12, 21, 13, 30, 5))664 # The parsed result does a round trip to default format665 text = f.widget.format_value(result)666 self.assertEqual(text, "2010-12-21 13:30:05")667 def test_localized_dateTimeField(self):668 "Localized DateTimeFields in a non-localized environment act as unlocalized widgets"669 f = forms.DateTimeField()670 # Parse a date in an unaccepted format; get an error671 with self.assertRaises(forms.ValidationError):672 f.clean('13:30:05 21.12.2010')673 # Parse a date in a valid format, get a parsed result674 result = f.clean('2010-12-21 13:30:05')675 self.assertEqual(result, datetime(2010, 12, 21, 13, 30, 5))676 # The parsed result does a round trip to the same format677 text = f.widget.format_value(result)678 self.assertEqual(text, "2010-12-21 13:30:05")679 # Parse a date in a valid format, get a parsed result680 result = f.clean('12/21/2010 13:30:05')681 self.assertEqual(result, datetime(2010, 12, 21, 13, 30, 5))682 # The parsed result does a round trip to default format683 text = f.widget.format_value(result)684 self.assertEqual(text, "2010-12-21 13:30:05")685 def test_dateTimeField_with_inputformat(self):686 "DateTimeFields with manually specified input formats can accept those formats"687 f = forms.DateTimeField(input_formats=["%I:%M:%S %p %d.%m.%Y", "%I:%M %p %d-%m-%Y"])688 # Parse a date in an unaccepted format; get an error689 with self.assertRaises(forms.ValidationError):690 f.clean('2010-12-21 13:30:05')691 # Parse a date in a valid format, get a parsed result692 result = f.clean('1:30:05 PM 21.12.2010')693 self.assertEqual(result, datetime(2010, 12, 21, 13, 30, 5))694 # The parsed result does a round trip to the same format695 text = f.widget.format_value(result)696 self.assertEqual(text, "2010-12-21 13:30:05")697 # Parse a date in a valid format, get a parsed result698 result = f.clean('1:30 PM 21-12-2010')699 self.assertEqual(result, datetime(2010, 12, 21, 13, 30))700 # The parsed result does a round trip to default format701 text = f.widget.format_value(result)702 self.assertEqual(text, "2010-12-21 13:30:00")703 def test_localized_dateTimeField_with_inputformat(self):704 "Localized DateTimeFields with manually specified input formats can accept those formats"705 f = forms.DateTimeField(input_formats=["%I:%M:%S %p %d.%m.%Y", "%I:%M %p %d-%m-%Y"], localize=True)706 # Parse a date in an unaccepted format; get an error707 with self.assertRaises(forms.ValidationError):708 f.clean('2010-12-21 13:30:05')709 # Parse a date in a valid format, get a parsed result710 result = f.clean('1:30:05 PM 21.12.2010')711 self.assertEqual(result, datetime(2010, 12, 21, 13, 30, 5))712 # The parsed result does a round trip to the same format713 text = f.widget.format_value(result)714 self.assertEqual(text, "2010-12-21 13:30:05")715 # Parse a date in a valid format, get a parsed result716 result = f.clean('1:30 PM 21-12-2010')717 self.assertEqual(result, datetime(2010, 12, 21, 13, 30))718 # The parsed result does a round trip to default format719 text = f.widget.format_value(result)...
formats.js
Source:formats.js
2 dependencies: ['web.formats']3}, function (test) {4 test("format_datetime", function (instance) {5 var date = instance.web.str_to_datetime("2009-05-04 12:34:23");6 var str = instance.web.format_value(date, {type:"datetime"});7 equal(str, date.toString("MM/dd/yyyy HH:mm:ss"));8 });9 test("format_date", function (instance) {10 var date = instance.web.str_to_datetime("2009-05-04 12:34:23");11 var str = instance.web.format_value(date, {type:"date"});12 equal(str, date.toString("MM/dd/yyyy"));13 });14 test("format_time", function (instance) {15 var date = instance.web.str_to_datetime("2009-05-04 12:34:23");16 var str = instance.web.format_value(date, {type:"time"});17 equal(str, date.toString("HH:mm:ss"));18 });19 test("format_float_time", function (instance) {20 strictEqual(21 instance.web.format_value(1.0, {type:'float', widget:'float_time'}),22 '01:00');23 strictEqual(24 instance.web.format_value(0.9853, {type:'float', widget:'float_time'}),25 '00:59');26 strictEqual(27 instance.web.format_value(0.0085, {type:'float', widget:'float_time'}),28 '00:01');29 strictEqual(30 instance.web.format_value(-1.0, {type:'float', widget:'float_time'}),31 '-01:00');32 strictEqual(33 instance.web.format_value(-0.9853, {type:'float', widget:'float_time'}),34 '-00:59');35 strictEqual(36 instance.web.format_value(-0.0085, {type:'float', widget:'float_time'}),37 '-00:01');38 strictEqual(39 instance.web.format_value(4.9999, {type:'float', widget:'float_time'}),40 '05:00');41 strictEqual(42 instance.web.format_value(-6.9999, {type:'float', widget:'float_time'}),43 '-07:00');44 });45 test("format_float", function (instance) {46 var fl = 12.1234;47 var str = instance.web.format_value(fl, {type:"float"});48 equal(str, "12.12");49 equal(instance.web.format_value(12.02, {type: 'float'}),50 '12.02');51 equal(instance.web.format_value(0.0002, {type: 'float', digits: [1, 3]}),52 '0.000');53 equal(instance.web.format_value(0.0002, {type: 'float', digits: [1, 4]}),54 '0.0002');55 equal(instance.web.format_value(0.0002, {type: 'float', digits: [1, 6]}),56 '0.000200');57 equal(instance.web.format_value(1, {type: 'float', digits: [1, 6]}),58 '1.000000');59 equal(instance.web.format_value(1, {type: 'float'}),60 '1.00');61 equal(instance.web.format_value(-11.25, {type: 'float'}),62 "-11.25");63 instance.web._t.database.parameters.grouping = [1, 2, -1];64 equal(instance.web.format_value(1111111.25, {type: 'float'}),65 "1111,11,1.25");66 instance.web._t.database.parameters.grouping = [1, 0];67 equal(instance.web.format_value(-11.25, {type: 'float'}),68 "-1,1.25");69 });70// test("parse_datetime", function () {71// var val = openerp.web.str_to_datetime("2009-05-04 12:34:23");72// var res = openerp.web.parse_value(val.toString("MM/dd/yyyy HH:mm:ss"), {type:"datetime"});73// equal(val.toString("MM/dd/yyyy HH:mm:ss"), res.toString("MM/dd/yyyy HH:mm:ss"));74// });75// test("parse_date", function () {76// var val = openerp.web.str_to_date("2009-05-04");77// var res = openerp.web.parse_value(val.toString("MM/dd/yyyy"), {type:"date"});78// equal(val.toString("MM/dd/yyyy"), res.toString("MM/dd/yyyy"));79// });80// test("parse_time", function () {81// var val = openerp.web.str_to_time("12:34:23");82// var res = openerp.web.parse_value(val.toString("HH:mm:ss"), {type:"time"});83// equal(val.toString("HH:mm:ss"), res.toString("HH:mm:ss"));84// });85 test('parse_integer', function (instance) {86 var tmp = instance.web._t.database.parameters.thousands_sep;87 try {88 var val = instance.web.parse_value('123,456', {type: 'integer'});89 equal(val, 123456);90 instance.web._t.database.parameters.thousands_sep = '|';91 var val2 = instance.web.parse_value('123|456', {type: 'integer'});92 equal(val2, 123456);93 } finally {94 instance.web._t.database.parameters.thousands_sep = tmp;95 }96 });97 test("parse_float", function (instance) {98 var tmp1 = instance.web._t.database.parameters.thousands_sep;99 var tmp2 = instance.web._t.database.parameters.decimal_point;100 try {101 var str = "134,112.1234";102 var val = instance.web.parse_value(str, {type:"float"});103 equal(val, 134112.1234);104 str = "-134,112.1234";105 val = instance.web.parse_value(str, {type:"float"});106 equal(val, -134112.1234);107 _.extend(instance.web._t.database.parameters, {108 decimal_point: ',',109 thousands_sep: '.'110 });111 var val3 = instance.web.parse_value('123.456,789', {type: 'float'});112 equal(val3, 123456.789);113 } finally {114 instance.web._t.database.parameters.thousands_sep = tmp1;115 instance.web._t.database.parameters.decimal_point = tmp2;116 }117 });118 test('intersperse', function (instance) {119 var g = instance.web.intersperse;120 equal(g("", []), "");121 equal(g("0", []), "0");122 equal(g("012", []), "012");123 equal(g("1", []), "1");124 equal(g("12", []), "12");125 equal(g("123", []), "123");126 equal(g("1234", []), "1234");127 equal(g("123456789", []), "123456789");128 equal(g("&ab%#@1", []), "&ab%#@1");129 equal(g("0", []), "0");130 equal(g("0", [1]), "0");131 equal(g("0", [2]), "0");132 equal(g("0", [200]), "0");133 equal(g("12345678", [0], '.'), '12345678');134 equal(g("", [1], '.'), '');135 equal(g("12345678", [1], '.'), '1234567.8');136 equal(g("12345678", [1], '.'), '1234567.8');137 equal(g("12345678", [2], '.'), '123456.78');138 equal(g("12345678", [2, 1], '.'), '12345.6.78');139 equal(g("12345678", [2, 0], '.'), '12.34.56.78');140 equal(g("12345678", [-1, 2], '.'), '12345678');141 equal(g("12345678", [2, -1], '.'), '123456.78');142 equal(g("12345678", [2, 0, 1], '.'), '12.34.56.78');143 equal(g("12345678", [2, 0, 0], '.'), '12.34.56.78');144 equal(g("12345678", [2, 0, -1], '.'), '12.34.56.78');145 equal(g("12345678", [3,3,3,3], '.'), '12.345.678');146 equal(g("12345678", [3,0], '.'), '12.345.678');147 });148 test('format_integer', function (instance) {149 instance.web._t.database.parameters.grouping = [3, 3, 3, 3];150 equal(instance.web.format_value(1000000, {type: 'integer'}),151 '1,000,000');152 instance.web._t.database.parameters.grouping = [3, 2, -1];153 equal(instance.web.format_value(106500, {type: 'integer'}),154 '1,06,500');155 instance.web._t.database.parameters.grouping = [1, 2, -1];156 equal(instance.web.format_value(106500, {type: 'integer'}),157 '106,50,0');158 });159 test('format_float', function (instance) {160 instance.web._t.database.parameters.grouping = [3, 3, 3, 3];161 equal(instance.web.format_value(1000000, {type: 'float'}),162 '1,000,000.00');163 instance.web._t.database.parameters.grouping = [3, 2, -1];164 equal(instance.web.format_value(106500, {type: 'float'}),165 '1,06,500.00');166 instance.web._t.database.parameters.grouping = [1, 2, -1];167 equal(instance.web.format_value(106500, {type: 'float'}),168 '106,50,0.00');169 _.extend(instance.web._t.database.parameters, {170 grouping: [3, 0],171 decimal_point: ',',172 thousands_sep: '.'173 });174 equal(instance.web.format_value(6000, {type: 'float'}),175 '6.000,00');176 });177});178openerp.testing.section('web-formats', {179 dependencies: ['web.formats']180}, function (test) {181 test('format stripper', function (instance) {182 strictEqual(instance.web.strip_raw_chars('%a, %Y %b %d'),183 '%a, %Y %b %d');184 strictEqual(instance.web.strip_raw_chars('%a, %Y.eko %bren %da'),185 '%a, %Y. %b %d');186 });187 test('ES date format', function (instance) {188 instance.web._t.database.parameters.date_format = '%a, %Y %b %d';189 var date = instance.web.str_to_date("2009-05-04");190 strictEqual(instance.web.format_value(date, {type:"date"}),191 'Mon, 2009 May 04');192 strictEqual(instance.web.parse_value('Mon, 2009 May 04', {type: 'date'}),193 '2009-05-04');194 });195 test('extended ES date format', function (instance) {196 instance.web._t.database.parameters.date_format = '%a, %Y.eko %bren %da';197 var date = instance.web.str_to_date("2009-05-04");198 strictEqual(instance.web.format_value(date, {type:"date"}),199 'Mon, 2009. May 04');200 strictEqual(instance.web.parse_value('Mon, 2009. May 04', {type: 'date'}),201 '2009-05-04');202 });...
test_templatetags.py
Source:test_templatetags.py
...26 def test_format_value_boolean_or_none(self):27 """28 Tests format_value with booleans and None29 """30 self.assertEqual(format_value(True), '<code>true</code>')31 self.assertEqual(format_value(False), '<code>false</code>')32 self.assertEqual(format_value(None), '<code>null</code>')33 def test_format_value_hyperlink(self):34 url = 'http://url.com'35 name = 'name_of_url'36 hyperlink = Hyperlink(url, name)37 self.assertEqual(format_value(hyperlink), '<a href=%s>%s</a>' % (url, name))38 def test_format_value_list(self):39 """40 Tests format_value with a list of strings41 """42 list_items = ['item1', 'item2', 'item3']43 self.assertEqual(format_value(list_items), '\n item1, item2, item3\n')44 self.assertEqual(format_value([]), '\n\n')45 def test_format_value_table(self):46 """47 Tests format_value with a list of lists/dicts48 """49 list_of_lists = [['list1'], ['list2'], ['list3']]50 expected_list_format = """51 <tableclass="tabletable-striped">52 <tbody>53 <tr>54 <th>0</th>55 <td>list1</td>56 </tr>57 <tr>58 <th>1</th>59 <td>list2</td>60 </tr>61 <tr>62 <th>2</th>63 <td>list3</td>64 </tr>65 </tbody>66 </table>"""67 self.assertEqual(68 format_html(format_value(list_of_lists)),69 format_html(expected_list_format)70 )71 expected_dict_format = """72 <tableclass="tabletable-striped">73 <tbody>74 <tr>75 <th>0</th>76 <td></td>77 </tr>78 <tr>79 <th>1</th>80 <td></td>81 </tr>82 <tr>83 <th>2</th>84 <td></td>85 </tr>86 </tbody>87 </table>"""88 list_of_dicts = [{'item1': 'value1'}, {'item2': 'value2'}, {'item3': 'value3'}]89 self.assertEqual(90 format_html(format_value(list_of_dicts)),91 format_html(expected_dict_format)92 )93 def test_format_value_simple_string(self):94 """95 Tests format_value with a simple string96 """97 simple_string = 'this is an example of a string'98 self.assertEqual(format_value(simple_string), simple_string)99 def test_format_value_string_hyperlink(self):100 """101 Tests format_value with a url102 """103 url = 'http://www.example.com'104 self.assertEqual(format_value(url), '<a href="http://www.example.com">http://www.example.com</a>')105 def test_format_value_string_email(self):106 """107 Tests format_value with an email address108 """109 email = 'something@somewhere.com'110 self.assertEqual(format_value(email), '<a href="mailto:something@somewhere.com">something@somewhere.com</a>')111 def test_format_value_string_newlines(self):112 """113 Tests format_value with a string with newline characters114 :return:115 """116 text = 'Dear user, \n this is a message \n from,\nsomeone'117 self.assertEqual(format_value(text), '<pre>Dear user, \n this is a message \n from,\nsomeone</pre>')118 def test_format_value_object(self):119 """120 Tests that format_value with a object returns the object's __str__ method121 """122 obj = object()123 self.assertEqual(format_value(obj), obj.__str__())124 def test_add_nested_class(self):125 """126 Tests that add_nested_class returns the proper class127 """128 positive_cases = [129 [['item']],130 [{'item1': 'value1'}],131 {'item1': 'value1'}132 ]133 negative_cases = [134 ['list'],135 '',136 None,137 True,...
test_jinja_filters.py
Source:test_jinja_filters.py
1from datetime import datetime2from unittest import TestCase3from mock import Mock4from app.jinja_filters import format_date, format_currency, format_multilined_string, format_percentage5from app.jinja_filters import format_household_member_name6from app.jinja_filters import format_str_as_date7from app.jinja_filters import format_str_as_date_range8from app.jinja_filters import format_str_as_month_year_date9class TestJinjaFilters(TestCase):10 def test_format_currency(self):11 # Given12 currency = 1.1213 # When14 format_value = format_currency(currency)15 self.assertEqual(format_value, '£1.12')16 def test_format_multilined_string_matches_carriage_return(self):17 # Given18 new_line = 'this is on a new\rline'19 context = Mock()20 context.autoescape = False21 # When22 format_value = format_multilined_string(context, new_line)23 self.assertEqual(format_value, '<p>this is on a new<br>line</p>')24 def test_format_multilined_string_matches_new_line(self):25 # Given26 new_line = 'this is on a new\nline'27 context = Mock()28 context.autoescape = False29 # When30 format_value = format_multilined_string(context, new_line)31 self.assertEqual(format_value, '<p>this is on a new<br>line</p>')32 def test_format_multilined_string_matches_carriage_return_new_line(self):33 # Given34 new_line = 'this is on a new\r\nline'35 context = Mock()36 context.autoescape = False37 # When38 format_value = format_multilined_string(context, new_line)39 self.assertEqual(format_value, '<p>this is on a new<br>line</p>')40 def test_format_multilined_string(self):41 # Given42 new_line = 'this is\ron a\nnew\r\nline'43 context = Mock()44 context.autoescape = False45 # When46 format_value = format_multilined_string(context, new_line)47 self.assertEqual(format_value, '<p>this is<br>on a<br>new<br>line</p>')48 def test_format_multilined_string_auto_escape(self):49 # Given50 new_line = '<'51 context = Mock()52 context.autoescape = True53 # When54 format_value = format_multilined_string(context, new_line)55 self.assertEqual(str(format_value), '<p><</p>')56 def test_format_date(self):57 # Given58 date = datetime.strptime('01/01/17', '%d/%m/%y')59 # When60 format_value = format_date(date)61 self.assertEqual(format_value, '1 January 2017')62 def test_format_str_as_date_range(self):63 # Given64 date_range = {'from': '01/01/2017',65 'to': '01/01/2018'}66 # When67 format_value = format_str_as_date_range(date_range)68 self.assertEqual(format_value, '01 January 2017 to 01 January 2018')69 def test_format_str_as_month_year_date(self):70 # Given71 month_year_date = '3/2018'72 # When73 format_value = format_str_as_month_year_date(month_year_date)74 self.assertEqual(format_value, 'March 2018')75 def test_format_str_as_date(self):76 # Given77 date = '02/03/2017'78 # When79 format_value = format_str_as_date(date)80 self.assertEqual(format_value, '02 March 2017')81 def test_format_household_member_name(self):82 # Given83 name = ['John', 'Doe']84 # When85 format_value = format_household_member_name(name)86 self.assertEqual(format_value, 'John Doe')87 def test_format_household_member_name_no_surname(self):88 # Given89 name = ['John', '']90 # When91 format_value = format_household_member_name(name)92 self.assertEqual(format_value, 'John')93 def test_format_household_member_name_surname_is_none(self):94 # Given95 name = ['John', None]96 # When97 format_value = format_household_member_name(name)98 self.assertEqual(format_value, 'John')99 def test_format_household_member_name_no_first_name(self):100 # Given101 name = ['', 'Doe']102 # When103 format_value = format_household_member_name(name)104 self.assertEqual(format_value, 'Doe')105 def test_format_household_member_name_first_name_is_none(self):106 # Given107 name = [None, 'Doe']108 # When109 format_value = format_household_member_name(name)110 self.assertEqual(format_value, 'Doe')111 def test_format_household_member_name_first_middle_and_last(self):112 # Given113 name = ['John', 'J', 'Doe']114 # When115 format_value = format_household_member_name(name)116 self.assertEqual(format_value, 'John J Doe')117 def test_format_household_member_name_no_middle_name(self):118 # Given119 name = ['John', '', 'Doe']120 # When121 format_value = format_household_member_name(name)122 self.assertEqual(format_value, 'John Doe')123 def test_format_household_member_name_middle_name_is_none(self):124 # Given125 name = ['John', None, 'Doe']126 # When127 format_value = format_household_member_name(name)128 self.assertEqual(format_value, 'John Doe')129 def test_format_household_member_name_trim_spaces(self):130 # Given131 name = ['John ', ' Doe ']132 # When133 format_value = format_household_member_name(name)134 self.assertEqual(format_value, 'John Doe')135 def test_format_percentage(self):136 self.assertEqual(format_percentage('100'), '100%')137 self.assertEqual(format_percentage(100), '100%')...
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!!