| 
									
										
										
										
											2022-09-28 09:35:12 +00:00
										 |  |  | from moto.moto_api._internal import mock_random | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_semi_random_uuids(): | 
					
						
							|  |  |  |     # Create random UUID first | 
					
						
							|  |  |  |     random_uuid = str(mock_random.uuid4()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Seed our generator - the next generation should be predetermined | 
					
						
							|  |  |  |     mock_random.seed(42) | 
					
						
							|  |  |  |     fixed_uuid = str(mock_random.uuid4()) | 
					
						
							| 
									
										
										
										
											2023-08-15 07:45:57 +00:00
										 |  |  |     assert fixed_uuid == "bdd640fb-0667-4ad1-9c80-317fa3b1799d" | 
					
						
							| 
									
										
										
										
											2022-09-28 09:35:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Ensure they are different | 
					
						
							| 
									
										
										
										
											2023-08-15 07:45:57 +00:00
										 |  |  |     assert fixed_uuid != random_uuid | 
					
						
							| 
									
										
										
										
											2022-09-28 09:35:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Retrieving another 'fixed' UUID should not return a known UUID | 
					
						
							|  |  |  |     second_fixed = str(mock_random.uuid4()) | 
					
						
							| 
									
										
										
										
											2023-08-15 07:45:57 +00:00
										 |  |  |     assert second_fixed != random_uuid | 
					
						
							|  |  |  |     assert second_fixed != fixed_uuid | 
					
						
							| 
									
										
										
										
											2022-09-28 09:35:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_semi_random_hex_strings(): | 
					
						
							|  |  |  |     # Create random HEX first | 
					
						
							|  |  |  |     random_hex = mock_random.get_random_hex() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Seed our generator - the next generation should be predetermined | 
					
						
							|  |  |  |     mock_random.seed(42) | 
					
						
							|  |  |  |     fixed_hex = mock_random.get_random_hex() | 
					
						
							| 
									
										
										
										
											2023-08-15 07:45:57 +00:00
										 |  |  |     assert fixed_hex == "30877432" | 
					
						
							| 
									
										
										
										
											2022-09-28 09:35:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Ensure they are different | 
					
						
							| 
									
										
										
										
											2023-08-15 07:45:57 +00:00
										 |  |  |     assert fixed_hex != random_hex | 
					
						
							| 
									
										
										
										
											2022-09-28 09:35:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-10 09:39:55 +02:00
										 |  |  |     # Retrieving another 'fixed' HEX should not return a known HEX | 
					
						
							|  |  |  |     second_hex = mock_random.get_random_hex() | 
					
						
							| 
									
										
										
										
											2023-08-15 07:45:57 +00:00
										 |  |  |     assert second_hex != random_hex | 
					
						
							|  |  |  |     assert second_hex != fixed_hex | 
					
						
							| 
									
										
										
										
											2023-10-10 09:39:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_semi_random_token_urlsafe(): | 
					
						
							|  |  |  |     mock_random.seed(42) | 
					
						
							|  |  |  |     token = mock_random.token_urlsafe(32) | 
					
						
							|  |  |  |     assert token == "nXmxo38xgBzRGmcG-0DWvVdSaEaQO7E-3lYkOenBuCM" |