def test_old_version_live(self): with patch.dict('os.environ', {'FEATURETOOLS_UPDATE_CHECKER': 'TRUE'}): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") featuretools_update_checker.check_version(version='0.7', headers=headers) self.assertEqual(len(w), 1) assert "Featuretools is out-of-date: installed == 0.7, latest == " in str(w[-1].message)
def test_httperror(self, mock_get): mock_get.side_effect = requests.exceptions.HTTPError with patch.dict('os.environ', {'FEATURETOOLS_UPDATE_CHECKER': 'TRUE'}): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") featuretools_update_checker.check_version(version='0.7.1', headers=headers) self.assertEqual(len(w), 0)
def test_non_json_response(self, mock_get): mock_response = Mock() mock_response.content = "Text response" mock_get.return_value = mock_response with patch.dict('os.environ', {'FEATURETOOLS_UPDATE_CHECKER': 'TRUE'}): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") featuretools_update_checker.check_version(headers=headers) self.assertEqual(len(w), 0)
def test_current_version_live(self): # get the current featuretools version from the api data = get_response_json(version='0.7', headers=headers) version = data['version'] with patch.dict('os.environ', {'FEATURETOOLS_UPDATE_CHECKER': 'TRUE'}): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") featuretools_update_checker.check_version(version=version, headers=headers) self.assertEqual(len(w), 0)
def test_bad_response(self, mock_get): mock_response = Mock() http_error = requests.exceptions.HTTPError() mock_response.raise_for_status.side_effect = http_error mock_get.return_value = mock_response with patch.dict('os.environ', {'FEATURETOOLS_UPDATE_CHECKER': 'TRUE'}): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") featuretools_update_checker.check_version(headers=headers) self.assertEqual(len(w), 0)
def test_current_version_mock(self, mock_get): return_json = {"is_latest": True, "upload_time": "Wed, 24 Apr 2019 15:54:56 GMT", "version": "0.7.1"} mock_response = Mock() mock_response.json.return_value = return_json mock_get.return_value = mock_response with patch.dict('os.environ', {'FEATURETOOLS_UPDATE_CHECKER': 'TRUE'}): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") featuretools_update_checker.check_version(version='0.7.1', headers=headers) self.assertEqual(len(w), 0)
def test_old_version_mock(self, mock_get): return_json = {"is_latest": False, "upload_time": "Wed, 24 Apr 2019 15:54:56 GMT", "version": "0.7.1"} mock_response = Mock() mock_response.json.return_value = return_json mock_get.return_value = mock_response with patch.dict('os.environ', {'FEATURETOOLS_UPDATE_CHECKER': 'TRUE'}): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") featuretools_update_checker.check_version(version='0.7', headers=headers) self.assertEqual(len(w), 1) assert "Featuretools is out-of-date: installed == 0.7, latest == 0.7.1" == str(w[-1].message)
def test_environment_variables(self, mock_get): return_json = {"is_latest": False, "upload_time": "Wed, 24 Apr 2019 15:54:56 GMT", "version": "0.7.1"} mock_response = Mock() mock_response.json.return_value = return_json mock_get.return_value = mock_response # this test would fail unless the check is skipped by setting # the FEATURETOOLS_UPDATE_CHECKER environment variable to false for env_value in ['0', 'False', 'false', 'FALSE']: with patch.dict('os.environ', {'FEATURETOOLS_UPDATE_CHECKER': env_value}): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") featuretools_update_checker.check_version(version='0.7', headers=headers) self.assertEqual(len(w), 0)