def test_logout_auto(set_mock, as_guest, user): testutil.guest_mode = False assert user.update_userinfo(user.urlopen('/').read()) == 'test' assert user.username == 'test' testutil.guest_mode = True assert user.update_userinfo(user.urlopen('/').read()) is None assert user.username is None assert user.rating is None assert user.skill is None
def test_login_ok(set_mock, as_guest, user): set_mock({'/login/ajax-login': '******'}) assert user.username is None assert user.login('test', '123456') is None testutil.guest_mode = False assert user.update_userinfo(user.urlopen('/').read()) == 'test' assert user.username == 'test'
def test_login_fail(set_mock, as_guest, user): set_mock({'/login/ajax-login': '******'}) assert user.username is None with pytest.raises(api.TabunResultError): user.login('test', '123456') assert user.username is None assert user.update_userinfo(user.urlopen('/').read()) is None assert user.username is None
def test_cloudflare_solution_ok_again(set_mock, as_guest, intercept): # Отличие от предыдущего теста в том, что печеньки уже стоят заранее cfdata = _get_cf_data() set_mock({ '/': cfdata['cf_mock'], '/login/': cfdata['cf_mock'], cfdata['answer_url']: cfdata['cf_mock_solved'], }) calls = {'page': 0, 'solve': 0} @intercept('/') @intercept('/login/') def get_page(data, headers): calls['page'] += 1 @intercept(cfdata['answer_url']) def cf_solve(data, headers): calls['solve'] += 1 set_mock({ '/': 'index.html', '/login/': 'login.html', }) user = UserTest(security_ls_key='N/A', session_id='abcdef9876543210abcdef9876543210', avoid_cf=True) user.extra_cookies.update({ '__cfduid': cfdata['cookvalue1'], 'cf_clearance': 'foobarblablablathisisoldcookie', }) resp = user.urlopen('/') assert resp.code == 200 user.update_userinfo(resp.read()) assert calls == {'page': 2, 'solve': 1} assert user.sleeps == [1, 4.0] assert user.extra_cookies == { '__cfduid': cfdata['cookvalue1'], 'cf_clearance': cfdata['cookvalue2'], } assert user.session_id == 'abcdef9876543210abcdef9876543210' assert user.security_ls_key == '0123456789abcdef0123456789abcdef'
def test_user_partially_preloaded_cookies(session_id, security_ls_key, key): user = UserTest(phpsessid=session_id, security_ls_key=security_ls_key, key=key) assert user.username == None if security_ls_key else 'test' assert user.phpsessid == session_id assert user.security_ls_key == '0123456789abcdef0123456789abcdef' assert user.key in (None, '00000000000000000000000000000000') assert user.update_userinfo(user.urlopen('/').read()) == 'test' assert user.phpsessid == session_id assert user.security_ls_key == '0123456789abcdef0123456789abcdef' assert user.key in (None, '00000000000000000000000000000000')
def test_login_init_ok(set_mock, as_guest): set_mock({'/login/ajax-login': '******'}) user = UserTest('test', '123456') testutil.guest_mode = False assert user.update_userinfo(user.urlopen('/').read()) == 'test' assert user.username == 'test'