コード例 #1
0
ファイル: reply_template_test.py プロジェクト: oliversauter/h
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"
コード例 #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'
コード例 #3
0
ファイル: reply_template_test.py プロジェクト: Forethinker/h
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
コード例 #4
0
ファイル: reply_template_test.py プロジェクト: robertknight/h
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
コード例 #5
0
ファイル: reply_template_test.py プロジェクト: chrber/h
def test_parent_values_root_annotation():
    """Test if it gives back an empty dict for root annotations"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
        annotation = store_fake_data[0]
        parent = rt.parent_values(annotation)

        assert len(parent.items()) == 0
コード例 #6
0
ファイル: reply_template_test.py プロジェクト: robertknight/h
def test_parent_values_reply():
    """Test if the function gives back the correct parent_value"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
        annotation = store_fake_data[1]
        parent = rt.parent_values(annotation)

        assert parent['id'] == '0'
コード例 #7
0
ファイル: reply_template_test.py プロジェクト: chrber/h
def test_parent_values_reply():
    """Test if the function gives back the correct parent_value"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
        annotation = store_fake_data[1]
        parent = rt.parent_values(annotation)

        assert parent['id'] == '0'
コード例 #8
0
ファイル: reply_template_test.py プロジェクト: robertknight/h
def test_parent_values_root_annotation():
    """Test if it gives back an empty dict for root annotations"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
        annotation = store_fake_data[0]
        parent = rt.parent_values(annotation)

        assert len(parent.items()) == 0
コード例 #9
0
ファイル: reply_template_test.py プロジェクト: Treora/h
def test_parent_values_second_level_reply():
    """Test if it the grandparent values are filled for a second level reply"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
        annotation = store_fake_data[2]
        parent = rt.parent_values(annotation)

        assert parent['id'] == '1'
        assert parent['quote'] == store_fake_data[0]['text']
コード例 #10
0
ファイル: reply_template_test.py プロジェクト: Forethinker/h
def test_parent_values_second_level_reply():
    """Test if it the grandparent values are filled for a second level reply"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
        annotation = store_fake_data[2]
        parent = rt.parent_values(annotation)

        assert parent['id'] == '1'
        assert parent['quote'] == store_fake_data[0]['text']
コード例 #11
0
ファイル: reply_template_test.py プロジェクト: oliversauter/h
def test_dont_send_if_parent_is_missing():
    """Tests that this function returns False if the annotations parent's user is missing"""
    with patch("h.notification.reply_template.Annotation") as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)

        annotation = store_fake_data[3]
        data = {"parent": rt.parent_values(annotation), "subscription": {"id": 1}}

        send = rt.check_conditions(annotation, data)
        assert send is False
コード例 #12
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']
コード例 #13
0
ファイル: reply_template_test.py プロジェクト: oliversauter/h
def test_good_conditions():
    """If conditions match, this function returns with a True value"""
    with patch("h.notification.reply_template.Annotation") as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)

        annotation = store_fake_data[1]
        data = {"parent": rt.parent_values(annotation), "subscription": {"id": 1, "uri": "acct:[email protected]"}}

        send = rt.check_conditions(annotation, data)
        assert send is True
コード例 #14
0
ファイル: reply_template_test.py プロジェクト: oliversauter/h
def test_dont_send_to_the_same_user():
    """Tests that if the parent user and the annotation user is the same
    then this function returns False"""
    with patch("h.notification.reply_template.Annotation") as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)

        annotation = store_fake_data[0]
        data = {"parent": rt.parent_values(annotation), "subscription": {"id": 1}}

        send = rt.check_conditions(annotation, data)
        assert send is False
コード例 #15
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')
コード例 #16
0
ファイル: reply_template_test.py プロジェクト: oliversauter/h
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"]})
コード例 #17
0
def test_dont_send_if_parent_is_missing():
    """Tests that this function returns False if the annotations parent's user is missing"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)

        annotation = store_fake_data[3]
        data = {
            'parent': rt.parent_values(annotation),
            'subscription': {'id': 1}
        }

        send = rt.check_conditions(annotation, data)
        assert send is False
コード例 #18
0
ファイル: reply_template_test.py プロジェクト: oliversauter/h
def test_different_subscription():
    """If subscription.uri is different from user, do not send!"""
    with patch("h.notification.reply_template.Annotation") as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)

        annotation = store_fake_data[1]
        data = {
            "parent": rt.parent_values(annotation),
            "subscription": {"id": 1, "uri": "acct:[email protected]"},
        }

        send = rt.check_conditions(annotation, data)
        assert send is False
コード例 #19
0
def test_dont_send_to_the_same_user():
    """Tests that if the parent user and the annotation user is the same
    then this function returns False"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)

        annotation = store_fake_data[0]
        data = {
            'parent': rt.parent_values(annotation),
            'subscription': {'id': 1}
        }

        send = rt.check_conditions(annotation, data)
        assert send is False
