Ejemplo n.º 1
0
    def ignore_event_fingerprint(
        self,
        fingerprint: str,
        ignore_type: str,
        expires_at: Optional[datetime] = None,
        reported_at: Optional[datetime] = None,
        record_metadata: Optional[datetime] = None,
    ) -> None:
        """Add a fingerprint to the list of ignored events.

        Args:
            fingerprint: fingerprint of the event to ignore
            ignore_type: the type (reason) for ignoring, for example IgnoreFingerprintRecord.SNOOZE
            expires_at: specify the time of the ignore expiration
            reported_at: specify the time of the reported date
            record_metadata: metadata to hydrate the record with.
        """
        new_record = IgnoreFingerprintRecord(
            fingerprint=fingerprint,
            ignore_type=ignore_type,
            expires_at=expires_at,
            reported_at=reported_at,
            record_metadata=record_metadata,
        )
        with self.session.begin() as session:
            session.add(new_record)
Ejemplo n.º 2
0
def test_get_interactions_for_fingerprint(ds_instance):
    one_a = IgnoreFingerprintRecord(
        id=1,
        fingerprint="f1",
        ignore_type="resolved",
        reported_at=datetime(2019, 1, 1, 0, 0, 11),
        expires_at=datetime(2019, 1, 7, 0, 0, 11),
        record_metadata=None,
    )
    fingerprint = "f1"
    ds_instance.ignore_event_fingerprint(
        fingerprint,
        ignore_type=one_a.ignore_type,
        record_metadata=one_a.record_metadata,
        reported_at=one_a.reported_at,
        expires_at=one_a.expires_at,
    )

    expected = [{
        "id": 1,
        "fingerprint": "f1",
        "ignore_type": "resolved",
        "reported_at": datetime(2019, 1, 1, 0, 0, 11),
        "expires_at": datetime(2019, 1, 7, 0, 0, 11),
    }]
    result = ds_instance.get_interactions_fingerprint(fingerprint)
    assert result == expected
Ejemplo n.º 3
0
def test_get_interactions_for_fingerprint(data_store):
    """Test fingerprint interaction of the data store.

    Create an IgnoreFingerprintRecord, store it in the data store and read it back to ensure it has been stored
    properly.
    """
    one_a = IgnoreFingerprintRecord(
        id=1,
        fingerprint="f1",
        ignore_type="resolved",
        reported_at=datetime(2019, 1, 1, 0, 0, 11),
        expires_at=datetime(2019, 1, 7, 0, 0, 11),
        record_metadata=None,
    )
    fingerprint = "f1"
    data_store.ignore_event_fingerprint(
        fingerprint,
        ignore_type=one_a.ignore_type,
        record_metadata=one_a.record_metadata,
        reported_at=one_a.reported_at,
        expires_at=one_a.expires_at,
    )

    expected = [{
        "id": 1,
        "fingerprint": "f1",
        "ignore_type": "resolved",
        "reported_at": datetime(2019, 1, 1, 0, 0, 11),
        "expires_at": datetime(2019, 1, 7, 0, 0, 11),
    }]
    result = data_store.get_interactions_fingerprint(fingerprint)
    assert result == expected
