| 
									
										
										
										
											2015-11-23 14:04:14 +01:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-09 17:38:26 -08:00
										 |  |  | import copy | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 14:14:40 -05:00
										 |  |  | import sure  # noqa | 
					
						
							|  |  |  | from freezegun import freeze_time | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  | from moto.core.utils import ( | 
					
						
							|  |  |  |     camelcase_to_underscores, | 
					
						
							|  |  |  |     underscores_to_camelcase, | 
					
						
							|  |  |  |     unix_time, | 
					
						
							| 
									
										
										
										
											2019-12-09 17:38:26 -08:00
										 |  |  |     py2_strip_unicode_keys, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2015-11-23 14:04:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_camelcase_to_underscores(): | 
					
						
							|  |  |  |     cases = { | 
					
						
							|  |  |  |         "theNewAttribute": "the_new_attribute", | 
					
						
							|  |  |  |         "attri bute With Space": "attribute_with_space", | 
					
						
							|  |  |  |         "FirstLetterCapital": "first_letter_capital", | 
					
						
							| 
									
										
										
										
											2017-03-15 23:39:36 -04:00
										 |  |  |         "ListMFADevices": "list_mfa_devices", | 
					
						
							| 
									
										
										
										
											2015-11-23 14:04:14 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     for arg, expected in cases.items(): | 
					
						
							|  |  |  |         camelcase_to_underscores(arg).should.equal(expected) | 
					
						
							| 
									
										
										
										
											2015-11-23 14:09:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_underscores_to_camelcase(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     cases = {"the_new_attribute": "theNewAttribute"} | 
					
						
							| 
									
										
										
										
											2015-11-23 14:09:31 +01:00
										 |  |  |     for arg, expected in cases.items(): | 
					
						
							|  |  |  |         underscores_to_camelcase(arg).should.equal(expected) | 
					
						
							| 
									
										
										
										
											2015-11-27 14:14:40 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @freeze_time("2015-01-01 12:00:00") | 
					
						
							|  |  |  | def test_unix_time(): | 
					
						
							|  |  |  |     unix_time().should.equal(1420113600.0) | 
					
						
							| 
									
										
										
										
											2019-12-09 17:38:26 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if sys.version_info[0] < 3: | 
					
						
							|  |  |  |     # Tests for unicode removals (Python 2 only) | 
					
						
							|  |  |  |     def _verify_no_unicode(blob): | 
					
						
							|  |  |  |         """Verify that no unicode values exist""" | 
					
						
							|  |  |  |         if type(blob) == dict: | 
					
						
							|  |  |  |             for key, value in blob.items(): | 
					
						
							|  |  |  |                 assert type(key) != unicode | 
					
						
							|  |  |  |                 _verify_no_unicode(value) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         elif type(blob) in [list, set]: | 
					
						
							|  |  |  |             for item in blob: | 
					
						
							|  |  |  |                 _verify_no_unicode(item) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         assert blob != unicode | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_py2_strip_unicode_keys(): | 
					
						
							|  |  |  |         bad_dict = { | 
					
						
							|  |  |  |             "some": "value", | 
					
						
							|  |  |  |             "a": {"nested": ["List", "of", {"unicode": "values"}]}, | 
					
						
							|  |  |  |             "and a": {"nested", "set", "of", 5, "values"}, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         result = py2_strip_unicode_keys(copy.deepcopy(bad_dict)) | 
					
						
							|  |  |  |         _verify_no_unicode(result) |