예제 #1
0
def test_perform_http_call(method, method_config, netloc, initialized_db):
    repository = Repository("buynlarge", "orgrepo")
    notification = Notification(
        uuid="fake",
        event_name="repo_push",
        method_name=method.method_name(),
        event_config_dict={},
        method_config_dict=method_config,
        repository=repository,
    )

    event_handler = NotificationEvent.get_event("repo_push")
    sample_data = event_handler.get_sample_data(repository.namespace_name,
                                                repository.name, {})

    url_hit = [False]

    @urlmatch(netloc=netloc)
    def url_handler(_, __):
        url_hit[0] = True
        return ""

    with HTTMock(url_handler):
        method().perform(notification, event_handler, {
            "event_data": sample_data,
            "performer_data": {}
        })

    assert url_hit[0]
예제 #2
0
def test_perform_email(initialized_db):
    repository = Repository("buynlarge", "orgrepo")
    notification = Notification(
        uuid="fake",
        event_name="repo_push",
        method_name="email",
        event_config_dict={},
        method_config_dict={"email": "*****@*****.**"},
        repository=repository,
    )

    event_handler = NotificationEvent.get_event("repo_push")
    sample_data = event_handler.get_sample_data(repository.namespace_name,
                                                repository.name, {})

    mock = Mock()

    def get_mock(*args, **kwargs):
        return mock

    with patch("notifications.notificationmethod.Message", get_mock):
        method = EmailMethod()
        method.perform(notification, event_handler, {
            "event_data": sample_data,
            "performer_data": {}
        })

    mock.send.assert_called_once()
예제 #3
0
def test_perform_quay_notification(target, expected_users, initialized_db):
    repository = Repository("buynlarge", "orgrepo")
    notification = Notification(
        uuid="fake",
        event_name="repo_push",
        method_name="quay",
        event_config_dict={},
        method_config_dict={"target": target},
        repository=repository,
    )

    event_handler = NotificationEvent.get_event("repo_push")

    sample_data = event_handler.get_sample_data(repository.namespace_name,
                                                repository.name, {})

    method = QuayNotificationMethod()
    method.perform(notification, event_handler, {"event_data": sample_data})

    # Ensure that the notification was written for all the expected users.
    if target["kind"] != "team":
        user = model.user.get_namespace_user(target["name"])
        assert len(
            model.notification.list_notifications(user,
                                                  kind_name="repo_push")) > 0
예제 #4
0
def test_perform_quay_notification(target, expected_users, initialized_db):
  repository = Repository('buynlarge', 'orgrepo')
  notification = Notification(uuid='fake', event_name='repo_push', method_name='quay',
                              event_config_dict={}, method_config_dict={'target': target},
                              repository=repository)

  event_handler = NotificationEvent.get_event('repo_push')

  sample_data = event_handler.get_sample_data(repository.namespace_name, repository.name, {})

  method = QuayNotificationMethod()
  method.perform(notification, event_handler, {'event_data': sample_data})

  # Ensure that the notification was written for all the expected users.
  if target['kind'] != 'team':
    user = model.user.get_namespace_user(target['name'])
    assert len(model.notification.list_notifications(user, kind_name='repo_push')) > 0
예제 #5
0
def test_perform_email(initialized_db):
  repository = Repository('buynlarge', 'orgrepo')
  notification = Notification(uuid='fake', event_name='repo_push', method_name='email',
                              event_config_dict={}, method_config_dict={'email': '*****@*****.**'},
                              repository=repository)

  event_handler = NotificationEvent.get_event('repo_push')
  sample_data = event_handler.get_sample_data(repository.namespace_name, repository.name, {})

  mock = Mock()
  def get_mock(*args, **kwargs):
    return mock

  with patch('notifications.notificationmethod.Message', get_mock):
    method = EmailMethod()
    method.perform(notification, event_handler, {'event_data': sample_data, 'performer_data': {}})

  mock.send.assert_called_once()
예제 #6
0
def test_perform_http_call(method, method_config, netloc, initialized_db):
  repository = Repository('buynlarge', 'orgrepo')
  notification = Notification(uuid='fake', event_name='repo_push', method_name=method.method_name(),
                              event_config_dict={}, method_config_dict=method_config,
                              repository=repository)

  event_handler = NotificationEvent.get_event('repo_push')
  sample_data = event_handler.get_sample_data(repository.namespace_name, repository.name, {})

  url_hit = [False]
  @urlmatch(netloc=netloc)
  def url_handler(_, __):
    url_hit[0] = True
    return ''

  with HTTMock(url_handler):
    method().perform(notification, event_handler, {'event_data': sample_data, 'performer_data': {}})

  assert url_hit[0]