Exemplo n.º 1
0
def create_template_map(request, reply, data):
    document_title = ''
    if 'document' in reply:
        document_title = reply['document'].get('title', '')

    if document_title is '':
        document_title = data['parent']['uri']

    parent_user = user_name(data['parent']['user'])
    reply_user = user_name(reply['user'])

    token = request.registry.notification_serializer.dumps({
        'type': REPLY_TYPE,
        'uri': data['parent']['user'],
    })
    unsubscribe = request.route_url('unsubscribe', token=token)

    return {
        'document_title': document_title,
        'document_path': data['parent']['uri'],
        'parent_text': data['parent']['text'],
        'parent_user': parent_user,
        'parent_timestamp': format_timestamp(data['parent']['created']),
        'parent_user_profile': user_profile_url(
            request, data['parent']['user']),
        'parent_path': standalone_url(request, data['parent']['id']),
        'reply_text': reply['text'],
        'reply_user': reply_user,
        'reply_timestamp': format_timestamp(reply['created']),
        'reply_user_profile': user_profile_url(request, reply['user']),
        'reply_path': standalone_url(request, reply['id']),
        'unsubscribe': unsubscribe
    }
Exemplo n.º 2
0
def test_template_map_key_values():
    """This test checks whether the keys holds the correct values"""
    with patch("h.notification.reply_template.Annotation") as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
        request = _create_request()
        annotation = store_fake_data[1]

        parent = rt.parent_values(annotation)
        tmap = rt.create_template_map(request, annotation, parent)

        parent = store_fake_data[0]

        # Document properties
        assert tmap["document_title"] == annotation["document"]["title"]
        assert tmap["document_path"] == parent["uri"]

        # Parent properties
        assert tmap["parent_text"] == parent["text"]
        assert tmap["parent_user"] == user_name(parent["user"])
        assert tmap["parent_user_profile"] == user_profile_url(request, parent["user"])
        assert tmap["parent_path"] == standalone_url(request, parent["id"])

        # Annotation properties
        assert tmap["reply_text"] == annotation["text"]
        assert tmap["reply_user"] == user_name(annotation["user"])
        assert tmap["reply_user_profile"] == user_profile_url(request, annotation["user"])
        assert tmap["reply_path"] == standalone_url(request, annotation["id"])

        assert tmap["parent_timestamp"] == "27 October 2013 at 19:40"
        assert tmap["reply_timestamp"] == "27 October 2014 at 19:50"

        assert tmap["unsubscribe"] == "UNSUBSCRIBE_URL"
