def test_post_uses_default_base_url(self): self.stub_post_requests() client = Client(access_token="abc123") client.post("/messages", body="Hello Yammer") self.assert_post_request("https://www.yammer.com/api/v1/messages.json")
def test_post_uses_custom_base_url(self): self.stub_post_requests() client = Client(access_token="1a2bc3", base_url="http://example.com") client.post("/messages", body="Hello fake Yammer") self.assert_post_request("http://example.com/messages.json")
def test_post_sends_query_string_parameters(self): self.stub_post_requests() client = Client(access_token="456efg") client.post("/messages", body="Oh hai") self.assert_post_request( url="https://www.yammer.com/api/v1/messages.json", params={"body": "Oh hai"}, )
def test_post_sends_authorization_header(self): self.stub_post_requests() client = Client(access_token="abc123") client.post("/messages", body="I am authorized") self.assert_post_request( url="https://www.yammer.com/api/v1/messages.json", headers={"Authorization": "Bearer abc123"}, )
def test_post_parses_response_json(self): self.stub_post_requests( response_body='{"messages": ["first", "second"]}', ) client = Client(access_token="abc123") messages = client.post("/messages", body="Hello world") self.assertEqual(messages.messages, ["first", "second"])
def test_post_handles_created_responses(self): self.stub_post_requests( response_status=201, response_body='{"status": "OK"}', ) client = Client(access_token="456efg") response = client.post("/messages", body="A-OK") self.assertEqual(response, {"status": "OK"})