Exemplo n.º 1
0
async def publish(s):
    response = await auth(s)
    verb = Verbs.ADD
    component = Components.CONVERSATIONS
    address = '*****@*****.**'
    ts = datetime.utcnow().replace(tzinfo=timezone.utc)
    conv = hash_id(address, to_unix_ms(ts), 'foo bar', sha256=True)
    data = {
        'address': address,
        'timestamp': ts,
        'event_id': hash_id(to_unix_ms(ts), address, conv, verb, component,
                            None),
        'kwargs': {
            'data': PUBLISH_KWARGS
        },
    }
    url = f'{conv}/{component}/{verb}/'

    headers = dict(Authorization=response['key'], **CT_HEADER)
    await s.post(url, data=encoding.encode(data), headers=headers)
Exemplo n.º 2
0
async def test_create_basic_conversation(controller):
    action = Action('*****@*****.**', None, Verbs.ADD)
    await controller.act(action, subject='foo bar')
    ds = controller.ds
    assert len(ds.data) == 1
    conv = ds.data[0]
    assert len(conv['participants']) == 1
    assert len(conv['events']) == 0
    assert conv['creator'] == '*****@*****.**'
    assert conv['status'] == 'draft'
    assert conv['subject'] == 'foo bar'
    assert isinstance(conv['timestamp'], datetime.datetime)
    hash_data = '[email protected]_{}_foo bar'.format(to_unix_ms(conv['timestamp'])).encode()
    hash_result = hashlib.sha256(hash_data).hexdigest()
    assert conv['conv_id'] == hash_result
Exemplo n.º 3
0
 def calc_event_id(self):
     ts = self.timestamp and to_unix_ms(self.timestamp)
     return hash_id(ts, self.address, self.conv, self.verb, self.component, self.item)
Exemplo n.º 4
0
Arquivo: encoding.py Projeto: em-2/em2
def _encoder(obj):
    if isinstance(obj, datetime):
        return {_DT: to_unix_ms(obj)}
    return obj
Exemplo n.º 5
0
 def _conv_id_hash(self, creator, timestamp, ref):
     ts = timestamp and to_unix_ms(timestamp)
     return hash_id(creator, ts, ref, sha256=True)