Skip to content

Commit

Permalink
mark test that require network, skip them in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mkuznets committed Jun 28, 2020
1 parent 22e5ddf commit 7b815ec
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 42 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ jobs:
test:
runs-on: ubuntu-20.04
strategy:
max-parallel: 2
fail-fast: false
matrix:
python-version:
Expand All @@ -34,5 +33,5 @@ jobs:
run: |
cd $GITHUB_WORKSPACE
pip install -e .[tests]
make test
PYTEST_ADDOPTS='-m "not network"' make test
coveralls || true
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SHELL := /usr/bin/env bash

test:
coverage run --branch --source pyvk -m pytest
pytest --cov-branch --cov=pyvk ./tests
coverage report -m

.PHONY: test
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
markers =
network
11 changes: 2 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,8 @@
version=version,
platforms='any',
packages=['pyvk'],
install_requires=['requests', 'lxml', 'appdirs', ],
extras_require={
"tests": [
"mock",
"pytest",
"coverage",
"coveralls",
]
},
install_requires=['requests', 'lxml', 'appdirs',],
extras_require={"tests": ["mock", "pytest", "pytest-cov", "coverage", "coveralls",]},
author='Max Kuznetsov',
author_email='maks.kuznetsov@gmail.com',
description='VK API for Python',
Expand Down
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest

from pyvk import ClientAuth, p_basic, p_market, p_docs
from tests.utils import EnvInput


@pytest.fixture(scope='session')
def api():
auth = ClientAuth(input=EnvInput, scope=p_basic | p_market | p_docs, disable_cache=True)
auth.auth()
return auth.api(max_attempts=100)
25 changes: 14 additions & 11 deletions tests/test_reqn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
from pyvk.helpers import reqn
from tests.utils import EnvInput

auth = ClientAuth(input=EnvInput, scope=p_wall | p_friends, disable_cache=True)
auth.auth()
api = auth.api(max_attempts=100)


def fetch(method, args, n, batch_size):
rb = reqn(method, n=n, batch_size=batch_size, **args)
Expand Down Expand Up @@ -42,14 +38,16 @@ def fetch_and_compare(method, args, n, batch_size):
assert rb == rn


def test_reqn_exhaustive():
@pytest.mark.network
def test_reqn_exhaustive(api):
method = api.friends.get
args = dict(user_id=1)
fetch_and_compare(method, args, None, batch_size=100)


@pytest.mark.skip()
def test_reqn_wall_get():
@pytest.mark.network
def test_reqn_wall_get(api):
method = api.wall.get
args = dict(owner_id=-29534144, filter='owner', extended=1)
fetch_and_compare(method, args, n=100, batch_size=10)
Expand All @@ -58,13 +56,15 @@ def test_reqn_wall_get():
fetch_and_compare(method, args, n=100, batch_size=10)


def test_reqn_wall_getreposts():
@pytest.mark.network
def test_reqn_wall_getreposts(api):
method = api.wall.getReposts
args = dict(owner_id=-29534144, post_id=1347049)
fetch_and_compare(method, args, n=40, batch_size=10)


def test_reqn_users_getsubscriptions():
@pytest.mark.network
def test_reqn_users_getsubscriptions(api):
method = api.users.getSubscriptions

with pytest.raises(ValueError):
Expand All @@ -75,8 +75,9 @@ def test_reqn_users_getsubscriptions():
fetch_and_compare(method, args, n=40, batch_size=10)


@pytest.mark.network
@pytest.mark.skip(reason="flaky")
def test_reqn_friends_getonline():
def test_reqn_friends_getonline(api):
method = api.friends.getOnline

n = 5
Expand All @@ -97,7 +98,8 @@ def test_reqn_friends_getonline():
break


def test_reqn_friends_getmutual():
@pytest.mark.network
def test_reqn_friends_getmutual(api):
method = api.friends.getMutual

