Exemplo n.º 1
0
def test_unsubscribe_url_generation():
    """ensures that a serialized token is generated for the unsubscribe url"""
    request = _fake_request()
    annotation = _fake_anno(4)
    parent = _fake_anno(0)

    rt.create_template_map(request, annotation, parent)

    request.route_url.assert_called_with('unsubscribe', token='TOKEN')
Exemplo n.º 2
0
def test_unsubscribe_url_generation():
    """ensures that a serialized token is generated for the unsubscribe url"""
    request = _fake_request()
    annotation = _fake_anno(4)
    parent = _fake_anno(0)

    rt.create_template_map(request, annotation, parent)

    request.route_url.assert_called_with('unsubscribe', token='TOKEN')
Exemplo n.º 3
0
def test_unsubscribe_url_generation():
    """ensures that a serialized token is generated for the unsubscribe url"""
    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[4]

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

        request.route_url.assert_called_with('unsubscribe', token='TOKEN')
Exemplo n.º 4
0
def test_unsubscribe_token_generation():
    """ensures that a serialized token is generated for the unsubscribe url"""
    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[4]

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

        notification_serializer = request.registry.notification_serializer
        notification_serializer.dumps.assert_called_with({"type": REPLY_TYPE, "uri": parent["user"]})
Exemplo n.º 5
0
def test_unsubscribe_token_generation():
    """ensures that a serialized token is generated for the unsubscribe url"""
    request = _fake_request()
    annotation = _fake_anno(4)
    parent = _fake_anno(0)

    rt.create_template_map(request, annotation, parent)

    notification_serializer = request.registry.notification_serializer
    notification_serializer.dumps.assert_called_with({
        'type': REPLY_TYPE,
        'uri': parent['user'],
    })
Exemplo n.º 6
0
def test_unsubscribe_token_generation():
    """ensures that a serialized token is generated for the unsubscribe url"""
    request = _fake_request()
    annotation = _fake_anno(4)
    parent = _fake_anno(0)

    rt.create_template_map(request, annotation, parent)

    notification_serializer = request.registry.notification_serializer
    notification_serializer.dumps.assert_called_with({
        'type': REPLY_TYPE,
        'uri': parent['user'],
    })
Exemplo n.º 7
0
def test_unsubscribe_token_generation():
    """ensures that a serialized token is generated for the unsubscribe url"""
    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[4]

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

        notification_serializer = request.registry.notification_serializer
        notification_serializer.dumps.assert_called_with({
            'type': REPLY_TYPE,
            'uri': parent['user'],
        })
Exemplo n.º 8
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.º 9
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.º 10
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.º 11
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.º 12
0
def test_all_keys_are_there():
    """Checks for the existence of every needed key for the template"""
    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)

        assert 'document_title' in tmap
        assert 'document_path' in tmap
        assert 'parent_text' in tmap
        assert 'parent_user' in tmap
        assert 'parent_timestamp' in tmap
        assert 'parent_user_profile' in tmap
        assert 'parent_path' in tmap
        assert 'reply_text' in tmap
        assert 'reply_user' in tmap
        assert 'reply_timestamp' in tmap
        assert 'reply_user_profile' in tmap
        assert 'reply_path' in tmap
        assert 'unsubscribe' in tmap
Exemplo n.º 13
0
def test_all_keys_are_there():
    """Checks for the existence of every needed key for the template"""
    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)

        assert 'document_title' in tmap
        assert 'document_path' in tmap
        assert 'parent_text' in tmap
        assert 'parent_user' in tmap
        assert 'parent_timestamp' in tmap
        assert 'parent_user_profile' in tmap
        assert 'parent_path' in tmap
        assert 'reply_text' in tmap
        assert 'reply_user' in tmap
        assert 'reply_timestamp' in tmap
        assert 'reply_user_profile' in tmap
        assert 'reply_path' in tmap
        assert 'unsubscribe' in tmap
Exemplo n.º 14
0
def test_fallback_title():
    """Checks that the title falls back to using the url"""
    request = _fake_request()
    annotation = _fake_anno(4)
    parent = _fake_anno(0)

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

    assert tmap['document_title'] == annotation['uri']
Exemplo n.º 15
0
def test_create_template_map_when_parent_has_no_text():
    """It shouldn't crash if the parent annotation has no 'text' item."""
    rt.create_template_map(
        Mock(application_url='https://hypothes.is'),
        reply=Mock(
            document=Mock(title='Document Title'),
            userid='acct:[email protected]',
            text="This is Bob's annotation",
            created=datetime.datetime(2013, 10, 27, 19, 40, 53),
            id='0'
        ),
        parent=Mock(
            uri='http://example.com/example.html',
            userid='acct:[email protected]',
            created=datetime.datetime(2013, 10, 27, 19, 40, 53),
            id='1',
            text=None  # Parent annotation has no 'text' item.
        ))
Exemplo n.º 16
0
def test_fallback_title():
    """Checks that the title falls back to using the url"""
    request = _fake_request()
    annotation = _fake_anno(4)
    parent = _fake_anno(0)

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

    assert tmap['document_title'] == annotation['uri']
