def test_invalid(self, monkeypatch): class FakeMessageVerifier: @staticmethod @pretend.call_recorder def __init__(topics, session): self.topics = topics self.session = session @staticmethod @pretend.call_recorder def verify(message): raise views.sns.InvalidMessage("This is an Invalid Message") monkeypatch.setattr(views.sns, "MessageVerifier", FakeMessageVerifier) request = pretend.stub( http=pretend.stub(), registry=pretend.stub(settings={ "mail.topic": "this is a topic", }, ), ) message = pretend.stub() with pytest.raises(HTTPBadRequest, match="This is an Invalid Message"): views._verify_sns_message(request, message) assert FakeMessageVerifier.__init__.calls == [ pretend.call(topics=["this is a topic"], session=request.http), ] assert FakeMessageVerifier.verify.calls == [pretend.call(message)]
def test_invalid(self, monkeypatch): class FakeMessageVerifier: @staticmethod @pretend.call_recorder def __init__(topics, session): self.topics = topics self.session = session @staticmethod @pretend.call_recorder def verify(message): raise views.sns.InvalidMessage("This is an Invalid Message") monkeypatch.setattr(views.sns, "MessageVerifier", FakeMessageVerifier) request = pretend.stub( http=pretend.stub(), registry=pretend.stub( settings={ "mail.topic": "this is a topic", }, ), ) message = pretend.stub() with pytest.raises(HTTPBadRequest, match="This is an Invalid Message"): views._verify_sns_message(request, message) assert FakeMessageVerifier.__init__.calls == [ pretend.call(topics=["this is a topic"], session=request.http), ] assert FakeMessageVerifier.verify.calls == [pretend.call(message)]
def test_valid(self, monkeypatch): class FakeMessageVerifier: @staticmethod @pretend.call_recorder def __init__(topics, session): self.topics = topics self.session = session @staticmethod @pretend.call_recorder def verify(message): pass monkeypatch.setattr(views.sns, "MessageVerifier", FakeMessageVerifier) request = pretend.stub( http=pretend.stub(), registry=pretend.stub(settings={"mail.topic": "this is a topic"}), ) message = pretend.stub() views._verify_sns_message(request, message) assert FakeMessageVerifier.__init__.calls == [ pretend.call(topics=["this is a topic"], session=request.http) ] assert FakeMessageVerifier.verify.calls == [pretend.call(message)]