Ejemplo n.º 4
0
def test_get_open_issues(*_):
    data_store = comet_core.data_store.DataStore("sqlite://")

    one = EventRecord(source_type="test_type",
                      fingerprint="f1",
                      received_at=datetime.utcnow(),
                      owner="test")
    data_store.add_record(one)

    two = EventRecord(source_type="test_type",
                      fingerprint="f2",
                      received_at=datetime.utcnow() - timedelta(days=0.9),
                      owner="test")
    data_store.add_record(two)

    three = EventRecord(source_type="test_type",
                        fingerprint="f3",
                        received_at=datetime.utcnow() - timedelta(days=2),
                        owner="test")
    data_store.add_record(three)

    four = EventRecord(source_type="test_type",
                       fingerprint="f4",
                       received_at=datetime.utcnow(),
                       owner="not_test")
    data_store.add_record(four)

    five = EventRecord(source_type="test_type",
                       fingerprint="f5",
                       received_at=datetime.utcnow() - timedelta(days=1.5),
                       owner="not_test")
    data_store.add_record(five)

    six = EventRecord(source_type="test_type",
                      fingerprint="f2",
                      received_at=datetime.utcnow() - timedelta(days=0.2),
                      owner="test")
    data_store.add_record(six)

    open_issues = data_store.get_open_issues(["test"])
    assert len(open_issues) == 2

    open_issues = data_store.get_open_issues(["test", "not_test"])
    assert len(open_issues) == 3

    test_snooze_record = IgnoreFingerprintRecord(
        fingerprint="f1",
        ignore_type=IgnoreFingerprintRecord.SNOOZE,
        reported_at=datetime(2018, 2, 22, 0, 0, 11),
        expires_at=datetime(3000, 2, 23, 0, 0, 11),
    )

    data_store.add_record(test_snooze_record)

    open_issues = data_store.get_open_issues(["test"])
    assert len(open_issues) == 1
Ejemplo n.º 5
0
def test_get_open_issues(data_store):
    """Tests getting open issues by adding events of different types and check how many are still open."""

    one = EventRecord(source_type="test_type",
                      fingerprint="f1",
                      received_at=datetime.utcnow(),
                      owner="test")
    data_store.add_record(one)

    two = EventRecord(source_type="test_type",
                      fingerprint="f2",
                      received_at=datetime.utcnow() - timedelta(days=0.9),
                      owner="test")
    data_store.add_record(two)

    three = EventRecord(source_type="test_type",
                        fingerprint="f3",
                        received_at=datetime.utcnow() - timedelta(days=2),
                        owner="test")
    data_store.add_record(three)

    four = EventRecord(source_type="test_type",
                       fingerprint="f4",
                       received_at=datetime.utcnow(),
                       owner="not_test")
    data_store.add_record(four)

    five = EventRecord(source_type="test_type",
                       fingerprint="f5",
                       received_at=datetime.utcnow() - timedelta(days=1.5),
                       owner="not_test")
    data_store.add_record(five)

    six = EventRecord(source_type="test_type",
                      fingerprint="f2",
                      received_at=datetime.utcnow() - timedelta(days=0.2),
                      owner="test")
    data_store.add_record(six)

    open_issues = data_store.get_open_issues(["test"])
    assert len(open_issues) == 2

    open_issues = data_store.get_open_issues(["test", "not_test"])
    assert len(open_issues) == 3

    test_snooze_record = IgnoreFingerprintRecord(
        fingerprint="f1",
        ignore_type=IgnoreFingerprintRecord.SNOOZE,
        reported_at=datetime(2018, 2, 22, 0, 0, 11),
        expires_at=datetime(3000, 2, 23, 0, 0, 11),
    )

    data_store.add_record(test_snooze_record)

    open_issues = data_store.get_open_issues(["test"])
    assert len(open_issues) == 1
Ejemplo n.º 6
0
def test_get_open_issues(*_):
    data_store = comet_core.data_store.DataStore('sqlite://')

    one = EventRecord(source_type='test_type',
                      fingerprint='f1',
                      received_at=datetime.utcnow(),
                      owner='test')
    data_store.add_record(one)

    two = EventRecord(source_type='test_type',
                      fingerprint='f2',
                      received_at=datetime.utcnow() - timedelta(days=.9),
                      owner='test')
    data_store.add_record(two)

    three = EventRecord(source_type='test_type',
                        fingerprint='f3',
                        received_at=datetime.utcnow() - timedelta(days=2),
                        owner='test')
    data_store.add_record(three)

    four = EventRecord(source_type='test_type',
                       fingerprint='f4',
                       received_at=datetime.utcnow(),
                       owner='not_test')
    data_store.add_record(four)

    five = EventRecord(source_type='test_type',
                       fingerprint='f5',
                       received_at=datetime.utcnow() - timedelta(days=1.5),
                       owner='not_test')
    data_store.add_record(five)

    six = EventRecord(source_type='test_type',
                      fingerprint='f2',
                      received_at=datetime.utcnow() - timedelta(days=.2),
                      owner='test')
    data_store.add_record(six)

    open_issues = data_store.get_open_issues(['test'])
    assert len(open_issues) == 2

    open_issues = data_store.get_open_issues(['test', 'not_test'])
    assert len(open_issues) == 3

    test_snooze_record = IgnoreFingerprintRecord(
        fingerprint='f1',
        ignore_type=IgnoreFingerprintRecord.SNOOZE,
        reported_at=datetime(2018, 2, 22, 0, 0, 11),
        expires_at=datetime(3000, 2, 23, 0, 0, 11))

    data_store.add_record(test_snooze_record)

    open_issues = data_store.get_open_issues(['test'])
    assert len(open_issues) == 1
