Beispiel #1
0
    def delete(self):
        """
        Deletes the current member from the list

        :return: True if sucessful
        """
        if not self.id:
            return False

        try:
            Request.delete("%s/%s" %
                           (MCMember.get_list_url(self.list_id), self.id))
            return True

        except Exception as e:
            logger.error("Unable to delete member from list")
            raise e
    def test_delete_with_relative_url(self):
        with responses.RequestsMock() as rsps:
            rsps.add(responses.DELETE,
                     'https://us1.api.mailchimp.com/3.0/instance/1',
                     status=204,
                     content_type='application/json')

            response = Request.delete('/instance/1')
            self.assertEqual(response.status_code, 204)
            self.assertEqual(b'', response.content)

            self.assertEqual(1, len(rsps.calls))
            self.assertEqual("https://us1.api.mailchimp.com/3.0/instance/1",
                             rsps.calls[0].request.url)
            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'])