Beispiel #1
0
 def test_json_error(self, parse_args: Mock, db_upgrade: Mock,
                     capsys: CaptureFixture) -> None:
     parse_args.return_value.json = True
     db_upgrade.return_value = UpgradeResult(
         VersionResult(123, 45),
         VersionResult(123, 45),
         [],
         FileInfo("foo.sql", "", "", 124, 46),
     )
     with pytest.raises(SystemExit):
         main()
     j = json.loads(capsys.readouterr().out)
     assert j == {
         "success": False,
         "oldVersion": {
             "version": 123,
             "apiLevel": 45
         },
         "newVersion": {
             "version": 123,
             "apiLevel": 45
         },
         "appliedScripts": [],
         "failedScript": {
             "filename": "foo.sql",
             "version": 124,
             "apiLevel": 46,
         },
     }
Beispiel #2
0
 def test_json_success(self, parse_args: Mock, db_upgrade: Mock,
                       capsys: CaptureFixture) -> None:
     parse_args.return_value.json = True
     db_upgrade.return_value = UpgradeResult(
         VersionResult(123, 45),
         VersionResult(124, 46),
         [FileInfo("foo.sql", "", "", 124, 46)],
     )
     main()
     j = json.loads(capsys.readouterr().out)
     assert j == {
         "success":
         True,
         "oldVersion": {
             "version": 123,
             "apiLevel": 45
         },
         "newVersion": {
             "version": 124,
             "apiLevel": 46
         },
         "appliedScripts": [{
             "filename": "foo.sql",
             "version": 124,
             "apiLevel": 46,
         }],
     }
Beispiel #3
0
 def test_no_json_output(self, parse_args: Mock,
                         capsys: CaptureFixture) -> None:
     parse_args.return_value.json = False
     main()
     assert capsys.readouterr().out == ""
Beispiel #4
0
 def test_json_logging(self, logging: Mock, parse_args: Mock) -> None:
     parse_args.return_value.json = True
     main()
     logging.basicConfig.assert_called_once_with(level=logging.ERROR)
Beispiel #5
0
 def test_quiet_logging(self, logging: Mock, parse_args: Mock) -> None:
     parse_args.return_value.quiet = True
     main()
     logging.basicConfig.assert_called_once_with(level=logging.WARNING)
Beispiel #6
0
 def test_default_logging(self, logging: Mock, parse_args: Mock) -> None:
     parse_args.return_value.quiet = False
     parse_args.return_value.json = False
     main()
     logging.basicConfig.assert_called_once_with(level=logging.INFO)
Beispiel #7
0
 def test_error(self, db_upgrade: Mock) -> None:
     db_upgrade.return_value = UpgradeResult(
         vi, vi, [], FileInfo("foo.sql", "", "", 123, 45))
     with pytest.raises(SystemExit) as exc:
         main()
     assert exc.value.code == 1
Beispiel #8
0
 def test_success(self, db_upgrade: Mock) -> None:
     db_upgrade.return_value = UpgradeResult(
         vi, vi, [FileInfo("foo.sql", "", "", 123, 45)])
     main()