-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix empty result * Remove unused namedtuple
- Loading branch information
1 parent
6c6176e
commit cbfcb7b
Showing
2 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from collections import namedtuple | ||
from mock import patch | ||
import unittest | ||
|
||
from requests.models import Response | ||
from six import BytesIO | ||
|
||
from pydruid.db.api import Cursor | ||
|
||
|
||
class CursorTestSuite(unittest.TestCase): | ||
|
||
@patch('requests.post') | ||
def test_execute(self, requests_post_mock): | ||
response = Response() | ||
response.status_code = 200 | ||
response.raw = BytesIO(b'[{"name": "alice"}, {"name": "bob"}, {"name": "charlie"}]') | ||
requests_post_mock.return_value = response | ||
Row = namedtuple('Row', ['name']) | ||
|
||
cursor = Cursor('http://example.com/') | ||
cursor.execute('SELECT * FROM table') | ||
result = cursor.fetchall() | ||
expected = [ | ||
Row(name='alice'), | ||
Row(name='bob'), | ||
Row(name='charlie'), | ||
] | ||
self.assertEquals(result, expected) | ||
|
||
@patch('requests.post') | ||
def test_execute_empty_result(self, requests_post_mock): | ||
response = Response() | ||
response.status_code = 200 | ||
response.raw = BytesIO(b'[]') | ||
requests_post_mock.return_value = response | ||
|
||
cursor = Cursor('http://example.com/') | ||
cursor.execute('SELECT * FROM table') | ||
result = cursor.fetchall() | ||
expected = [] | ||
self.assertEquals(result, expected) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |