def test_validate_old(self): """ Assert that validation returns correct output when the version is older. """ url = "http://testing.url" timeout = (5, 20) # Mock requests_session requests_session = mock.Mock() response = mock.Mock() response.status_code = 200 response.json.return_value = {"version": "1.1", "release": "1.fc34"} requests_session.get.return_value = response # Prepare package package = Package(name="test", version="1.0", distro="Fedora") validator = MDApi(url, requests_session, timeout) result = validator.validate(package) requests_session.get.assert_called_with( url + "/koji/srcpkg/test", timeout=timeout ) assert result["newer"] is False assert result["version"] == "1.1" assert result["release"] == "1.fc34"
def test_validate_response_not_ok(self): """ Assert that validation raises HTTPException when response code is not 200. """ url = "http://testing.url" timeout = (5, 20) # Mock requests_session requests_session = mock.Mock() response = mock.Mock() response.status_code = 500 # Prepare package package = Package(name="test", version="1.0", distro="Fedora") validator = MDApi(url, requests_session, timeout) validator.requests_session.get.return_value = response with pytest.raises(HTTPException) as ex: validator.validate(package) assert ex.value.error_code == 500 assert ( ex.value.message == "Error encountered on request {}/koji/srcpkg/test".format(url) ) requests_session.get.assert_called_with( url + "/koji/srcpkg/test", timeout=timeout )
def test_init(self): """ Assert that mdapi class is initialized successfully. """ url = "http://testing.url" timeout = (5, 20) requests_session = mock.Mock() validator = MDApi(url, requests_session, timeout) assert validator.url == url assert validator.requests_session == requests_session assert validator.timeout == timeout