Esempio n. 1
0
def test_create_tempfile():
    tf = create_tempfile('blah\nblub\n')
    with open(tf, 'r') as tfile:
        contents = tfile.read()
        assert_equal(contents, 'blah\nblub\n')
    # cleanup the tempfile
    os.unlink(tf)
Esempio n. 2
0
def test_compile_template(cleanup_tempfiles):
    swagger_template_file = create_tempfile(
        textwrap.dedent("""\
        ---
          swagger: "2.0"
          info:
            title: {{apiName}}
            description: {{apiDescription}}
            version: "0.0.1"
          basePath: "/{{apiBasePath}}"
          host: "{{apiHostname}}"
    """))
    cleanup_tempfiles.append(swagger_template_file)

    template_params = {
        'apiName': 'apiName',
        'apiDescription': 'apiDescription',
        'apiBasePath': 'apiBasePath',
        'apiHostname': 'apiHostname'
    }

    expected = textwrap.dedent("""\
        ---
          swagger: "2.0"
          info:
            title: apiName
            description: apiDescription
            version: "0.0.1"
          basePath: "/apiBasePath"
          host: "apiHostname"
    """)

    assert_equal(_compile_template(swagger_template_file, template_params),
                 expected)
Esempio n. 3
0
def test_invoke_payload_from_file(awsclient, vendored_folder, temp_lambda):
    log.info('running test_invoke')

    lambda_name = temp_lambda[0]
    role_arn = temp_lambda[2]
    payload_file = create_tempfile('{"ramuda_action": "ping"}')

    response = invoke(awsclient, lambda_name,
                      payload='file://%s' % payload_file)
    assert response == '"alive"'

    # cleanup
    os.unlink(payload_file)
Esempio n. 4
0
def test_invoke_outfile(awsclient, vendored_folder, temp_lambda):
    log.info('running test_invoke')

    lambda_name = temp_lambda[0]
    role_arn = temp_lambda[2]
    outfile = create_tempfile('')
    payload = '{"ramuda_action": "ping"}'  # default to ping event

    response = invoke(awsclient, lambda_name, payload=payload, outfile=outfile)

    with open(outfile, 'r') as ofile:
        assert ofile.read() == '"alive"'

    # cleanup
    os.unlink(outfile)
Esempio n. 5
0
def test_load_hooks():
    tfile = create_tempfile(
        textwrap.dedent("""
    COUNT = {'register': 0, 'deregister': 0}

    def register():
        COUNT['register'] += 1


    def deregister():
        COUNT['deregister'] += 1
    """))
    module = _load_hooks(tfile)

    assert module.COUNT['register'] == 1
    os.unlink(tfile)