class TestSubscription(unittest.TestCase):
    def setUp(self):
        self.endpoint = 'http://softlayer.com/v1/account/topics/topic'
        self.sub_id = 'sub_id'
        self.base_href = "%s/subscriptions/%s" % (self.endpoint, self.sub_id)
        self.auth = Mock()
        self.sub = Subscription(self.endpoint, self.sub_id, self.auth)

    def test_client_init(self):
        self.assertEquals(self.sub.url, self.base_href)
        self.assertEquals(self.sub.id, self.sub_id)
        self.assertEquals(self.sub.auth, 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.sub.headers = {'test': Mock()}
        result = self.sub.request('GET', 'path')
        self.assertEqual(result.json, {'some': 'json'})
        self.assertEqual(result.headers, header_resp)
        res.assert_called_with(
            'GET', '%s/path' % (self.base_href,),
            headers=self.sub.headers, auth=self.auth)

    @patch('softlayer_messaging.topic.Subscription.request')
    def test_delete_subscription(self, res):
        result = self.sub.delete()
        res.assert_called_with('DELETE')
        self.assertEqual(result, True)

    def test_repr(self):
        self.sub.url = "URL"
        value = repr(self.sub)
        self.assertEqual(value, "<Subscription [URL]>")
 def setUp(self):
     self.endpoint = 'http://softlayer.com/v1/account/topics/topic'
     self.sub_id = 'sub_id'
     self.base_href = "%s/subscriptions/%s" % (self.endpoint, self.sub_id)
     self.auth = Mock()
     self.sub = Subscription(self.endpoint, self.sub_id, self.auth)