def test_access_token_valid(mock_settings_env_vars) -> None: dmpy = Dmpy() dmpy.last_created = int(datetime.utcnow().timestamp()) # act with patch("requests.get"): result = dmpy.get_access_token() assert result == "FAKE_TOKEN_1234"
def test_upload_response_error(mock_settings_env_vars, mock_dmp_upload_response_error, upload_payload, caplog) -> None: dmpy = Dmpy() # Ensures no new token is generated, skipping token's POST auth dmpy.last_created = int(datetime.utcnow().timestamp()) response = MagicMock(json=lambda: mock_dmp_upload_response_error) with patch("requests.post", return_value=response), caplog.at_level(logging.ERROR): result = dmpy.upload(upload_payload) assert result == False assert "UPLOAD_ERROR" in caplog.text