Ejemplo n.º 1
0
 def __init__(self, db_facade: DBFacade, gh_face: GithubInterface,
              config: Config):
     """Give handlers access to the database."""
     self.__secret = config.github_webhook_secret
     self.__event_handlers = [
         OrganizationEventHandler(db_facade, gh_face, config),
         TeamEventHandler(db_facade, gh_face, config),
         MembershipEventHandler(db_facade, gh_face, config)
     ]
Ejemplo n.º 2
0
def test_handle_team_event_create_update(mock_logging, team_created_payload):
    """Test that teams can be updated if they are in the db."""
    mock_facade = mock.MagicMock(DBFacade)
    webhook_handler = TeamEventHandler(mock_facade)
    rsp, code = webhook_handler.handle(team_created_payload)
    mock_logging.warning.assert_called_with(("team github with id 2723476 "
                                             "already exists."))
    mock_facade.store.assert_called_once()
    assert rsp == "created team with github id 2723476"
    assert code == 200
Ejemplo n.º 3
0
def test_handle_team_event_created_team(mock_logging, team_created_payload):
    """Test that teams can be created if they are not in the db."""
    mock_facade = mock.MagicMock(DBFacade)
    mock_facade.retrieve.side_effect = LookupError
    webhook_handler = TeamEventHandler(mock_facade)
    rsp, code = webhook_handler.handle(team_created_payload)
    mock_logging.debug.assert_called_with(("team github with id 2723476 "
                                           "added to organization."))
    mock_facade.store.assert_called_once()
    assert rsp == "created team with github id 2723476"
    assert code == 200
Ejemplo n.º 4
0
def test_handle_team_event_empty_payload(team_empty_payload):
    """Test that empty/invalid payloads can be handled."""
    mock_facade = mock.MagicMock(DBFacade)
    webhook_handler = TeamEventHandler(mock_facade)
    rsp, code = webhook_handler.handle(team_empty_payload)
    assert rsp == "invalid payload"
Ejemplo n.º 5
0
def test_handle_team_event_edit_miss(team_edited_payload):
    """Test that attempts to edit a missing team are handled."""
    mock_facade = mock.MagicMock(DBFacade)
    mock_facade.retrieve.side_effect = LookupError
    webhook_handler = TeamEventHandler(mock_facade)
    rsp, code = webhook_handler.handle(team_edited_payload)