| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  | import sure  # noqa # pylint: disable=unused-import | 
					
						
							| 
									
										
										
										
											2013-03-05 08:14:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 17:24:26 +01:00
										 |  |  | from unittest.mock import patch | 
					
						
							| 
									
										
										
										
											2014-03-30 12:05:38 -04:00
										 |  |  | from moto.server import main, create_backend_app, DomainDispatcherApplication | 
					
						
							| 
									
										
										
										
											2013-03-05 08:14:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_wrong_arguments(): | 
					
						
							|  |  |  |     try: | 
					
						
							| 
									
										
										
										
											2013-06-25 12:42:24 -04:00
										 |  |  |         main(["name", "test1", "test2", "test3"]) | 
					
						
							| 
									
										
										
										
											2013-03-05 08:14:43 -05:00
										 |  |  |         assert False, ( | 
					
						
							|  |  |  |             "main() when called with the incorrect number of args" | 
					
						
							|  |  |  |             " should raise a system exit" | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     except SystemExit: | 
					
						
							|  |  |  |         pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-28 20:15:37 -05:00
										 |  |  | @patch("moto.server.run_simple") | 
					
						
							|  |  |  | def test_right_arguments(run_simple): | 
					
						
							| 
									
										
										
										
											2013-07-26 14:42:32 -04:00
										 |  |  |     main(["s3"]) | 
					
						
							| 
									
										
										
										
											2013-12-28 20:15:37 -05:00
										 |  |  |     func_call = run_simple.call_args[0] | 
					
						
							| 
									
										
										
										
											2016-09-01 12:05:34 +01:00
										 |  |  |     func_call[0].should.equal("127.0.0.1") | 
					
						
							| 
									
										
										
										
											2013-12-28 20:15:37 -05:00
										 |  |  |     func_call[1].should.equal(5000) | 
					
						
							| 
									
										
										
										
											2013-06-25 12:42:24 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-28 20:15:37 -05:00
										 |  |  | @patch("moto.server.run_simple") | 
					
						
							|  |  |  | def test_port_argument(run_simple): | 
					
						
							| 
									
										
										
										
											2013-07-26 14:42:32 -04:00
										 |  |  |     main(["s3", "--port", "8080"]) | 
					
						
							| 
									
										
										
										
											2013-12-28 20:15:37 -05:00
										 |  |  |     func_call = run_simple.call_args[0] | 
					
						
							| 
									
										
										
										
											2016-09-01 12:05:34 +01:00
										 |  |  |     func_call[0].should.equal("127.0.0.1") | 
					
						
							| 
									
										
										
										
											2013-12-28 20:15:37 -05:00
										 |  |  |     func_call[1].should.equal(8080) | 
					
						
							| 
									
										
										
										
											2014-03-30 12:05:38 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_domain_dispatched(): | 
					
						
							|  |  |  |     dispatcher = DomainDispatcherApplication(create_backend_app) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     backend_app = dispatcher.get_application( | 
					
						
							|  |  |  |         {"HTTP_HOST": "email.us-east1.amazonaws.com"} | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2014-08-26 13:25:50 -04:00
										 |  |  |     keys = list(backend_app.view_functions.keys()) | 
					
						
							|  |  |  |     keys[0].should.equal("EmailResponse.dispatch") | 
					
						
							| 
									
										
										
										
											2014-03-30 12:05:38 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_domain_dispatched_with_service(): | 
					
						
							|  |  |  |     # If we pass a particular service, always return that. | 
					
						
							|  |  |  |     dispatcher = DomainDispatcherApplication(create_backend_app, service="s3") | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     backend_app = dispatcher.get_application({"HTTP_HOST": "s3.us-east1.amazonaws.com"}) | 
					
						
							| 
									
										
										
										
											2014-08-26 13:25:50 -04:00
										 |  |  |     keys = set(backend_app.view_functions.keys()) | 
					
						
							| 
									
										
										
										
											2022-06-09 17:40:22 +00:00
										 |  |  |     keys.should.contain("S3Response.key_response") |