示例#1
0
    def test_annotations_of_multiple_documents_in_one_timeframe(
            self, annotation_datetime, timeframe_label):
        document_1 = factories.Document()
        document_2 = factories.Document()
        document_3 = factories.Document()
        results = [
            factories.Annotation(document=document_1,
                                 updated=annotation_datetime),
            factories.Annotation(document=document_2,
                                 updated=annotation_datetime),
            factories.Annotation(document=document_3,
                                 updated=annotation_datetime),
        ]

        timeframes = bucketing.bucket(results)

        assert timeframes == [
            timeframe_with(
                timeframe_label, {
                    document_1: bucketing.DocumentBucket(
                        document_1, [results[0]]),
                    document_2: bucketing.DocumentBucket(
                        document_2, [results[1]]),
                    document_3: bucketing.DocumentBucket(
                        document_3, [results[2]]),
                }),
        ]
示例#2
0
    def test_annotations_from_different_days_in_same_month(self):
        """
        Test bucketing multiple annotations from different days of same month.

        Annotations from different days of the same month should go into one
        bucket.

        """
        document = factories.Document()
        one_month_ago = UTCNOW - datetime.timedelta(days=30)
        annotations = [
            factories.Annotation(document=document, updated=one_month_ago),
            factories.Annotation(document=document,
                                 updated=one_month_ago -
                                 datetime.timedelta(days=1)),
            factories.Annotation(document=document,
                                 updated=one_month_ago -
                                 datetime.timedelta(days=2)),
        ]

        timeframes = bucketing.bucket(annotations)

        expected_bucket = bucketing.DocumentBucket(document)
        expected_bucket.update(annotations)

        assert timeframes == [
            timeframe_with('Jan 1970', {document: expected_bucket})
        ]
示例#3
0
    def test_one_annotation(self, annotation_datetime, timeframe_label):
        annotation = factories.Annotation(document=factories.Document(),
                                          updated=annotation_datetime)

        timeframes = bucketing.bucket([annotation])

        assert timeframes == [
            timeframe_with(timeframe_label, {
                annotation.document: bucketing.DocumentBucket(annotation.document, [annotation])
            })
        ]
示例#4
0
    def test_one_annotation(self, annotation_datetime, timeframe_label):
        document = factories.Document()
        results = [
            factories.Annotation(document=document,
                                 updated=annotation_datetime)
        ]

        timeframes = bucketing.bucket(results)

        assert timeframes == [
            timeframe_with(
                timeframe_label,
                {document: bucketing.DocumentBucket(document, results)})
        ]
示例#5
0
    def test_multiple_annotations_of_one_document_in_one_timeframe(
            self, annotation_datetime, timeframe_label):
        document = factories.Document()
        results = [
            factories.Annotation(document=document,
                                 updated=annotation_datetime) for _ in range(3)
        ]

        timeframes = bucketing.bucket(results)

        assert timeframes == [
            timeframe_with(
                timeframe_label,
                {document: bucketing.DocumentBucket(document, results)}),
        ]
示例#6
0
    def test_annotations_of_the_same_document_in_different_timeframes(self):
        document = factories.Document()
        results = [
            factories.Annotation(document=document),
            factories.Annotation(document=document,
                                 updated=FIFTH_NOVEMBER_1969),
            factories.Annotation(document=document, updated=THIRD_MARCH_1968),
        ]

        timeframes = bucketing.bucket(results)

        expected_bucket_1 = bucketing.DocumentBucket(document, [results[0]])
        expected_bucket_2 = bucketing.DocumentBucket(document, [results[1]])
        expected_bucket_3 = bucketing.DocumentBucket(document, [results[2]])

        assert timeframes == [
            timeframe_with('Last 7 days', {document: expected_bucket_1}),
            timeframe_with('Nov 1969', {document: expected_bucket_2}),
            timeframe_with('Mar 1968', {document: expected_bucket_3}),
        ]
示例#7
0
    def test_annotations_of_the_same_document_in_different_timeframes(self):
        results = [
            factories.Annotation(),
            factories.Annotation(updated=FIFTH_NOVEMBER_1969),
            factories.Annotation(updated=THIRD_MARCH_1968),
        ]
        document = factories.Document()
        for annotation in results:
            annotation.document = document

        timeframes = bucketing.bucket(results)

        expected_bucket_1 = bucketing.DocumentBucket(document, [results[0]])
        expected_bucket_2 = bucketing.DocumentBucket(document, [results[1]])
        expected_bucket_3 = bucketing.DocumentBucket(document, [results[2]])

        assert timeframes == [
            timeframe_with("Last 7 days", {document: expected_bucket_1}),
            timeframe_with("Nov 1969", {document: expected_bucket_2}),
            timeframe_with("Mar 1968", {document: expected_bucket_3}),
        ]
示例#8
0
    def test_recent_and_older_annotations_together(self):
        document_1 = factories.Document()
        document_2 = factories.Document()
        document_3 = factories.Document()
        document_4 = factories.Document()
        document_5 = factories.Document()
        document_6 = factories.Document()
        results = [
            factories.Annotation(document=document_1),
            factories.Annotation(document=document_2),
            factories.Annotation(document=document_3),
            factories.Annotation(document=document_4,
                                 updated=THIRD_MARCH_1968),
            factories.Annotation(document=document_5,
                                 updated=THIRD_MARCH_1968),
            factories.Annotation(document=document_6,
                                 updated=THIRD_MARCH_1968),
        ]

        timeframes = bucketing.bucket(results)

        expected_bucket_1 = bucketing.DocumentBucket(document_1, [results[0]])
        expected_bucket_2 = bucketing.DocumentBucket(document_2, [results[1]])
        expected_bucket_3 = bucketing.DocumentBucket(document_3, [results[2]])
        expected_bucket_4 = bucketing.DocumentBucket(document_4, [results[3]])
        expected_bucket_5 = bucketing.DocumentBucket(document_5, [results[4]])
        expected_bucket_6 = bucketing.DocumentBucket(document_6, [results[5]])

        assert timeframes == [
            timeframe_with(
                'Last 7 days', {
                    document_1: expected_bucket_1,
                    document_2: expected_bucket_2,
                    document_3: expected_bucket_3,
                }),
            timeframe_with(
                'Mar 1968', {
                    document_4: expected_bucket_4,
                    document_5: expected_bucket_5,
                    document_6: expected_bucket_6,
                }),
        ]
示例#9
0
 def document(self, db_session):
     document = factories.Document()
     db_session.add(document)
     db_session.flush()
     return document