def test_without_from_tag(self): """Test without from_tag supplied. This makes the validator a no-op.""" del self.request.validated['from_tag'] validators.validate_from_tag(self.request) assert not self.request.errors
def test_without_sidetag(self): """A tag that is not a sidetag should add an error to the request""" self.request.validated['from_tag'] = 'no-side-tag' validators.validate_from_tag(self.request) assert self.request.errors == [ {'location': 'body', 'name': 'from_tag', 'description': "The supplied tag is not a side tag."} ]
def test_known_without_builds(self): """Test with known from_tag but without builds in request.validated. This test expects that builds_from_tag is set to True, and builds are filled after calling the validator.""" validators.validate_from_tag(self.request) assert self.request.validated['builds_from_tag'] == True assert len(self.request.validated['builds']) assert not self.request.errors
def test_with_unknown_tag(self): """Test to prevent users to create an update from a tag that doesn't exist""" with mock.patch('bodhi.server.validators.buildsys.get_session', self.mock_get_session_for_class(self.UnknownTagDevBuildsys)): validators.validate_from_tag(self.request) assert self.request.errors == [ {'location': 'body', 'name': 'from_tag', 'description': "The supplied from_tag doesn't exist."} ]
def test_known_with_builds(self): """Test with known from_tag and with builds set in request.validated. This test expects that builds_from_tag is set to False after calling the validator.""" self.request.validated['builds'] = ['foo-1-1'] validators.validate_from_tag(self.request) assert self.request.validated['builds_from_tag'] == False assert not self.request.errors
def test_unknown_koji_genericerror(self): """An unknown koji.GenericError should be wrapped.""" with pytest.raises(BodhiException) as excinfo: with mock.patch('bodhi.server.validators.buildsys.get_session', self.mock_get_session_for_class(self.UnknownKojiGenericError)): validators.validate_from_tag(self.request) assert (str(excinfo.value) == "Encountered error while requesting tagged builds from Koji: 'foo'") # check type of wrapped exception assert isinstance(excinfo.value.__cause__, koji.GenericError)
def test_unknown_without_builds(self): """An unknown from_tag should add an error to the request. This test runs without a list of fills in request.validated.""" with mock.patch('bodhi.server.validators.buildsys.get_session', self.mock_get_session_for_class(self.UnknownTagDevBuildsys)): validators.validate_from_tag(self.request) assert self.request.errors == [ {'location': 'body', 'name': 'from_tag', 'description': "The supplied from_tag doesn't exist."} ]
def test_known_with_empty_builds(self): """Test with known from_tag but with empty builds in request.validated. This test expects an appropriate error to be added.""" with mock.patch('bodhi.server.validators.buildsys.get_session', self.mock_get_session_for_class(self.NoBuildsDevBuildsys)): validators.validate_from_tag(self.request) assert self.request.errors == [ {'location': 'body', 'name': 'from_tag', 'description': "The supplied from_tag doesn't contain any builds."} ]