コード例 #20
0
ファイル: reply_template_test.py プロジェクト: nshkuro/h
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']
コード例 #21
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'],
        })
コード例 #22
0
def test_get_email():
    """Tests whether it gives back the user.email property"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
        with patch('h.notification.reply_template.get_user_by_name') as mock_user_db:
            user = Mock()
            user.email = '*****@*****.**'
            mock_user_db.return_value = user
            request = _create_request()

            annotation = store_fake_data[1]
            parent = rt.parent_values(annotation)

            email = rt.get_recipients(request, parent)
            assert email[0] == user.email
コード例 #23
0
ファイル: reply_template_test.py プロジェクト: robertknight/h
def test_good_conditions():
    """If conditions match, this function returns with a True value"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)

        annotation = store_fake_data[1]
        data = {
            'parent': rt.parent_values(annotation),
            'subscription': {
                'id': 1,
                'uri': 'acct:[email protected]'
            }
        }

        send = rt.check_conditions(annotation, data)
        assert send is True
コード例 #24
0
ファイル: reply_template_test.py プロジェクト: chrber/h
def test_good_conditions():
    """If conditions match, this function returns with a True value"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)

        annotation = store_fake_data[1]
        data = {
            'parent': rt.parent_values(annotation),
            'subscription': {
                'id': 1,
                'uri': 'acct:[email protected]'
            }
        }

        send = rt.check_conditions(annotation, data)
        assert send is True
コード例 #25
0
ファイル: reply_template_test.py プロジェクト: robertknight/h
def test_different_subscription():
    """If subscription.uri is different from user, do not send!"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)

        annotation = store_fake_data[1]
        data = {
            'parent': rt.parent_values(annotation),
            'subscription': {
                'id': 1,
                'uri': 'acct:[email protected]'
            }
        }

        send = rt.check_conditions(annotation, data)
        assert send is False
コード例 #26
0
ファイル: reply_template_test.py プロジェクト: chrber/h
def test_different_subscription():
    """If subscription.uri is different from user, do not send!"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)

        annotation = store_fake_data[1]
        data = {
            'parent': rt.parent_values(annotation),
            'subscription': {
                'id': 1,
                'uri': 'acct:[email protected]'
            }
        }

        send = rt.check_conditions(annotation, data)
        assert send is False
コード例 #27
0
ファイル: reply_template_test.py プロジェクト: Forethinker/h
def test_dont_send_to_the_same_user():
    """Tests that if the parent user and the annotation user is the same
    then this function returns False"""
    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[0]
        data = {
            'parent': rt.parent_values(annotation),
            'subscription': {'id': 1}
        }

        send = rt.check_conditions(annotation, data)
        assert send is False
コード例 #28
0
def test_no_email():
    """If user has no email we must throw an exception"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
        with patch('h.notification.reply_template.get_user_by_name') as mock_user_db:
            mock_user_db.return_value = {}
            request = _create_request()

            annotation = store_fake_data[1]
            parent = rt.parent_values(annotation)

            exc = False
            try:
                rt.get_recipients(request, parent)
            except:
                exc = True
            assert exc
コード例 #29
0
ファイル: reply_template_test.py プロジェクト: Forethinker/h
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
コード例 #30
0
ファイル: reply_template_test.py プロジェクト: bbarker/h
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'],
        })
コード例 #31
0
ファイル: reply_template_test.py プロジェクト: Forethinker/h
def test_get_email():
    """Tests whether it gives back the user.email property"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
        with patch('h.notification.reply_template.get_user_by_name') as mock_user_db:
            user = Mock()
            user.email = '*****@*****.**'
            mock_user_db.return_value = user
            request = DummyRequest()
            request.domain = 'www.howtoreachtheark.now'

            annotation = store_fake_data[1]
            data = {
                'parent': rt.parent_values(annotation),
                'subscription': {'id': 1}
            }

            email = rt.get_recipients(request, data)
            assert email[0] == user.email
コード例 #32
0
ファイル: reply_template_test.py プロジェクト: Forethinker/h
def test_no_email():
    """If user has no email we must throw an exception"""
    with patch('h.notification.reply_template.Annotation') as mock_annotation:
        mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
        with patch('h.notification.reply_template.get_user_by_name') as mock_user_db:
            mock_user_db.return_value = {}
            request = DummyRequest()
            request.domain = 'www.howtoreachtheark.now'

            annotation = store_fake_data[1]
            data = {
                'parent': rt.parent_values(annotation),
                'subscription': {'id': 1}
            }

            exc = False
            try:
                rt.get_recipients(request, data)
            except:
                exc = True
            assert exc
コード例 #33
0
ファイル: reply_template_test.py プロジェクト: chrber/h
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