@@ -341,6 +341,90 @@ def test_make_tables_with_force_enabled(
341341 mock_make_tables .reset_mock ()
342342 mock_path .reset_mock ()
343343
344+ @patch ("datafaker.main.Path" )
345+ @patch ("datafaker.settings.get_settings" )
346+ def test_incorrect_dialect_causes_nice_error_message (
347+ self ,
348+ mock_get_settings : MagicMock ,
349+ mock_path : MagicMock ,
350+ ) -> None :
351+ """Test the make-tables sub-command, when the force option is activated."""
352+ mock_get_settings .return_value = Settings (
353+ # postgres: not postgresql: will cause sqlalchemy to fail to connect
354+ src_dsn = "postgres://suser:spassword@shost:5432/sdbname" ,
355+ dst_dsn = "postgresql://duser:dpassword@dhost:5432/ddbname" ,
356+ # To stop any local .env files influencing the test
357+ # The mypy ignore can be removed once we upgrade to pydantic 2.
358+ _env_file = None , # type: ignore[call-arg]
359+ )
360+ mock_path .return_value .exists .return_value = True
361+
362+ result = runner .invoke (
363+ app ,
364+ [
365+ "make-tables" ,
366+ "--force" ,
367+ "--orm-file=tests/examples/example_orm.yaml" ,
368+ ],
369+ )
370+ self .assertIs (type (result .exception ), SystemExit )
371+
372+ @patch ("datafaker.main.Path" )
373+ @patch ("datafaker.settings.get_settings" )
374+ def test_invalid_host_causes_nice_error_message (
375+ self ,
376+ mock_get_settings : MagicMock ,
377+ mock_path : MagicMock ,
378+ ) -> None :
379+ """Test the make-tables sub-command, when the force option is activated."""
380+ mock_get_settings .return_value = Settings (
381+ # postgres: not postgresql: will cause sqlalchemy to fail to connect
382+ src_dsn = "postgresql://suser:spassword@invalid_host:5432/sdbname" ,
383+ dst_dsn = "postgresql://duser:dpassword@dhost:5432/ddbname" ,
384+ # To stop any local .env files influencing the test
385+ # The mypy ignore can be removed once we upgrade to pydantic 2.
386+ _env_file = None , # type: ignore[call-arg]
387+ )
388+ mock_path .return_value .exists .return_value = True
389+
390+ result = runner .invoke (
391+ app ,
392+ [
393+ "make-tables" ,
394+ "--force" ,
395+ "--orm-file=tests/examples/example_orm.yaml" ,
396+ ],
397+ )
398+ self .assertIs (type (result .exception ), SystemExit )
399+
400+ @patch ("datafaker.main.Path" )
401+ @patch ("datafaker.settings.get_settings" )
402+ def test_incorrect_dsn_causes_nice_error_message (
403+ self ,
404+ mock_get_settings : MagicMock ,
405+ mock_path : MagicMock ,
406+ ) -> None :
407+ """Test the make-tables sub-command, when the force option is activated."""
408+ mock_get_settings .return_value = Settings (
409+ # postgres: not postgresql: will cause sqlalchemy to fail to connect
410+ src_dsn = "postgresql://suser:spassword:localhost:5432/sdbname" ,
411+ dst_dsn = "postgresql://duser:dpassword@dhost:5432/ddbname" ,
412+ # To stop any local .env files influencing the test
413+ # The mypy ignore can be removed once we upgrade to pydantic 2.
414+ _env_file = None , # type: ignore[call-arg]
415+ )
416+ mock_path .return_value .exists .return_value = True
417+
418+ result = runner .invoke (
419+ app ,
420+ [
421+ "make-tables" ,
422+ "--force" ,
423+ "--orm-file=tests/examples/example_orm.yaml" ,
424+ ],
425+ )
426+ self .assertIs (type (result .exception ), SystemExit )
427+
344428 def test_validate_config (self ) -> None :
345429 """Test the validate-config sub-command."""
346430 result = runner .invoke (
0 commit comments