Exemplo n.º 3
0
def test_template_map_key_values():
    """This test checks whether the keys holds the correct values"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
        request = _create_request()
        annotation = store_fake_data[1]

        parent = rt.parent_values(annotation)
        tmap = rt.create_template_map(request, annotation, parent)

        parent = store_fake_data[0]

        # Document properties
        assert tmap['document_title'] == annotation['document']['title']
        assert tmap['document_path'] == parent['uri']

        # Parent properties
        assert tmap['parent_text'] == parent['text']
        assert tmap['parent_user'] == user_name(parent['user'])
        assert tmap['parent_user_profile'] == user_profile_url(request, parent['user'])
        assert tmap['parent_path'] == standalone_url(request, parent['id'])

        # Annotation properties
        assert tmap['reply_text'] == annotation['text']
        assert tmap['reply_user'] == user_name(annotation['user'])
        assert tmap['reply_user_profile'] == user_profile_url(request, annotation['user'])
        assert tmap['reply_path'] == standalone_url(request, annotation['id'])

        assert tmap['parent_timestamp'] == '27 October 2013 at 19:40'
        assert tmap['reply_timestamp'] == '27 October 2014 at 19:50'

        assert tmap['unsubscribe'] == 'UNSUBSCRIBE_URL'
Exemplo n.º 4
0
def create_template_map(request, reply, parent):
    document_title = ''
    if reply.document:
        document_title = reply.document.title

    if document_title is '':
        document_title = parent.target_uri

    parent_user = user_name(parent.userid)
    reply_user = user_name(reply.userid)

    token = request.registry.notification_serializer.dumps({
        'type': REPLY_TYPE,
        'uri': parent.userid,
    })
    unsubscribe = request.route_url('unsubscribe', token=token)

    return {
        'document_title': document_title,
        'document_path': parent.target_uri,
        'parent_text': parent.text,
        'parent_user': parent_user,
        'parent_timestamp': format_timestamp(parent.created),
        'parent_user_profile': user_profile_url(request, parent.userid),
        'parent_path': standalone_url(request, parent.id),
        'reply_text': reply.text,
        'reply_user': reply_user,
        'reply_timestamp': format_timestamp(reply.created),
        'reply_user_profile': user_profile_url(request, reply.userid),
        'reply_path': standalone_url(request, reply.id),
        'unsubscribe': unsubscribe
    }
Exemplo n.º 5
0
def test_template_map_key_values():
    """This test checks whether the keys holds the correct values"""
    request = _fake_request()
    annotation = _fake_anno(1)
    parent = _fake_anno(0)

    tmap = rt.create_template_map(request, annotation, parent)

    # Document properties
    assert tmap['document_title'] == annotation['document']['title']
    assert tmap['document_path'] == parent['uri']

    # Parent properties
    assert tmap['parent_text'] == parent['text']
    assert tmap['parent_user'] == user_name(parent['user'])
    assert tmap['parent_user_profile'] == user_profile_url(request, parent['user'])
    assert tmap['parent_path'] == standalone_url(request, parent['id'])

    # Annotation properties
    assert tmap['reply_text'] == annotation['text']
    assert tmap['reply_user'] == user_name(annotation['user'])
    assert tmap['reply_user_profile'] == user_profile_url(request, annotation['user'])
    assert tmap['reply_path'] == standalone_url(request, annotation['id'])

    assert tmap['parent_timestamp'] == '27 October 2013 at 19:40'
    assert tmap['reply_timestamp'] == '27 October 2014 at 19:50'

    assert tmap['unsubscribe'] == 'UNSUBSCRIBE_URL'
Exemplo n.º 6
0
def create_template_map(request, reply, parent):
    document_title = ''
    if 'document' in reply:
        document_title = reply['document'].get('title', '')

    if document_title is '':
        document_title = parent['uri']

    parent_user = user_name(parent['user'])
    reply_user = user_name(reply['user'])

    token = request.registry.notification_serializer.dumps({
        'type': REPLY_TYPE,
        'uri': parent['user'],
    })
    unsubscribe = request.route_url('unsubscribe', token=token)

    return {
        'document_title': document_title,
        'document_path': parent['uri'],
        'parent_text': parent.get('text', ''),
        'parent_user': parent_user,
        'parent_timestamp': format_timestamp(parent['created']),
        'parent_user_profile': user_profile_url(request, parent['user']),
        'parent_path': standalone_url(request, parent['id']),
        'reply_text': reply['text'],
        'reply_user': reply_user,
        'reply_timestamp': format_timestamp(reply['created']),
        'reply_user_profile': user_profile_url(request, reply['user']),
        'reply_path': standalone_url(request, reply['id']),
        'unsubscribe': unsubscribe
    }
Exemplo n.º 7
0
def test_template_map_key_values():
    """This test checks whether the keys holds the correct values"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
        request = DummyRequest()
        request.domain = 'www.howtoreachtheark.now'
        annotation = store_fake_data[1]

        data = {
            'parent': rt.parent_values(annotation),
            'subscription': {'id': 1}
        }
        tmap = rt.create_template_map(request, annotation, data)

        parent = store_fake_data[0]

        # Document properties
        assert tmap['document_title'] == annotation['document']['title']
        assert tmap['document_path'] == parent['uri']

        # Parent properties
        assert tmap['parent_text'] == parent['text']
        assert tmap['parent_user'] == user_name(parent['user'])
        assert tmap['parent_user_profile'] == user_profile_url(request, parent['user'])
        assert tmap['parent_path'] == standalone_url(request, parent['id'])

        # Annotation properties
        assert tmap['reply_text'] == annotation['text']
        assert tmap['reply_user'] == user_name(annotation['user'])
        assert tmap['reply_user_profile'] == user_profile_url(request, annotation['user'])
        assert tmap['reply_path'] == standalone_url(request, annotation['id'])

        # Timestamps
        date_format = '%Y-%m-%dT%H:%M:%S.%f'
        parent_timestamp = datetime.strptime(parent['created'][:-6], date_format)
        reply_timestamp = datetime.strptime(annotation['created'][:-6], date_format)

        assert tmap['parent_timestamp'] == parent_timestamp
        assert tmap['reply_timestamp'] == reply_timestamp

        # Unsubscribe link
        seq = ('http://', str(request.domain), '/app?__formid__=unsubscribe&subscription_id=', str(data['subscription']['id']))
        unsubscribe = "".join(seq)

        assert tmap['unsubscribe'] == unsubscribe
