|
| 1 | +from unittest import TestCase |
| 2 | +from unittest.mock import patch |
| 3 | +from unittest.mock import Mock |
| 4 | +from tests.utils.helpers import catch_prints |
| 5 | + |
| 6 | + |
| 7 | +TEST_VERSION = "1.0.0b1" |
| 8 | +TEST_NEW_MAJOR_VERSION = "22.2.2" |
| 9 | +TEST_NEW_VERSION = "1.2.2" |
| 10 | + |
| 11 | + |
| 12 | +mock_response_1 = Mock(status_code=200) |
| 13 | +mock_response_1.json.return_value = {"releases": [TEST_NEW_MAJOR_VERSION]} |
| 14 | +mock_get_1 = Mock(return_value=mock_response_1) |
| 15 | + |
| 16 | +mock_response_2 = Mock(status_code=200) |
| 17 | +mock_response_2.json.return_value = {"releases": [TEST_NEW_VERSION]} |
| 18 | +mock_get_2 = Mock(return_value=mock_response_2) |
| 19 | + |
| 20 | + |
| 21 | +class TestVersionCheck(TestCase): |
| 22 | + |
| 23 | + @patch('superannotate.version.__version__', TEST_VERSION) |
| 24 | + @patch("requests.get", mock_get_1) |
| 25 | + def test_dev_version_first_info_log(self): |
| 26 | + with catch_prints() as out: |
| 27 | + import src.superannotate |
| 28 | + import src.superannotate.lib.core as constances |
| 29 | + logs = out.getvalue().split("\n") |
| 30 | + self.assertEqual( |
| 31 | + logs[0], |
| 32 | + "SA-PYTHON-SDK - INFO - " + constances.PACKAGE_VERSION_INFO_MESSAGE.format(TEST_VERSION) |
| 33 | + ) |
| 34 | + |
| 35 | + @patch('superannotate.version.__version__', TEST_VERSION) |
| 36 | + @patch("requests.get", mock_get_1) |
| 37 | + def test_dev_version_major_update(self): |
| 38 | + with catch_prints() as out: |
| 39 | + import src.superannotate |
| 40 | + import src.superannotate.lib.core as constances |
| 41 | + logs = out.getvalue().split("\n") |
| 42 | + self.assertEqual( |
| 43 | + logs[1], |
| 44 | + "SA-PYTHON-SDK - WARNING - " + constances.PACKAGE_VERSION_MAJOR_UPGRADE.format( |
| 45 | + TEST_VERSION, TEST_NEW_MAJOR_VERSION |
| 46 | + ) |
| 47 | + ) |
| 48 | + |
| 49 | + @patch('superannotate.version.__version__', TEST_VERSION) |
| 50 | + @patch("requests.get", mock_get_2) |
| 51 | + def test_dev_version_update(self): |
| 52 | + with catch_prints() as out: |
| 53 | + import src.superannotate |
| 54 | + import src.superannotate.lib.core as constances |
| 55 | + logs = out.getvalue().split("\n") |
| 56 | + self.assertEqual( |
| 57 | + logs[1], |
| 58 | + "SA-PYTHON-SDK - WARNING - " + constances.PACKAGE_VERSION_UPGRADE.format(TEST_VERSION, |
| 59 | + TEST_NEW_VERSION) |
| 60 | + ) |
| 61 | + |
0 commit comments