args = dict(source_uid=1, target_uid=21)
Expand All @@ -110,7 +112,8 @@ def test_reqn_friends_getmutual():
assert eb['common_friends'] == en['common_friends']


def test_reqn_storage_getkeys():
@pytest.mark.network
def test_reqn_storage_getkeys(api):
method = api.storage.getKeys

args = {'global': 1}
Expand Down
41 changes: 22 additions & 19 deletions tests/test_uploaders.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
from io import BytesIO
from pyvk import ClientAuth, p_basic, p_market, p_docs
from pyvk.helpers.uploaders import *
from tests.utils import EnvInput
import requests

import pytest


auth = ClientAuth(input=EnvInput, scope=p_basic | p_market | p_docs, disable_cache=True)
auth.auth()
api = auth.api(max_attempts=100)
from pyvk.helpers.uploaders import *


def get_random_photo():
def get_random_photo(api):
(photo_obj,) = api.photos.get(album_id=237720036, count=1, rev=True)['items']
photo_url = photo_obj['photo_604']
return requests.get(photo_url).content


def test_video():
@pytest.mark.network
def test_video(api):
up = VideoUploader(api, link='https://www.youtube.com/watch?v=dQw4w9WgXcQ', wallpost=True)
result = up.upload()
assert 'response' in result


def test_album_photo():
@pytest.mark.network
def test_album_photo(api):
photo = get_random_photo()
up = AlbumPhotoUploader(api, album_id=237720036)
result = up.upload(BytesIO(photo), caption='shakal')
assert 'jpg' in result[0]['photo_604']


def test_wall_photo():
@pytest.mark.network
def test_wall_photo(api):
photo = get_random_photo()
up = WallPhotoUploader(api)
attach = up.upload(BytesIO(photo), attach=True)
post = api.wall.post(attachments=attach)
assert post['post_id']


def test_profile_photo():
@pytest.mark.network
def test_profile_photo(api):
(user,) = api.users.get(fields=['photo_max'])
photo_url = user['photo_max']
photo = requests.get(photo_url).content
Expand All @@ -49,25 +46,28 @@ def test_profile_photo():
assert 'photo_src' in result


@pytest.mark.network
@pytest.mark.skip()
def test_chat_photo():
def test_chat_photo(api):
photo = get_random_photo()

up = ChatPhotoUploader(api, chat_id=1)
result = up.upload(BytesIO(photo))
assert 'message_id' in result


@pytest.mark.network
@pytest.mark.skip()
def test_message_photo():
def test_message_photo(api):
photo = get_random_photo()
up = MessagePhotoUploader(api)
attach = up.upload(BytesIO(photo), attach=True)
msg_id = api.messages.send(chat_id=1, attachment=attach)
assert type(msg_id) is int


def test_audio():
@pytest.mark.network
def test_audio(api):
(item,) = api.audio.get(count=1)['items']
audio_url = item['url']
audio = requests.get(audio_url).content
Expand All @@ -77,7 +77,8 @@ def test_audio():
assert 'id' in result


def test_doc():
@pytest.mark.network
def test_doc(api):
(item,) = api.docs.get(count=1)['items']
doc_url, doc_name = item['url'], item['title']
doc = requests.get(doc_url).content
Expand All @@ -89,8 +90,9 @@ def test_doc():
assert 'id' in result[0]


@pytest.mark.network
@pytest.mark.skip()
def test_product_photo():
def test_product_photo(api):
(item,) = api.market.getById(item_ids=['-131241381_360858'], extended=True)['items']
(photo_obj,) = item['photos']
photo_url = photo_obj['photo_2560']
Expand All @@ -103,7 +105,8 @@ def test_product_photo():
assert 'id' in result[0]


def test_product_collection_photo():
@pytest.mark.network
def test_product_collection_photo(api):
(item,) = api.market.getById(item_ids=['-131241381_360858'], extended=True)['items']
(photo_obj,) = item['photos']
photo_url = photo_obj['photo_2560']
Expand Down

0 comments on commit 7b815ec

Please sign in to comment.