示例#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,
         },
     }
示例#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,
         }],
     }
示例#3
0
 def test_result_no_files(self, fetch_current_db_versions: Mock,
                          apply_files: Mock) -> None:
     fetch_current_db_versions.return_value = (122, 44)
     apply_files.return_value = ([], None)
     result = db_upgrade(
         "myschema",
         "postgres://localhost/foo",
         "/tmp",
         VersionInfo(),
     )
     assert result == UpgradeResult(VersionResult(122, 44),
                                    VersionResult(122, 44), [], None)
示例#4
0
 def test_result_error(self, fetch_current_db_versions: Mock,
                       apply_files: Mock) -> None:
     file_info1 = FileInfo("foo.sql", "myschema", "", 123, 45)
     file_info2 = FileInfo("foo.sql", "myschema", "", 124, 46)
     fetch_current_db_versions.return_value = (122, 44)
     apply_files.return_value = ([file_info1], file_info2)
     result = db_upgrade(
         "myschema",
         "postgres://localhost/foo",
         "/tmp",
         VersionInfo(),
     )
     assert result == UpgradeResult(
         VersionResult(122, 44),
         VersionResult(123, 45),
         [file_info1],
         file_info2,
     )
示例#5
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
示例#6
0
 def test_success(self, db_upgrade: Mock) -> None:
     db_upgrade.return_value = UpgradeResult(
         vi, vi, [FileInfo("foo.sql", "", "", 123, 45)])
     main()
示例#7
0
 def db_upgrade(self, mocker: MockerFixture) -> Mock:
     return mocker.patch("dbupgrade.main.db_upgrade",
                         return_value=UpgradeResult(vi, vi, []))