def setUp(self):
     self.endpoint = 'http://softlayer.com/v1/account/queues/queue_name'
     self.queue_name = 'queue_name'
     self.message_id = 'message_id'
     self.base_href = "%s/messages/%s" % (self.endpoint, self.message_id)
     self.auth = Mock()
     self.message = Message(self.endpoint, self.queue_name, self.message_id, self.auth)
class TestMessage(unittest.TestCase):
    def setUp(self):
        self.endpoint = 'http://softlayer.com/v1/account/queues/queue_name'
        self.queue_name = 'queue_name'
        self.message_id = 'message_id'
        self.base_href = "%s/messages/%s" % (self.endpoint, self.message_id)
        self.auth = Mock()
        self.message = Message(self.endpoint, self.queue_name, self.message_id, self.auth)

    @patch('requests.request')
    def test_request(self, res):
        header_resp = Mock()
        res.return_value.error = None
        res.return_value.status_code = 200
        res.return_value.content = '{"some": "json"}'
        res.return_value.headers = header_resp
        self.message.headers = {'test': Mock()}
        result = self.message.request('DELETE')
        self.assertEqual(result.json, {'some': 'json'})
        self.assertEqual(result.headers, header_resp)

        res.assert_called_with(
            'DELETE', self.base_href,
            headers=self.message.headers, auth=self.auth)

    def test_client_init(self):
        self.assertEquals(self.message.url, self.base_href)
        self.assertEquals(self.message.queue_name, self.queue_name)
        self.assertEquals(self.message.id, self.message_id)
        self.assertEquals(self.message.auth, self.auth)

    @patch('softlayer_messaging.queue.Message.request')
    def test_delete_message(self, res):
        result = self.message.delete()
        res.assert_called_with('DELETE')
        self.assertEqual(result, True)

    def test_repr(self):
        self.message.url = "URL"
        value = repr(self.message)
        self.assertEqual(value, "<Message [URL]>")