Beispiel #1
0
def test_build_new_project(cb, topic):
    """
    Tests that:
    - CB project created
    - CB build started
    - notification published
    """

    main.account = "123"

    resource_not_found_error = ClientError({"Error": {"Code": "ResourceNotFoundException", "Message": "test"}}, "test")
    cb.update_project.side_effect = resource_not_found_error

    main.handle(event)

    cb.update_project.assert_called_once_with(name=url_hash,
                                              description=url,
                                              source=ANY,
                                              artifacts=ANY,
                                              environment=ANY,
                                              serviceRole=ANY)

    cb.create_project.assert_called_once_with(name=url_hash,
                                              description=url,
                                              source=ANY,
                                              artifacts=ANY,
                                              environment=ANY,
                                              serviceRole=ANY)

    cb.start_build.assert_called_once_with(projectName=url_hash)

    topic.publish.assert_called_once_with({"interaction_id": "123", "url": url, "status": "started"})
def test_handle_with_chefservernotfounderror_on_search(mock_chefapi,
                                                       mock_search):
    """
    Tests the handle function with ChefServerNotFoundError on search
    """
    cloudwatch = SampleEvent('cloudwatch_events')
    mock_search.side_effect = ChefServerNotFoundError('boom')
    assert handle(cloudwatch.event, 'blah') is False
def test_handle(mock_chefapi, mock_search, mock_node, mock_client):
    """
    Tests the handle function with no errors and valid input
    """
    cloudwatch = SampleEvent('cloudwatch_events')
    node = MagicMock()
    mock_search.return_value = node
    mock_node.delete.return_value = True
    mock_client.delete.return_value = True
    assert handle(cloudwatch.event, 'blah') is True
Beispiel #4
0
def test_handle_no_instances(mock_instances, mock_commands, mock_artifact,
                             mock_failure):
    """
    Test the handle function with valid input and no instances
    """
    mock_instances.return_value = []
    mock_commands.return_value = True
    mock_artifact.return_value = True
    mock_failure.return_value = True
    codepipeline = SampleEvent('codepipeline')
    assert handle(codepipeline.event, 'Test') is False
def test_handle_no_instances(mock_instances, mock_commands, mock_artifact,
                             mock_failure):
    """
    Test the handle function with valid input and no instances
    """
    mock_instances.return_value = []
    mock_commands.return_value = True
    mock_artifact.return_value = True
    mock_failure.return_value = True
    codepipeline = SampleEvent('codepipeline')
    assert handle(codepipeline.event, 'Test') is False
Beispiel #6
0
def test_handle(mock_instances, mock_commands, mock_artifact, mock_run_command,
                mock_success):
    """
    Test the handle function with valid input and instances
    """
    mock_instances.return_value = ['abcdef-12345']
    mock_commands.return_value = True
    mock_artifact.return_value = True
    mock_run_command.return_value = True
    mock_success.return_value = True
    codepipeline = SampleEvent('codepipeline')
    assert handle(codepipeline.event, 'Test')
def test_handle(mock_instances, mock_commands, mock_artifact, mock_run_command,
                mock_success):
    """
    Test the handle function with valid input and instances
    """
    mock_instances.return_value = ['abcdef-12345']
    mock_commands.return_value = True
    mock_artifact.return_value = True
    mock_run_command.return_value = True
    mock_success.return_value = True
    codepipeline = SampleEvent('codepipeline')
    assert handle(codepipeline.event, 'Test')
Beispiel #8
0
def main_test():
    data = {
        'method': 'GET',
        'headers': {
            'content-type': 'application/json',
        },
        'path': '/price',
        'queryParams': {
            "word": "PowerShot G7",
            "platform": 'shopee'
        },
        'body': {}
    }
    return handle(data, None)
Beispiel #9
0
def test_project_update_error(cb, topic):
    """
    Tests that:
    - notification published on CB project update error
    """

    main.account = "123"

    cb.update_project.side_effect = ValueError("test")

    main.handle(event)

    cb.update_project.assert_called_once_with(name=url_hash,
                                              description=url,
                                              source=ANY,
                                              artifacts=ANY,
                                              environment=ANY,
                                              serviceRole=ANY)

    cb.create_project.assert_not_called()
    cb.start_build.assert_not_called()

    topic.publish.assert_called_once_with({"interaction_id": "123", "url": url, "status": "failed"})
Beispiel #10
0
def test_existing_project(cb, topic):
    """
    Tests that:
    - CB project updated
    - CB build started
    - notification published
    """
    main.account = "abc"

    main.handle(event)

    cb.update_project.assert_called_once_with(name=url_hash,
                                              description=url,
                                              source=ANY,
                                              artifacts=ANY,
                                              environment=ANY,
                                              serviceRole=ANY)

    cb.start_build.assert_called_once_with(projectName=url_hash)

    topic.publish.assert_called_once_with({"interaction_id": "123", "url": url, "status": "started"})

    cb.create_project.assert_not_called()
 def test_handle(self):
     verification_token = os.environ.get('SLACK_APP_VERIFICATION_TOKEN')
     challenge = secrets.token_urlsafe(32)
     event = {
         "httpMethod":
         "POST",
         "resource":
         "/exp",
         "headers": {},
         "body":
         "{ \"token\": \"" + verification_token + "\", \"challenge\": \"" +
         challenge + "\", \"type\": \"url_verification\" }"
     }
     context = None
     response = main.handle(event, context)
     self.assertEqual(response["body"], challenge)
Beispiel #12
0
# encoding: utf-8
from __future__ import print_function, unicode_literals
import json

from main import handle

if __name__ == '__main__':

    handle(None, None)
Beispiel #13
0
def test_handle_invalid_event():
    """
    Test the handle function with an invalid event
    """
    event = {}
    assert handle(event, 'Test') is False
def test_handle_invalid_event():
    """
    Test the handle function with an invalid event
    """
    event = {}
    assert handle(event, 'Test') is False
Beispiel #15
0
 def testHelp(self):
     asd = handle(msg1)
     self.assertEqual(asd, getHelp(bot, msg1))
Beispiel #16
0
def index():
    return handle(flask.request)