Split Plan into Plan/PlanData, and add Plan.session

This commit is contained in:
Mads Marquart
2020-01-09 15:05:42 +01:00
parent e039e88f80
commit 483fdf43dc
8 changed files with 64 additions and 40 deletions

View File

@@ -1,9 +1,11 @@
import datetime
from fbchat._plan import GuestStatus, Plan
from fbchat._plan import GuestStatus, PlanData
def test_plan_properties():
plan = Plan(
def test_plan_properties(session):
plan = PlanData(
session=session,
id="1234567890",
time=...,
title=...,
guests={
@@ -18,7 +20,7 @@ def test_plan_properties():
assert plan.declined == ["4567"]
def test_plan_from_pull():
def test_plan_from_pull(session):
data = {
"event_timezone": "",
"event_creator_id": "1234",
@@ -35,7 +37,8 @@ def test_plan_from_pull():
'{"guest_list_state":"GOING","node":{"id":"4567"}}]'
),
}
assert Plan(
assert PlanData(
session=session,
id="1111",
time=datetime.datetime(2017, 7, 14, 2, 40, tzinfo=datetime.timezone.utc),
title="abc",
@@ -46,10 +49,10 @@ def test_plan_from_pull():
"3456": GuestStatus.DECLINED,
"4567": GuestStatus.GOING,
},
) == Plan._from_pull(data)
) == PlanData._from_pull(session, data)
def test_plan_from_fetch():
def test_plan_from_fetch(session):
data = {
"message_thread_id": 123456789,
"event_time": 1500000000,
@@ -92,7 +95,8 @@ def test_plan_from_fetch():
"4567": "GOING",
},
}
assert Plan(
assert PlanData(
session=session,
id=1111,
time=datetime.datetime(2017, 7, 14, 2, 40, tzinfo=datetime.timezone.utc),
title="abc",
@@ -105,10 +109,10 @@ def test_plan_from_fetch():
"3456": GuestStatus.DECLINED,
"4567": GuestStatus.GOING,
},
) == Plan._from_fetch(data)
) == PlanData._from_fetch(session, data)
def test_plan_from_graphql():
def test_plan_from_graphql(session):
data = {
"id": "1111",
"lightweight_event_creator": {"id": "1234"},
@@ -134,7 +138,8 @@ def test_plan_from_graphql():
]
},
}
assert Plan(
assert PlanData(
session=session,
time=datetime.datetime(2017, 7, 14, 2, 40, tzinfo=datetime.timezone.utc),
title="abc",
location="",
@@ -147,4 +152,4 @@ def test_plan_from_graphql():
"3456": GuestStatus.DECLINED,
"4567": GuestStatus.GOING,
},
) == Plan._from_graphql(data)
) == PlanData._from_graphql(session, data)

View File

@@ -1,6 +1,6 @@
import pytest
from fbchat import Plan, FBchatFacebookError
from fbchat import PlanData, FBchatFacebookError
from utils import random_hex, subset
from time import time
@@ -10,12 +10,12 @@ 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()]),
# PlanData(time=int(time()) + 100, title=random_hex()),
# pytest.param(
# PlanData(time=int(time()), title=random_hex()),
# marks=[pytest.mark.xfail(raises=FBchatFacebookError)],
# ),
# pytest.param(PlanData(time=0, title=None), marks=[pytest.mark.xfail()]),
],
)
def plan_data(request, client, user, thread, catch_event, compare):
@@ -73,7 +73,7 @@ def test_change_plan_participation(
@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())
new_plan = PlanData(plan.time + 100, random_hex())
with catch_event("on_plan_edited") as x:
client.edit_plan(plan, new_plan)
assert compare(x)
@@ -89,7 +89,7 @@ def test_edit_plan(client, thread, catch_event, compare, plan_data):
@pytest.mark.skip
def test_on_plan_ended(client, thread, catch_event, compare):
with catch_event("on_plan_ended") as x:
client.create_plan(Plan(int(time()) + 120, "Wait for ending"))
client.create_plan(PlanData(int(time()) + 120, "Wait for ending"))
x.wait(180)
assert subset(
x.res,