Beispiel #1
0
def test_session_edux(session_creator, should_fail):
    skip_auth(AUTH)
    username, password = auth.auth(target='edux')
    session = session_creator()
    r = session.get(EDUX)
    r.raise_for_status()
    parser = BeautifulSoup(r.text, 'html.parser')
    div = parser.find('div', {'class': 'user'})
    text = div.text.strip()
    if should_fail:
        assert not len(text) > 0
        assert not re.search(username, text)
    else:
        assert len(text) > 0
        assert re.search(username, text)
Beispiel #2
0
def test_session_api():
    skip_auth(AUTH)
    username, password = auth.auth(target='api')
    session = auth.session_api(username, password)
    assert 'Authorization' in session.headers
Beispiel #3
0
def test_config(target, file):
    credentials = auth.auth(target, file)
    assert len(credentials) == 2 if target != 'oauth' else 3
Beispiel #4
0
def test_config_fail():
    with pytest.raises(KeyError):
        auth.auth('non-existent-section', AUTH)
Beispiel #5
0
from eduxfeed.update import edux_page_prev, edux_feed_last

import os
import re
from datetime import datetime

import requests
from bs4 import BeautifulSoup

import pytest
import flexmock

FIXTURES = os.path.join(os.path.dirname(__file__), 'fixtures')

AUTH_SAMPLE = os.path.join(FIXTURES, 'auth.cfg.sample')
AUTH = AUTH_FILE if auth.auth() else AUTH_SAMPLE

OPEN = {
    'mode': 'r',
    'encoding': 'utf-8',
}

# TEST AUTH


@pytest.mark.parametrize(
    ['target', 'file'],
    [(target, AUTH) for target in ('edux', 'api', 'oauth')],
)
def test_config(target, file):
    credentials = auth.auth(target, file)