-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Поддержка Python 3 #5
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,31 @@ | ||
*.py[co] | ||
|
||
# Packages | ||
*.egg | ||
*.egg-info | ||
dist | ||
MANIFEST | ||
*.pyc | ||
vkontakte.egg-info | ||
build | ||
eggs | ||
parts | ||
bin | ||
var | ||
sdist | ||
develop-eggs | ||
.installed.cfg | ||
|
||
# Installer logs | ||
pip-log.txt | ||
|
||
# Unit test / coverage reports | ||
.coverage | ||
.tox | ||
|
||
#Translations | ||
*.mo | ||
|
||
#Mr Developer | ||
.mr.developer.cfg | ||
|
||
#Other files | ||
*sublime* | ||
.DS_Store |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
[tox] | ||
envlist = py25,py26,py27,pypy | ||
envlist = py26,py27,py33,pypy | ||
|
||
[testenv] | ||
deps= | ||
mock == 1.0.1 | ||
requests | ||
|
||
commands= | ||
python vkontakte/tests.py | ||
|
||
[testenv:py25] | ||
deps= | ||
mock == 1.0.1 | ||
simplejson | ||
|
||
[testenv:py26] | ||
deps= | ||
mock == 1.0.1 | ||
simplejson | ||
simplejson | ||
requests |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,21 +7,24 @@ | |
|
||
import os | ||
import sys | ||
import urllib | ||
sys.path.insert(0, os.path.abspath('..')) | ||
|
||
import unittest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Без sys.path.insert тесты, запущенные не через tox, могут импортировать глобально установленный vkontakte вместо того, что у нас тут. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вернул на место. |
||
|
||
import mock | ||
|
||
import vkontakte | ||
import vkontakte.api | ||
|
||
|
||
API_ID = 'api_id' | ||
API_SECRET = 'api_secret' | ||
|
||
|
||
class VkontakteTest(unittest.TestCase): | ||
def test_api_creation_error(self): | ||
self.assertRaises(ValueError, lambda: vkontakte.API()) | ||
|
||
|
||
class SignatureTest(unittest.TestCase): | ||
def test_signature_supports_unicode(self): | ||
params = {'foo': u'клен'} | ||
|
@@ -30,6 +33,7 @@ def test_signature_supports_unicode(self): | |
'560b3f1e09ff65167b8dc211604fed2b' | ||
) | ||
|
||
|
||
class IterparseTest(unittest.TestCase): | ||
def test_iterparse(self): | ||
data = '{"error":{"error_code":8,"error_msg":"Invalid request: this auth method is obsolete, please use oauth. vk.com\/developers","request_params":[{"key":"sig","value":"97aasff03cc81d5db25de67893e207"},{"key":"uids","value":"1,2"},{"key":"timestamp","value":"1355095295"},{"key":"v","value":"3.0"},{"key":"fields","value":"education"},{"key":"format","value":"JSON"},{"key":"random","value":"937530097"},{"key":"method","value":"getProfiles"},{"key":"api_id","value":"3267523"}]}}{"error":{"error_code":8,"error_msg":"Invalid request: this auth method is obsolete, please use oauth. vk.com\/developers","request_params":[{"key":"sig","value":"97aasff03cc81d5db25de67893e207"},{"key":"uids","value":"1,2"},{"key":"timestamp","value":"1355095295"},{"key":"v","value":"3.0"},{"key":"fields","value":"education"},{"key":"format","value":"JSON"},{"key":"random","value":"937530097"},{"key":"method","value":"getProfiles"},{"key":"api_id","value":"3267523"}]}}{"response":[{"uid":1,"first_name":"Павел","last_name":"Дуров","university":1,"university_name":"СПбГУ","faculty":15,"faculty_name":"Филологический","graduation":2006},{"uid":2,"first_name":"Александра","last_name":"Владимирова"}]}' | ||
|
@@ -46,7 +50,6 @@ def test_iterparse_edge(self): | |
self.assertEqual(parses[1]["foo"], "bar") | ||
|
||
|
||
|
||
class VkontakteMagicTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
|
@@ -73,14 +76,6 @@ def test_with_arguments_get(self, _get): | |
self.assertEqual(res, _get.return_value) | ||
_get.assert_called_once_with('getProfiles', vkontakte.api.DEFAULT_TIMEOUT, uids='1,2', fields='education') | ||
|
||
@mock.patch('vkontakte.http.post') | ||
def test_timeout(self, post): | ||
post.return_value = 200, '{"response":123}' | ||
api = vkontakte.API(API_ID, API_SECRET, timeout=5) | ||
res = api.getServerTime() | ||
self.assertEqual(res, 123) | ||
self.assertEqual(post.call_args[0][3], 5) | ||
|
||
@mock.patch('vkontakte.api._API._get') | ||
def test_magic(self, _get): | ||
for method in vkontakte.api.COMPLEX_METHODS: | ||
|
@@ -97,18 +92,6 @@ def test_magic_get(self, _get): | |
self.assertEqual(res, 'foo') | ||
_get.assert_called_once_with('friends.get', uid=642177) | ||
|
||
@mock.patch('vkontakte.http.post') | ||
def test_urlencode_bug(self, post): | ||
post.return_value = 200, '{"response":123}' | ||
res = self.api.search(q=u'клен') | ||
self.assertEqual(res, 123) | ||
|
||
@mock.patch('vkontakte.http.post') | ||
def test_valid_quoted_json(self, post): | ||
post.return_value = 200, '{"response": 123}' | ||
self.api.ads.getStat(data={'type': '1', 'id': 1}) | ||
posted_data = urllib.unquote(post.call_args[0][1]) | ||
self.assertTrue('data={"type":+"1",+"id":+1}' in posted_data, posted_data) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() | ||
unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А как requests справляется с корявым ответом ВКонтакте, который отдает 2 json-ответа в одном? В первом - ошибка, во втором - собственно ответ (это проверял удаленный тест IterparseTest). Или там что-то изменилось у ВКонтакте и они совсем старый метод авторизации отрубили? См. #3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Справлялся плохо, вернул к старому состоянию плюс оставил тест который уже был.