Exemplo n.º 17
0
def test_unsubscribe_token_generation():
    """ensures that a serialized token is generated for the unsubscribe url"""
    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[4]

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

        notification_serializer = request.registry.notification_serializer
        notification_serializer.dumps.assert_called_with({
            'type': REPLY_TYPE,
            'uri': data['parent']['user'],
        })
Exemplo n.º 18
0
def test_create_template_map_when_parent_has_no_text():
    """It shouldn't crash if the parent annotation has no 'text' item."""
    rt.create_template_map(
        Mock(application_url="https://hypothes.is"),
        reply={
            "document": {"title": "Document Title"},
            "user": "******",
            "text": "This is Bob's annotation",
            "created": "2013-10-27T19:40:53.245691+00:00",
            "id": "0",
        },
        # parent dict has no 'text' item.
        parent={
            "uri": "http://example.com/example.html",
            "user": "******",
            "created": "2013-10-27T19:40:53.245691+00:00",
            "id": "1",
        },
    )
Exemplo n.º 19
0
def test_fallback_title():
    """Checks that the title falls back to using the url"""
    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[4]

        parent = rt.parent_values(annotation)
        tmap = rt.create_template_map(request, annotation, parent)
        assert tmap['document_title'] == annotation['uri']
Exemplo n.º 20
0
def test_create_template_map_when_parent_has_no_text():
    """It shouldn't crash if the parent annotation has no 'text' item."""
    rt.create_template_map(
            Mock(application_url='https://hypothes.is'),
        reply={
            'document': {
                'title': 'Document Title'
            },
            'user': '******',
            'text': "This is Bob's annotation",
            'created': '2013-10-27T19:40:53.245691+00:00',
            'id': '0'
        },
        # parent dict has no 'text' item.
        parent={
            'uri': 'http://example.com/example.html',
            'user': '******',
            'created': '2013-10-27T19:40:53.245691+00:00',
            'id': '1'
        })
Exemplo n.º 21
0
def test_create_template_map_when_parent_has_no_text():
    """It shouldn't crash if the parent annotation has no 'text' item."""
    rt.create_template_map(
        Mock(application_url='https://hypothes.is'),
        reply={
            'document': {
                'title': 'Document Title'
            },
            'user': '******',
            'text': "This is Bob's annotation",
            'created': '2013-10-27T19:40:53.245691+00:00',
            'id': '0'
        },
        # parent dict has no 'text' item.
        parent={
            'uri': 'http://example.com/example.html',
            'user': '******',
            'created': '2013-10-27T19:40:53.245691+00:00',
            'id': '1'
        })
Exemplo n.º 22
0
def test_fallback_title():
    """Checks that the title falls back to using the url"""
    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[4]

        data = {
            'parent': rt.parent_values(annotation),
            'subscription': {'id': 1}
        }
        tmap = rt.create_template_map(request, annotation, data)
        assert tmap['document_title'] == annotation['uri']
Exemplo n.º 23
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.º 24
0
def test_all_keys_are_there():
    """Checks for the existence of every needed key for the template"""
    request = _fake_request()
    annotation = _fake_anno(1)
    parent = _fake_anno(0)

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

    assert 'document_title' in tmap
    assert 'document_path' in tmap
    assert 'parent_text' in tmap
    assert 'parent_user' in tmap
    assert 'parent_timestamp' in tmap
    assert 'parent_user_profile' in tmap
    assert 'parent_path' in tmap
    assert 'reply_text' in tmap
    assert 'reply_user' in tmap
    assert 'reply_timestamp' in tmap
    assert 'reply_user_profile' in tmap
    assert 'reply_path' in tmap
    assert 'unsubscribe' in tmap
Exemplo n.º 25
0
def test_all_keys_are_there():
    """Checks for the existence of every needed key for the template"""
    request = _fake_request()
    annotation = _fake_anno(1)
    parent = _fake_anno(0)

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

    assert 'document_title' in tmap
    assert 'document_path' in tmap
    assert 'parent_text' in tmap
    assert 'parent_user' in tmap
    assert 'parent_timestamp' in tmap
    assert 'parent_user_profile' in tmap
    assert 'parent_path' in tmap
    assert 'reply_text' in tmap
    assert 'reply_user' in tmap
    assert 'reply_timestamp' in tmap
    assert 'reply_user_profile' in tmap
    assert 'reply_path' in tmap
    assert 'unsubscribe' in tmap
Exemplo n.º 26
0
def test_all_keys_are_there():
    """Checks for the existence of every needed key for the template"""
    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)

        assert 'document_title' in tmap
        assert 'document_path' in tmap
        assert 'parent_text' in tmap
        assert 'parent_user' in tmap
        assert 'parent_timestamp' in tmap
        assert 'parent_user_profile' in tmap
        assert 'parent_path' in tmap
        assert 'reply_text' in tmap
        assert 'reply_user' in tmap
        assert 'reply_timestamp' in tmap
        assert 'reply_user_profile' in tmap
        assert 'reply_path' in tmap
        assert 'unsubscribe' in tmap