예제 #1
0
async def create_conv(conn, ds, conv_id='123'):
    await ds.create_conversation(
        conn,
        conv_id=conv_id,
        creator='*****@*****.**',
        timestamp=datetime_tz(),
        ref='x',
        subject='sub',
        status=Conversations.Status.ACTIVE,
    )
    return ds.new_conv_ds(conv_id, conn)
예제 #2
0
async def test_publish_reply_bad_ts(two_controllers):
    ctrl1, ctrl2, conv_id = await two_controllers()

    assert (len(ctrl1.ds.data), len(ctrl2.ds.data)) == (1, 0)
    a = Action('*****@*****.**', conv_id, Verbs.PUBLISH, Components.CONVERSATIONS)
    await ctrl1.act(a)
    assert (len(ctrl1.ds.data), len(ctrl2.ds.data)) == (1, 1)

    conv_id = ctrl1.ds.data[0]['conv_id']
    msg1_id = list(ctrl2.ds.data[0]['messages'])[0]
    a = Action('*****@*****.**', conv_id, Verbs.ADD, Components.MESSAGES, timestamp=datetime_tz(year=2000))
    a.event_id = a.calc_event_id()
    with pytest.raises(BadDataException) as excinfo:
        await ctrl1.act(a, parent_id=msg1_id, body='this is a reply')
    assert excinfo.value.args[0] == 'timestamp not after parent timestamp: 2000-01-01 00:00:00+00:00'
예제 #3
0
async def test_set_published_id(get_ds, datastore_cls):
    ds = await get_ds(datastore_cls)
    async with ds.connection() as conn:
        cds = await create_conv(conn, ds)
        assert cds.conv == '123'
        new_ts = datetime_tz(2)

        props = await cds.get_core_properties()
        # to avoid issue with tzinfo=psycopg2.tz...
        assert props['timestamp'].isoformat() != new_ts.isoformat()

        await cds.set_published_id(new_ts, '456')
        props = await cds.get_core_properties()
        props = dict(props)
        ts = props.pop('timestamp')
        assert ts.isoformat() == new_ts.isoformat()
        assert props == {
            'subject': 'sub',
            'creator': '*****@*****.**',
            'status': Conversations.Status.ACTIVE,
            'ref': 'x',
            'expiration': None,
        }
        assert cds.conv == '456'