Exemple #1
0
import datetime
import pytest

from sleuth.services import format_slack_id, prepare_sns_message, prepare_slack_message
from sleuth.auditor import Key, User

created = datetime.datetime(2019, 1, 1, tzinfo=datetime.timezone.utc)
lastused = created = datetime.datetime(2019,
                                       1,
                                       3,
                                       tzinfo=datetime.timezone.utc)
# 4 users to represent the 4 audit states
user1 = User('user1', 'slackuser1', 'U12345')
key1 = Key('user1', 'asdfksakfa', 'Active', created, lastused)
key1.audit_state = 'old'

user2 = User('user2', 'slackuser2', 'U67890')
key2 = Key('user2', 'ldasfkk', 'Active', created, lastused)
key2.audit_state = 'expire'

user3 = User('user3', 'slackuser3', 'U13579')
key3 = Key('user3', 'oithsetc', 'Active', created, lastused)
key3.audit_state = 'stagnant'

user4 = User('user4', 'slackuser4', 'U24680')
key4 = Key('user4', 'bajaoietnb', 'Active', created, lastused)
key4.audit_state = 'stagnant_expire'

user1.keys = [key1]
user2.keys = [key2]
from freezegun import freeze_time

import datetime
import pytest

from sleuth.services import format_slack_id, prepare_sns_message, prepare_slack_message
from sleuth.auditor import Key, User

created = datetime.datetime(2019, 1, 1, tzinfo=datetime.timezone.utc)
user1 = User('user1', 'slackuser1', 'U12345')
user2 = User('user1', 'slackuser1', 'U67890')
key1 = Key('user1', 'asdfksakfa', 'Active', created)
key1.audit_state = 'old'
key2 = Key('user2', 'ldasfkk', 'Active', created)
key2.audit_state = 'expire'
user1.keys = [key1]
user2.keys = [key2]
users = [user1, user2]


class TestFormatSlackID():
    def test_empty_input(self):
        """Test empty input"""
        # None input
        resp = format_slack_id(None)
        assert resp == 'UNKNOWN'

        # empty input
        resp = format_slack_id('')
        assert resp == 'UNKNOWN'