Exemplo n.º 8
0
def create_template_map(request, reply, data):
    document_title = ''
    if 'document' in reply:
        document_title = reply['document'].get('title', '')

    if document_title is '':
        document_title = data['parent']['uri']

    parent_user = user_name(data['parent']['user'])
    reply_user = user_name(reply['user'])

    # Currently we cut the UTC format because time.strptime has problems
    # parsing it, and of course it'd only correct the backend's timezone
    # which is not meaningful for international users
    date_format = '%Y-%m-%dT%H:%M:%S.%f'
    parent_timestamp = datetime.strptime(data['parent']['created'][:-6],
                                         date_format)
    reply_timestamp = datetime.strptime(reply['created'][:-6],
                                        date_format)

    seq = ('http://', str(request.domain),
           '/app?__formid__=unsubscribe&subscription_id=',
           str(data['subscription']['id']))
    unsubscribe = "".join(seq)

    return {
        'document_title': document_title,
        'document_path': data['parent']['uri'],
        'parent_text': data['parent']['text'],
        'parent_user': parent_user,
        'parent_timestamp': parent_timestamp,
        'parent_user_profile': user_profile_url(
            request, data['parent']['user']),
        'parent_path': standalone_url(request, data['parent']['id']),
        'reply_text': reply['text'],
        'reply_user': reply_user,
        'reply_timestamp': reply_timestamp,
        'reply_user_profile': user_profile_url(request, reply['user']),
        'reply_path': standalone_url(request, reply['id']),
        'unsubscribe': unsubscribe
    }
Exemplo n.º 9
0
def test_template_map_key_values():
    """This test checks whether the keys holds the correct values"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
        request = _create_request()
        annotation = store_fake_data[1]

        data = {
            'parent': rt.parent_values(annotation),
            'subscription': {
                'id': 1
            }
        }
        tmap = rt.create_template_map(request, annotation, data)

        parent = store_fake_data[0]

        # Document properties
        assert tmap['document_title'] == annotation['document']['title']
        assert tmap['document_path'] == parent['uri']

        # Parent properties
        assert tmap['parent_text'] == parent['text']
        assert tmap['parent_user'] == user_name(parent['user'])
        assert tmap['parent_user_profile'] == user_profile_url(
            request, parent['user'])
        assert tmap['parent_path'] == standalone_url(request, parent['id'])

        # Annotation properties
        assert tmap['reply_text'] == annotation['text']
        assert tmap['reply_user'] == user_name(annotation['user'])
        assert tmap['reply_user_profile'] == user_profile_url(
            request, annotation['user'])
        assert tmap['reply_path'] == standalone_url(request, annotation['id'])

        assert tmap['parent_timestamp'] == '27 October 2013 at 19:40'
        assert tmap['reply_timestamp'] == '27 October 2014 at 19:50'

        assert tmap['unsubscribe'] == 'UNSUBSCRIBE_URL'
Exemplo n.º 10
0
def create_template_map(request, annotation):
    if 'tags' in annotation:
        tags = '\ntags: ' + ', '.join(annotation['tags'])
    else:
        tags = ''
    user = re.search("^acct:([^@]+)", annotation['user']).group(1)
    return {
        'document_title': annotation['title'],
        'document_path': annotation['uri'],
        'text': annotation['text'],
        'tags': tags,
        'user_profile': user_profile_url(request, annotation['user']),
        'user': user,
        'path': standalone_url(request, annotation['id']),
        'timestamp': annotation['created'],
        'selection': annotation['quote']
    }