def test_update_poll_vote(client1, group, catch_event, poll_data): event, poll, options = poll_data new_vote_ids = [o.uid for o in options[0:len(options):2] if not o.vote] re_vote_ids = [o.uid for o in options[0:len(options):2] if o.vote] new_options = [random_hex(), random_hex()] with catch_event("onPollVoted") as x: client1.updatePollVote( event["poll"].uid, option_ids=new_vote_ids + re_vote_ids, new_options=new_options, ) assert subset( x.res, author_id=client1.uid, thread_id=group["id"], thread_type=ThreadType.GROUP, ) assert subset(vars(x.res["poll"]), title=poll.title, options_count=len(options + new_options)) for o in new_vote_ids: assert o in x.res["added_options"] assert len(x.res["added_options"]) == len(new_vote_ids) + len(new_options) assert set(x.res["removed_options"]) == set( o.uid for o in options if o.vote and o.uid not in re_vote_ids)
def create_user(username, email, password): """Create a new user, return the newly-created ID username: Name for the new user email: Email address (must be unique) password: Clear-text password """ username = username.lower(); email = email.lower(); if not isinstance(password, bytes): password=password.encode("utf-8") print password print email hex_key = utils.random_hex() with _conn, _conn.cursor() as cur: salt = os.urandom(16) hash = hashlib.sha256(salt+password).hexdigest() pwd = salt.encode("hex")+"-"+hash try: cur.execute("INSERT INTO users (username, email, password, hex_key) VALUES (%s, %s, %s, %s) RETURNING id, hex_key", \ (username, email, pwd, hex_key)) return cur.fetchone() except psycopg2.IntegrityError as e: return "That didn't work too well because: <br/>%s<br/> Maybe you already have an account or \ someone else is using the name you requested."%e
def index(self): user = self.get_user_by_request(flask.request, flask.session) if user is not None and user.is_authenticated(): return flask.redirect('/create-join', code=302) if SESSION_USE: if 'id' not in flask.session: flask.session['id'] = utils.random_hex(32) return flask.render_template('index.html')
def test_change_title(client1, group, catch_event): title = random_hex() with catch_event("onTitleChange") as x: client1.changeThreadTitle(title, group["id"], thread_type=ThreadType.GROUP) assert subset( x.res, author_id=client1.uid, new_title=title, thread_id=group["id"], thread_type=ThreadType.GROUP, )
def test_edit_plan(client, thread, catch_event, compare, plan_data): event, plan = plan_data new_plan = Plan(plan.time + 100, random_hex()) with catch_event("onPlanEdited") as x: client.editPlan(plan, new_plan) assert compare(x) assert subset( vars(x.res["plan"]), time=new_plan.time, title=new_plan.title, author_id=client.uid, )
# -*- coding: utf-8 -*- from __future__ import unicode_literals import pytest from fbchat.models import Poll, PollOption, ThreadType from utils import random_hex, subset @pytest.fixture( scope="module", params=[ Poll(title=random_hex(), options=[]), Poll( title=random_hex(), options=[ PollOption(random_hex(), vote=True), PollOption(random_hex(), vote=True), ], ), Poll( title=random_hex(), options=[ PollOption(random_hex(), vote=False), PollOption(random_hex(), vote=False), ], ), Poll( title=random_hex(), options=[
def random_name(self): if self.image: return self.image_name[:12] + '_' + random_hex(11) else: return random_hex()
def random_name(): return 'nav_' + random_hex()
# -*- coding: utf-8 -*- from __future__ import unicode_literals import pytest from fbchat.models import Plan, FBchatFacebookError, ThreadType from utils import random_hex, subset from time import time @pytest.fixture(scope="module", params=[ Plan(int(time()) + 100, random_hex()), pytest.mark.xfail(Plan(int(time()), random_hex()), raises=FBchatFacebookError), pytest.mark.xfail(Plan(0, None)), ]) def plan_data(request, client, user, thread, catch_event, compare): with catch_event("onPlanCreated") as x: client.createPlan(request.param, thread["id"]) assert compare(x) assert subset( vars(x.res["plan"]), time=request.param.time, title=request.param.title, author_id=client.uid, going=[client.uid], declined=[], ) plan_id = x.res["plan"]
def test_random_hex(self): random.seed(21345) self.assertEqual(utils.random_hex(4), 'fa5f') self.assertEqual(utils.random_hex(16, upper=True), 'F9D9B6E7D414144F')
def test_change_nickname(client, client_all, catch_event, compare): nickname = random_hex() with catch_event("onNicknameChange") as x: client.changeNickname(nickname, client_all.uid) assert compare(x, changed_for=client_all.uid, new_nickname=nickname)
import pytest from fbchat import Poll, PollOption from utils import random_hex, subset pytestmark = pytest.mark.online @pytest.fixture( scope="module", params=[ (random_hex(), []), ( random_hex(), [ (random_hex(), True), (random_hex(), True), ], ), ( random_hex(), [ (random_hex(), False), (random_hex(), False), ], ), ( random_hex(), [ (random_hex(), True), (random_hex(), True),
def test_change_title(client1, group, catch_event): title = random_hex() with catch_event("on_title_change") as x: client1.change_thread_title(title, group["id"]) assert subset(x.res, author_id=client1.id, new_title=title, thread=group)
# -*- coding: utf-8 -*- from __future__ import unicode_literals import pytest from fbchat.models import Plan, FBchatFacebookError, ThreadType from utils import random_hex, subset from time import time @pytest.fixture( scope="module", params=[ Plan(int(time()) + 100, random_hex()), pytest.param( Plan(int(time()), random_hex()), marks=[pytest.mark.xfail(raises=FBchatFacebookError)], ), pytest.param(Plan(0, None), marks=[pytest.mark.xfail()]), ], ) def plan_data(request, client, user, thread, catch_event, compare): with catch_event("onPlanCreated") as x: client.createPlan(request.param, thread["id"]) assert compare(x) assert subset( vars(x.res["plan"]), time=request.param.time, title=request.param.title, author_id=client.uid,
import pytest from fbchat import Plan, FBchatFacebookError, ThreadType from utils import random_hex, subset from time import time pytestmark = pytest.mark.online @pytest.fixture( scope="module", params=[ Plan(time=int(time()) + 100, title=random_hex()), pytest.param( Plan(time=int(time()), title=random_hex()), marks=[pytest.mark.xfail(raises=FBchatFacebookError)], ), pytest.param(Plan(time=0, title=None), marks=[pytest.mark.xfail()]), ], ) def plan_data(request, client, user, thread, catch_event, compare): with catch_event("on_plan_created") as x: client.create_plan(request.param, thread["id"]) assert compare(x) assert subset( vars(x.res["plan"]), time=request.param.time, title=request.param.title, author_id=client.uid, going=[client.uid], declined=[],