def test_post_with_relative_url(self): with responses.RequestsMock() as rsps: rsps.add(responses.POST, 'https://us1.api.mailchimp.com/3.0/instance', json={"Instance": { "Id": 1 }}, status=200, content_type='application/json') response = Request.post('/instance', {"Id": 1}) response_json = response.json() self.assertTrue("Instance" in response_json.keys()) self.assertTrue("Id" in response_json['Instance'].keys()) self.assertEqual(1, response_json['Instance']['Id']) self.assertEqual(1, len(rsps.calls)) self.assertEqual("https://us1.api.mailchimp.com/3.0/instance", rsps.calls[0].request.url) self.assertEqual(json.dumps({"Id": 1}), rsps.calls[0].request.body.decode("utf-8")) self.assertEqual("application/json", rsps.calls[0].request.headers['Accept']) self.assertEqual("application/json", rsps.calls[0].request.headers['Content-Type']) self.assertEqual( "Basic dXNlcm5hbWU6YTY1YTY1YTY1YTY1YTY1YTU2YTVhNi11czE=", rsps.calls[0].request.headers['Authorization'])
def save(self, list_id=None): """ Saves the current member to the list :param list_id: the id of the list to save to - if not specified, the members list_id will be used :return: True if successful """ hash_value = self.id if not list_id: list_id = self.list_id if not self.id: response = Request.post("%s" % MCMember.get_list_url(list_id), self.to_dict()) self._update(response.json()) return True try: response = Request.put( "%s/%s" % (MCMember.get_list_url(list_id), hash_value), self.to_dict()) self._update(response.json()) return True except Exception as e: logger.error("Unable to save member") raise e