-
Notifications
You must be signed in to change notification settings - Fork 323
Описание примеров, keyboard в docs #155
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0eb6d2f
Fixes
Helow19274 24d8e74
README.MD to examples
Helow19274 5bb0fa1
Fix README.md
Helow19274 beeab14
Fix README.md x2
Helow19274 a6a857a
Fix README.md x3
Helow19274 cb89797
Fix README.md x4
Helow19274 eba19e6
Шапка keyboard.py
Helow19274 b6125fd
Немного тестов
Helow19274 7deb5dd
Beautify
Helow19274 70c5f39
test_jsonfig на unittests, Fix README.md x5
Helow19274 8d4f81e
Fix README.md x6
Helow19274 7c3b456
2 раза одно и то же
Helow19274 b828d71
Fix кавычку
Helow19274 dc0b5ea
unittest -> pytest
Helow19274 4befe95
Ещё тест
Helow19274 81e8d4f
Ну и ещё тест
Helow19274 525c202
Fix request_one_param_pool
Helow19274 f9e2092
Fix copyright
Helow19274 598bf88
Docstring'и к общему виду
Helow19274 6a086cd
fix keyboard docstrings
Helow19274 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,17 @@ | ||
| Примеры использования библиотеки vk_api | ||
| ====== | ||
| 'python@vk.com' замените на ваш логин, а 'mypassword' на пароль | ||
|
|
||
| 'bot_api_token' нужно заменить на токен группы | ||
| * [Отправка запросов к API (VkApi)](./simple_example.py) | ||
| * [Загрузка фото (VKUpload)](./upload_photo.py) | ||
| * [Обработка двухфакторной аутентификации](./two_factor_auth.py) | ||
| * [Обработка капчи](./captcha_handle.py) | ||
| * [Работа с пользовательским Long Poll (VkLongpoll)](./longpoll.py) | ||
| * [Работа с оберткой над execute (VkFunction)](./execute_functions.py) | ||
| * [Получение альбомов музыки (VkAudio)](./get_album_audio.py) | ||
| * [Получение аудиозаписей (VkAudio)](./get_all_audio.py) | ||
| * [Составление клавиатуры для бота группы (VkKeyboard)](./keyboard.py) | ||
| * [Получение большого кол-ва объектов (VkTools)](./get_full_wall.py) | ||
| * [Работа с VkRequestsPool](./requests_pool.py) | ||
| * [Работа с прокси и использование таймаутов](./proxies_timeout_retries.py) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,13 @@ | ||
| import os | ||
|
|
||
| import vk_api | ||
|
|
||
| vk = vk_api.VkApi(login=os.environ['LOGIN'], password=os.environ['PASSWORD']) | ||
| vk.auth(token_only=True) | ||
| api = vk.get_api() | ||
|
|
||
|
|
||
| def test_api(): | ||
| user_info = api.users.get(user_ids=1) | ||
| assert isinstance(user_info, list) | ||
| assert user_info[0]['id'] == 1 |
This file contains hidden or 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,16 @@ | ||
| import os | ||
|
|
||
| from vk_api import VkApi | ||
| from vk_api.execute import VkFunction | ||
|
|
||
| vk = VkApi(login=os.environ['LOGIN'], password=os.environ['PASSWORD']) | ||
| vk.auth(token_only=True) | ||
|
|
||
|
|
||
| def test_execute(): | ||
| func_add = VkFunction('return %(x)s + %(y)s;', args=('x', 'y')) | ||
| func_get = VkFunction('return API.users.get(%(values)s)[0]["id"];', | ||
| args=('values',)) | ||
|
|
||
| assert func_add(vk, 2, 6) == 8 | ||
| assert func_get(vk, {'user_ids': 'durov'}) == 1 |
This file contains hidden or 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,37 @@ | ||
| from vk_api import VkKeyboard | ||
| from vk_api.keyboard import KeyboardColor | ||
| from vk_api.utils import sjson_dumps | ||
|
|
||
| KEYBOARD_TEST = { | ||
| 'one_time': False, | ||
| 'buttons': [ | ||
| [ | ||
| { | ||
| 'color': 'default', | ||
| 'action': { | ||
| 'type': 'text', | ||
| 'payload': sjson_dumps({'test': 'some_payload'}), | ||
| 'label': 'Test-1' | ||
| } | ||
| } | ||
| ], | ||
| [] | ||
| ] | ||
| } | ||
|
|
||
| EMPTY_KEYBOARD_TEST = {'one_time': False, 'buttons': []} | ||
|
|
||
|
|
||
| keyboard = VkKeyboard() | ||
|
|
||
|
|
||
| def test_keyboard(): | ||
| keyboard.add_button('Test-1', | ||
| color=KeyboardColor.DEFAULT, | ||
| payload={'test': 'some_payload'}) | ||
| keyboard.add_line() | ||
| assert keyboard.get_keyboard() == sjson_dumps(KEYBOARD_TEST) | ||
|
|
||
|
|
||
| def test_empty_keyboard(): | ||
| assert keyboard.get_empty_keyboard() == sjson_dumps(EMPTY_KEYBOARD_TEST) |
This file contains hidden or 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,31 @@ | ||
| import os | ||
|
|
||
| from vk_api import VkApi, VkRequestsPool, vk_request_one_param_pool | ||
|
|
||
| vk = VkApi(login=os.environ['LOGIN'], password=os.environ['PASSWORD']) | ||
| vk.auth(token_only=True) | ||
|
|
||
|
|
||
| def test_requests_pool(): | ||
| with VkRequestsPool(vk) as pool: | ||
| users = pool.method('users.get', {'user_ids': 'durov'}) | ||
| error_request = pool.method('invalid.method') | ||
|
|
||
| assert users.ok | ||
| assert isinstance(users.result, list) | ||
| assert users.result[0]['id'] == 1 | ||
|
|
||
| assert not error_request.ok | ||
|
|
||
|
|
||
| def test_requests_pool_one_param(): | ||
| users, error = vk_request_one_param_pool(vk, | ||
| 'users.get', | ||
| key='user_ids', | ||
| values=['durov', 'python273'], | ||
| default_values={'fields': 'city'}) | ||
|
Owner
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. такое форматирование лучше поменять на |
||
|
|
||
| assert error == {} | ||
| assert isinstance(users, dict) | ||
| assert users['durov'][0]['city']['id'] == 2 | ||
| assert users['python273'][0]['id'] == 183433824 | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Отдельным PR можно переделать через fixtures: https://docs.pytest.org/en/latest/fixture.html#fixtures