Ejemplo n.º 7
0
 def ignore_event_fingerprint(self, fingerprint, ignore_type, expires_at=None):
     """Add a fingerprint to the list of ignored events
     Args:
         fingerprint (str): fingerprint of the event to ignore
         ignore_type (str): the type (reason) for ignoring, for example IgnoreFingerprintRecord.SNOOZE
         expires_at (datetime.datetime): specify the time of the ignore expiration
     """
     new_record = IgnoreFingerprintRecord(fingerprint=fingerprint, ignore_type=ignore_type, expires_at=expires_at)
     self.session.begin()
     self.session.add(new_record)
     self.session.commit()
Ejemplo n.º 8
0
def test_check_snoozed_event(data_store):
    """Check that snoozed events are not ignored."""
    test_fingerprint2 = "f2"

    test_snooze_record = IgnoreFingerprintRecord(
        fingerprint=test_fingerprint2,
        ignore_type=IgnoreFingerprintRecord.SNOOZE,
        reported_at=datetime(2018, 2, 22, 0, 0, 11),
        expires_at=datetime(2018, 2, 23, 0, 0, 11),
    )
    data_store.add_record(test_snooze_record)
    assert not data_store.fingerprint_is_ignored(test_fingerprint2)
Ejemplo n.º 9
0
def test_check_snoozed_event_fingerprint():
    data_store = comet_core.data_store.DataStore('sqlite://')

    test_fingerprint1 = 'f1'
    test_fingerprint2 = 'f2'

    assert not data_store.fingerprint_is_ignored(test_fingerprint1)

    data_store.ignore_event_fingerprint(test_fingerprint1, ignore_type=IgnoreFingerprintRecord.SNOOZE,
                                        expires_at=datetime.utcnow() + timedelta(days=30))
    assert data_store.fingerprint_is_ignored(test_fingerprint1)

    test_snooze_record = IgnoreFingerprintRecord(fingerprint=test_fingerprint2,
                                                 ignore_type=IgnoreFingerprintRecord.SNOOZE,
                                                 reported_at=datetime(2018, 2, 22, 0, 0, 11),
                                                 expires_at=datetime(2018, 2, 23, 0, 0, 11))
    data_store.add_record(test_snooze_record)
    assert not data_store.fingerprint_is_ignored(test_fingerprint2)
Ejemplo n.º 10
0
 def ignore_event_fingerprint(self,
                              fingerprint,
                              ignore_type,
                              expires_at=None,
                              reported_at=None,
                              record_metadata=None):
     """Add a fingerprint to the list of ignored events
     Args:
         fingerprint (str): fingerprint of the event to ignore
         ignore_type (str): the type (reason) for ignoring, for example IgnoreFingerprintRecord.SNOOZE
         expires_at (datetime.datetime): specify the time of the ignore expiration
         reported_at (datetime.datetime): specify the time of the reported date
         record_metadata (dict): metadata to hydrate the record with.
     """
     new_record = IgnoreFingerprintRecord(
         fingerprint=fingerprint,
         ignore_type=ignore_type,
         expires_at=expires_at,
         reported_at=reported_at,
         record_metadata=record_metadata,
     )
     self.session.begin()
     self.session.add(new_record)
     self.session.commit()