Added tests for plans
This commit is contained in:
@@ -486,7 +486,7 @@ class PollOption(object):
|
|||||||
class Plan(object):
|
class Plan(object):
|
||||||
#: ID of the plan
|
#: ID of the plan
|
||||||
uid = None
|
uid = None
|
||||||
#: Plan time (unix time stamp)
|
#: Plan time (unix time stamp), only precise down to the minute
|
||||||
time = None
|
time = None
|
||||||
#: Plan title
|
#: Plan title
|
||||||
title = None
|
title = None
|
||||||
@@ -503,12 +503,12 @@ class Plan(object):
|
|||||||
#: List of the people IDs who are invited to the plan
|
#: List of the people IDs who are invited to the plan
|
||||||
invited = None
|
invited = None
|
||||||
|
|
||||||
def __init__(self, time, title, location='', location_id=''):
|
def __init__(self, time, title, location=None, location_id=None):
|
||||||
"""Represents a plan"""
|
"""Represents a plan"""
|
||||||
self.time = time
|
self.time = int(time)
|
||||||
self.title = title
|
self.title = title
|
||||||
self.location = location
|
self.location = location or ''
|
||||||
self.location_id = location_id
|
self.location_id = location_id or ''
|
||||||
self.author_id = None
|
self.author_id = None
|
||||||
self.going = []
|
self.going = []
|
||||||
self.declined = []
|
self.declined = []
|
||||||
|
@@ -20,7 +20,7 @@ def group(pytestconfig):
|
|||||||
return {"id": load_variable("group_id", pytestconfig.cache), "type": ThreadType.GROUP}
|
return {"id": load_variable("group_id", pytestconfig.cache), "type": ThreadType.GROUP}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(params=["user", "group", pytest.mark.xfail("none")])
|
@pytest.fixture(scope="session", params=["user", "group", pytest.mark.xfail("none")])
|
||||||
def thread(request, user, group):
|
def thread(request, user, group):
|
||||||
return {
|
return {
|
||||||
"user": user,
|
"user": user,
|
||||||
@@ -41,7 +41,7 @@ def client2(pytestconfig):
|
|||||||
yield c
|
yield c
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture # (scope="session")
|
@pytest.fixture(scope="module")
|
||||||
def client(client1, thread):
|
def client(client1, thread):
|
||||||
client1.setDefaultThread(thread["id"], thread["type"])
|
client1.setDefaultThread(thread["id"], thread["type"])
|
||||||
yield client1
|
yield client1
|
||||||
@@ -89,7 +89,7 @@ def catch_event(client2):
|
|||||||
t.join()
|
t.join()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture # (scope="session")
|
@pytest.fixture(scope="module")
|
||||||
def compare(client, thread):
|
def compare(client, thread):
|
||||||
def inner(caught_event, **kwargs):
|
def inner(caught_event, **kwargs):
|
||||||
d = {
|
d = {
|
||||||
|
105
tests/test_plans.py
Normal file
105
tests/test_plans.py
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
# -*- 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"]
|
||||||
|
assert user["id"] in x.res["plan"].invited
|
||||||
|
request.param.uid = x.res["plan"].uid
|
||||||
|
yield x.res, request.param
|
||||||
|
with catch_event("onPlanDeleted") as x:
|
||||||
|
client.deletePlan(plan_id)
|
||||||
|
assert compare(x)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.tryfirst
|
||||||
|
def test_create_delete_plan(plan_data):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def test_fetch_plan_info(client, catch_event, plan_data):
|
||||||
|
event, plan = plan_data
|
||||||
|
fetched_plan = client.fetchPlanInfo(plan.uid)
|
||||||
|
assert subset(
|
||||||
|
vars(fetched_plan),
|
||||||
|
time=plan.time,
|
||||||
|
title=plan.title,
|
||||||
|
author_id=int(client.uid),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("take_part", [False, True])
|
||||||
|
def test_change_plan_participation(client, thread, catch_event, compare, plan_data, take_part):
|
||||||
|
event, plan = plan_data
|
||||||
|
with catch_event("onPlanParticipation") as x:
|
||||||
|
client.changePlanParticipation(plan, take_part=take_part)
|
||||||
|
assert compare(x, take_part=take_part)
|
||||||
|
assert subset(
|
||||||
|
vars(x.res["plan"]),
|
||||||
|
time=plan.time,
|
||||||
|
title=plan.title,
|
||||||
|
author_id=client.uid,
|
||||||
|
going=[client.uid] if take_part else [],
|
||||||
|
declined=[client.uid] if not take_part else [],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.trylast
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.trylast
|
||||||
|
@pytest.mark.expensive
|
||||||
|
def test_on_plan_ended(client, thread, catch_event, compare):
|
||||||
|
with catch_event("onPlanEnded") as x:
|
||||||
|
client.createPlan(Plan(int(time()) + 120, "Wait for ending"))
|
||||||
|
x.wait(180)
|
||||||
|
assert subset(x.res, thread_id=client.uid if thread["type"] == ThreadType.USER else thread["id"], thread_type=thread["type"])
|
||||||
|
|
||||||
|
|
||||||
|
#createPlan(self, plan, thread_id=None)
|
||||||
|
#editPlan(self, plan, new_plan)
|
||||||
|
#deletePlan(self, plan)
|
||||||
|
#changePlanParticipation(self, plan, take_part=True)
|
||||||
|
|
||||||
|
#onPlanCreated(self, mid=None, plan=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None)
|
||||||
|
#onPlanEnded(self, mid=None, plan=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None)
|
||||||
|
#onPlanEdited(self, mid=None, plan=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None)
|
||||||
|
#onPlanDeleted(self, mid=None, plan=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None)
|
||||||
|
#onPlanParticipation(self, mid=None, plan=None, take_part=None, author_id=None, thread_id=None, thread_type=None, ts=None, metadata=None, msg=None)
|
||||||
|
|
||||||
|
#fetchPlanInfo(self, plan_id)
|
Reference in New Issue
Block a user