예제 #1
0
def make_command_parser(config: Config,
                        gh: Optional[GithubInterface] = None) \
        -> CommandParser:
    """
    Initialize and returns a :class:`CommandParser` object.

    :return: a new ``CommandParser`` object, freshly initialized
    """
    slack_api_token, slack_notification_channel = "", ""
    signing_key = ""
    if not config.testing:
        slack_api_token = config.slack_api_token
        github_auth_key = config.github_key
        github_app_id = config.github_app_id
        github_organization = config.github_org_name
        slack_notification_channel = config.slack_notification_channel
        gh = GithubInterface(DefaultGithubFactory(github_app_id,
                                                  github_auth_key),
                             github_organization)
        signing_key = config.github_key
    facade = DBFacade(DynamoDB(config))
    bot = Bot(WebClient(slack_api_token), slack_notification_channel)
    # TODO: make token config expiry configurable
    token_config = TokenCommandConfig(timedelta(days=7), signing_key)
    return CommandParser(facade, bot, cast(GithubInterface, gh), token_config)
예제 #2
0
def make_github_webhook_handler(config: Config) -> GitHubWebhookHandler:
    """
    Initialize a :class:`GitHubWebhookHandler` object.

    :return: a new ``GitHubWebhookHandler`` object, freshly initialized
    """
    facade = DBFacade(DynamoDB(config))
    return GitHubWebhookHandler(facade, config)
예제 #3
0
def make_slack_events_handler(config: Config) -> SlackEventsHandler:
    """
    Initialize a :class:`SlackEventsHandler` object.

    :return: a new ``SlackEventsHandler`` object, freshly initialized
    """
    facade = DBFacade(DynamoDB(config))
    bot = Bot(WebClient(config.slack_api_token),
              config.slack_notification_channel)
    return SlackEventsHandler(facade, bot)
예제 #4
0
def sync_user_email_perms(gcp: Optional[GCPInterface],
                          db: DBFacade,
                          user: User):
    """
    Refresh Google Drive permissions for a provided user. If no GCP client is
    provided, this function is a no-op.

    Finds folders for user by checking all teams the user is a part of, and
    calling ``sync_team_email_perms()``.
    """
    if gcp is None:
        logging.debug('GCP not enabled, skipping drive permissions')
        return

    if len(user.email) == 0 or len(user.github_id) == 0:
        return

    teams_user_is_in = db.query(Team, [('members', user.github_id)])
    for team in teams_user_is_in:
        sync_team_email_perms(gcp, db, team)
예제 #5
0
def test_retrieve_project(ddb):
    """Test retrieving project calls correct functions."""
    dbf = DBFacade(ddb)
    project_id = 'brussel-sprouts'
    dbf.retrieve(Project, project_id)
    ddb.retrieve.assert_called_with(Project, project_id)
예제 #6
0
def test_retrieve_team(ddb):
    """Test retrieving team calls correct functions."""
    dbf = DBFacade(ddb)
    team_name = 'brussel-sprouts'
    dbf.retrieve(Team, team_name)
    ddb.retrieve.assert_called_with(Team, team_name)
예제 #7
0
def test_delete_user(ddb):
    """Test deleting user calls correct functions."""
    dbf = DBFacade(ddb)
    slack_id = 'abc_123'
    dbf.delete(User, slack_id)
    ddb.delete.assert_called_with(User, slack_id)
예제 #8
0
def test_query_project(ddb):
    """Test querying project calls correct functions."""
    dbf = DBFacade(ddb)
    dbf.query(Project, [('platform', 'slack')])
    ddb.query.assert_called_with(Project, [('platform', 'slack')])
예제 #9
0
def test_string_rep(ddb):
    """Test string representation of the DBFacade class."""
    assert str(DBFacade(ddb)) == "Database Facade"
예제 #10
0
def test_delete_team(ddb):
    """Test deleting team calls correct functions."""
    dbf = DBFacade(ddb)
    team_name = 'brussel-sprouts'
    dbf.delete(Team, team_name)
    ddb.delete.assert_called_with(Team, team_name)
예제 #11
0
def test_query_or_team(ddb):
    """Test querying teams."""
    dbf = DBFacade(ddb)
    params = [('github_team_id', str(team_id)) for team_id in range(10)]
    dbf.query_or(Team, params)
    ddb.query_or.assert_called_with(Team, params)
예제 #12
0
def test_query_team(ddb):
    """Test querying team calls correct functions."""
    dbf = DBFacade(ddb)
    dbf.query(Team, [('platform', 'slack')])
    ddb.query.assert_called_with(Team, [('platform', 'slack')])
예제 #13
0
def test_store_project(ddb):
    """Test storing project calls correct functions."""
    dbf = DBFacade(ddb)
    test_project = create_test_project('1', ['a'])
    dbf.store(test_project)
    ddb.store.assert_called_with(test_project)
예제 #14
0
def test_bulk_retrieve_team(ddb):
    """Test bulk retrieving teams."""
    dbf = DBFacade(ddb)
    team_ids = list(map(str, range(10)))
    dbf.bulk_retrieve(Team, team_ids)
    ddb.bulk_retrieve.assert_called_with(Team, team_ids)
예제 #15
0
def test_store_team(ddb):
    """Test storing team calls correct functions."""
    dbf = DBFacade(ddb)
    test_team = create_test_team('1', 'brussel-sprouts', 'Brussel Sprouts')
    dbf.store(test_team)
    ddb.store.assert_called_with(test_team)
예제 #16
0
def test_query_user(ddb):
    """Test querying user calls correct functions."""
    dbf = DBFacade(ddb)
    dbf.query(User, ['permission_level', 'admin'])
    ddb.query.assert_called_with(User, ['permission_level', 'admin'])
예제 #17
0
def test_retrieve_user(ddb):
    """Test retrieving user calls correct functions."""
    dbf = DBFacade(ddb)
    slack_id = 'abc_123'
    dbf.retrieve(User, slack_id)
    ddb.retrieve.assert_called_with(User, slack_id)
예제 #18
0
def test_store_user(ddb):
    """Test storing user calls correct functions."""
    dbf = DBFacade(ddb)
    test_user = create_test_admin('abc_123')
    dbf.store(test_user)
    ddb.store.assert_called_with(test_user)
예제 #19
0
def test_delete_project(ddb):
    """Test deleting project calls correct functions."""
    dbf = DBFacade(ddb)
    project_id = 'brussel-sprouts'
    dbf.delete(Project, project_id)
    ddb.delete.assert_called_with(Project, project_id)