forked from josuebrunel/yahoo-oauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
67 lines (45 loc) · 1.49 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from __future__ import absolute_import
import pytest
import os
import logging
import myql
from myql.utils import pretty_json
from yahoo_oauth.utils import write_data, get_data
from yahoo_oauth import OAuth1, OAuth2
logging.basicConfig(
level=logging.DEBUG,
format="[%(asctime)s %(levelname)s] [%(name)s.%(module)s.%(funcName)s] %(message)s \n")
oauth_logger = logging.getLogger('yahoo_oauth')
oauth_logger.disabled = False
def test_oauth1():
oauth = OAuth1(None, None, from_file='oauth1.json')
yql = myql.MYQL(oauth=oauth)
response = yql.get_guid('josue_brunel')
logging.debug(pretty_json(response.content))
assert response.status_code == 200
def test_oauth2():
oauth = OAuth2(None, None, from_file='oauth2.yaml')
response = oauth.session.get('https://social.yahooapis.com/v1/me/guid?format=json')
logging.debug(pretty_json(response.content))
assert response.status_code == 200
@pytest.fixture
def data():
return {
'ck': 'consumer_key',
'cs': 'consumer_secret'
}
@pytest.fixture
def data_json():
return 'data.json'
@pytest.fixture
def data_yaml():
return 'data.yaml'
@pytest.fixture(params=['data_json', 'data_yaml'])
def data_format(request, data_json, data_yaml):
return locals().get(request.param)
def test_write_data(data, data_format):
write_data(data, data_format)
assert os.path.exists(data_format)
def test_get_data(data, data_format):
data_stored = get_data(data_format)
assert data == data_stored