def test_delete(self):
        mock_delete = self.mock_object(self.manager, '_delete')
        mock_post = self.mock_object(self.manager.api.client, 'post')

        self.manager.delete(fake.Message())

        mock_delete.assert_called_once_with(messages.RESOURCE_PATH %
                                            fake.Message.id)
        self.assertFalse(mock_post.called)
    def test_list(self):
        fake_message = fake.Message()
        mock_list = self.mock_object(self.manager, '_list',
                                     mock.Mock(return_value=[fake_message]))

        result = self.manager.list()

        self.assertEqual([fake_message], result)
        mock_list.assert_called_once_with(messages.RESOURCES_PATH,
                                          messages.RESOURCES_NAME)
    def test_get(self):
        fake_message = fake.Message()
        mock_get = self.mock_object(self.manager, '_get',
                                    mock.Mock(return_value=fake_message))

        result = self.manager.get(fake.Message.id)

        self.assertIs(fake_message, result)
        mock_get.assert_called_once_with(
            messages.RESOURCE_PATH % fake.Message.id, messages.RESOURCE_NAME)
    def test_list_with_filters(self, filters, filters_path):
        fake_message = fake.Message()
        mock_list = self.mock_object(self.manager, '_list',
                                     mock.Mock(return_value=[fake_message]))

        result = self.manager.list(search_opts=filters)

        self.assertEqual([fake_message], result)
        expected_path = (messages.RESOURCES_PATH + filters_path)
        mock_list.assert_called_once_with(expected_path,
                                          messages.RESOURCES_NAME)
    def test_list_with_sorting(self, key):
        fake_message = fake.Message()
        mock_list = self.mock_object(self.manager, '_list',
                                     mock.Mock(return_value=[fake_message]))

        result = self.manager.list(sort_dir='asc', sort_key=key)

        self.assertEqual([fake_message], result)
        expected_path = (messages.RESOURCES_PATH + '?sort_dir=asc&sort_key=' +
                         key)
        mock_list.assert_called_once_with(expected_path,
                                          messages.RESOURCES_NAME)