Пример #1
0
    def test_publish_message(self):
        self.populate_file('main.yaml', '''---
            variables:
                rabbit_config:
                    server: 127.0.0.1:5671
                    virtualhost: catcher.virtual.host
                    sslOptions: {'ssl_version': 'PROTOCOL_TLSv1_2', 'cert_reqs': 'CERT_NONE'}
                    username: catcher
                    password: catcher
            steps:
                - rabbit:
                    publish:
                        config: '{{ rabbit_config }}'
                        exchange: 'catcher.test.exchange'
                        routing_key: 'test'
                        data: 'Catcher test message'
                        headers: {'test.header.1': 'header1', 'test.header.2': 'header1'}
                    name: 'publish message'
            ''')
        runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
        self.assertTrue(runner.run_tests())

        import pika
        with pika.BlockingConnection(self.connectionParameters) as connection:
            channel = connection.channel()
            method_frame, header_frame, body = channel.basic_get(self.config['queue'])
            if method_frame:
                self.assertEqual(b'Catcher test message', body)
                self.assertEqual({'test.header.1': 'header1', 'test.header.2': 'header1'}, header_frame.headers)
                channel.basic_ack(method_frame.delivery_tag)
Пример #2
0
 def test_populate_generate(self):
     self.populate_file('resources/pg_schema.sql', '''
             CREATE TABLE foo(
                 user_id      integer    primary key,
                 email        varchar(36)    NOT NULL
             );
             ''')
     self.populate_file('resources/foo.csv', "user_id,email\n"
                                             "{% for user in users %}"
                                             "{{ loop.index }},{{ user }}\n"
                                             "{% endfor %}"
                                             "4,other_email\n"
                        )
     self.populate_file('main.yaml', '''---
                 variables:
                     postgres: 'test:test@localhost:5433/test'
                     users: ['test_1', 'test_2', 'test_3']
                 steps:
                     - prepare:
                         populate:
                             postgres:
                                 conf: '{{ postgres }}'
                                 schema: pg_schema.sql
                                 data:
                                     foo: foo.csv
                 ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     self.assertTrue(runner.run_tests())
     response = self.get_values('foo')
     self.assertEqual(4, len(response))
     self.assertEqual(1, response[0][0])
     self.assertEqual('test_1', response[0][1])
     self.assertEqual('test_2', response[1][1])
     self.assertEqual('test_3', response[2][1])
     self.assertEqual('other_email', response[3][1])
Пример #3
0
    def test_publish_json(self):
        self.populate_file('main.yaml', '''---
            variables:
                rabbit_config:
                    server: 127.0.0.1:5671
                    virtualhost: catcher.virtual.host
                    sslOptions: {'ssl_version': 'PROTOCOL_TLSv1_2', 'cert_reqs': 'CERT_NONE'}
                    username: catcher
                    password: catcher
            steps:
                - rabbit:
                    publish:
                        config: '{{ rabbit_config }}'
                        exchange: 'catcher.test.exchange'
                        routing_key: 'test'
                        data: "{{ {'key': RANDOM_INT}|tojson }}"
                        headers: {'test.header.1': 'header1', 'test.header.2': 'header1'}
                    name: 'publish message'
            ''')
        runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
        self.assertTrue(runner.run_tests())

        import pika
        with pika.BlockingConnection(self.connectionParameters) as connection:
            channel = connection.channel()
            method_frame, header_frame, body = channel.basic_get(self.config['queue'])
            if method_frame:
                actual_test_data = json.loads(body.decode('UTF-8'))
                if not isinstance(actual_test_data["key"], numbers.Number):
                    raise Exception('incorrect message format ' + str(actual_test_data))
                channel.basic_ack(method_frame.delivery_tag)
Пример #4
0
    def test_consume_message(self):
        # publish a message to the exchange so that it can be read by the queue
        import pika
        with pika.BlockingConnection(self.connectionParameters) as connection:
            channel = connection.channel()
            channel.basic_publish(exchange=self.config['exchange'],
                                  routing_key=self.config['routingKey'],
                                  body=b'Test queue message')

        self.populate_file('main.yaml', '''---
            variables:
                rabbit_config:
                    server: 127.0.0.1:5672
                    virtualhost: catcher.virtual.host
                    username: catcher
                    password: catcher
            steps:
                - rabbit:
                    consume:
                        config: '{{ rabbit_config }}'
                        queue: 'catcher.test'
                    register: {qMessage: '{{ OUTPUT }}'}
                    name: 'consume message'
                - check:
                    equals: {the: '{{ qMessage }}', is: 'Test queue message'}
                    name: 'Check: consume message'
            ''')
        runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
        self.assertTrue(runner.run_tests())
Пример #5
0
 def test_stop_from_include(self):
     self.populate_file('main.yaml', '''---
     include: 
         file: migration.yaml
         as: migrate
     variables:
         counter: 0
     steps:
         - run: migrate
         - check: {equals: {the: '{{ counter }}', is: 2}}
         - run: migrate
         - check: {equals: {the: '{{ counter }}', is: 2}}
     ''')
     self.populate_file('migration.yaml', '''---
     steps:
         - echo: {from: '{{ counter + 1 }}', register: {counter: '{{ OUTPUT }}'}}
         - stop: 
             if: 
                 equals: '{{ counter > 1 }}'
         - echo: {from: '{{ counter + 1 }}', register: {counter: '{{ OUTPUT }}'}}
         - stop: 
             if: 
                 equals: '{{ counter > 1 }}'
         - echo: {from: '{{ counter + 1 }}', register: {counter: '{{ OUTPUT }}'}}
         - check: {equals: {the: '{{ counter }}', is: 2}}
     ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     self.assertTrue(runner.run_tests())
Пример #6
0
 def test_write_lead(self, marketo_mock):
     instance = marketo_mock.return_value
     instance.execute.return_value = [{
         'status': 'updated'
     }, {
         'status': 'updated'
     }]
     self.populate_file(
         'main.yaml', '''---
         variables:
             marketo_config:
                 munchkin_id: test
                 client_id: test
                 client_secret: test
             email_1: '*****@*****.**'
             email_2: '*****@*****.**'
         steps:
             - marketo:
                 write:
                     conf:
                         munchkin_id: '{{ marketo_munchkin_id }}'
                         client_id: '{{ marketo_client_id }}'
                         client_secret: '{{ marketo_client_secret }}'
                     action: 'updateOnly'
                     lookupField: 'custom_id'
                     leads:
                         - custom_id: 14
                           email: '{{ email_1 }}'
                           custom_field_1: 'some value'
                         - custom_id: 15
                           email: '{{ email_2 }}'
                           custom_field_1: 'some other value'
                 register: {response: '{{ OUTPUT }}'}
             - check: 
                 all:
                     of: '{{ response }}'
                     equals: {the: '{{ ITEM.status }}', is: 'updated'}
         ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     self.assertTrue(runner.run_tests())
     instance.execute.assert_called_with(method='create_update_leads',
                                         leads=[{
                                             'custom_id':
                                             14,
                                             'email':
                                             '*****@*****.**',
                                             'custom_field_1':
                                             'some value'
                                         }, {
                                             'custom_id':
                                             15,
                                             'email':
                                             '*****@*****.**',
                                             'custom_field_1':
                                             'some other value'
                                         }],
                                         action='updateOnly',
                                         lookupField='custom_id',
                                         asyncProcessing='false',
                                         partitionName='Default')
Пример #7
0
 def test_call_variables(self):
     TestClass.copy_resource(self, 'greeter.proto')
     self.populate_file(
         'main.yaml', '''---
                         variables:
                             data:
                                 result: 
                                     url: 'my'
                                     title: 'test'
                                     snippets: 'test2'
                         steps:
                             - wait:
                                 seconds: 5
                                 for:
                                     - grpc:
                                         call:
                                             url: 'localhost:50051'
                                             function: greeter.greet
                                             schema: 'greeter.proto'
                                             data: '{{ data }}'
                                         register: {value: '{{ OUTPUT.name }}'}
                             - check: 
                                 equals: {'the': '{{ value }}', 'is': 'Result for test contains test2'}
                         ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     self.assertTrue(runner.run_tests())
Пример #8
0
    def test_different_conf(self):
        self.populate_file(
            'test_inventory.yml', '''
        postgres_str: 'test:test@localhost:5433/test'
        postgres_str_obj:
            url: 'test:test@localhost:5433/test'
            type: postgres
        postgres_obj:
            dbname: 'test'
            user: '******'
            password: '******'
            host: 'localhost'
            port: 5433
            type: 'postgres'
        ''')

        self.populate_file(
            'main.yaml', '''---
                steps:
                    - loop:
                        foreach:
                            in: '[{{ postgres_str_obj }}, "{{ postgres_str }}", {{ postgres_obj }}]'
                            do:   
                                - postgres:
                                    request:
                                        conf: '{{ ITEM }}'
                                        query: 'select count(*) from test'
                                    register: {documents: '{{ OUTPUT }}'}
                                - check:
                                    equals: {the: '{{ documents.count }}', is: 2}
                ''')
        runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'),
                        join(self.test_dir, 'test_inventory.yml'))
        self.assertTrue(runner.run_tests())
Пример #9
0
    def test_read_simple_query(self):
        self.populate_file(
            'test_inventory.yml', '''
        postgres:
            dbname: test
            user: test
            password: test
            host: localhost
            port: 5433
        ''')

        self.populate_file(
            'main.yaml', '''---
            steps:
                - postgres:
                    request:
                        conf: '{{ postgres }}'
                        query: 'select count(*) from test'
                    register: {documents: '{{ OUTPUT }}'}
                - check:
                    equals: {the: '{{ documents.count }}', is: 2}
            ''')
        runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'),
                        join(self.test_dir, 'test_inventory.yml'))
        self.assertTrue(runner.run_tests())
Пример #10
0
 def test_prepare_json(self):
     self.populate_file('resources/pg_schema.sql', '''
             CREATE TABLE foo(
                 user_id      integer    primary key,
                 payload      json       NOT NULL
             );
             ''')
     self.populate_file('resources/foo.csv', "user_id,payload\n"
                                             "1,{\"date\": \"1990-07-20\"}"
                        )
     self.populate_file('main.yaml', '''---
                 variables:
                     postgres: 'test:test@localhost:5433/test'
                     users: ['test_1', 'test_2', 'test_3']
                 steps:
                     - prepare:
                         populate:
                             postgres:
                                 conf: '{{ postgres }}'
                                 schema: pg_schema.sql
                                 data:
                                     foo: foo.csv
                                 use_json: true
                     - postgres:
                         request:
                             conf: '{{ postgres }}'
                             query: "select payload ->> 'date' AS date from foo where user_id = 1"
                         register: {date: '{{ OUTPUT.date }}' }
                     - check: {equals: {the: '1990-07-20', is: '{{ date }}'}}
                 ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     self.assertTrue(runner.run_tests())
Пример #11
0
 def test_loop_with_include(self):
     self.populate_file('main.yaml', '''---
     include: 
         file: print_file.yaml
         as: print
     variables:
         list: [{'file': 'a', 'value': 1}, {'file': 'b', 'value': 2}, {'file': 'c', 'value': 3}]
     steps:
         - loop: 
             foreach:
                 in: '{{ list }}'
                 do:
                     run: 
                         include: 'print'
                         variables: 
                             data: '{{ ITEM["value"] }}'
                             filename: '{{ ITEM["file"] }}'
     ''')
     self.populate_file('print_file.yaml', '''---
      steps:
         - echo: {from: '{{ data }}', to: '{{ filename }}'}
     ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     runner.run_tests()
     self.assertTrue(check_file(join(self.test_dir, 'a'), '1'))
     self.assertTrue(check_file(join(self.test_dir, 'b'), '2'))
     self.assertTrue(check_file(join(self.test_dir, 'c'), '3'))
Пример #12
0
 def test_include_multiple_places(self):
     """
     main |--> include1 --> include2
          |--> include2
     """
     self.populate_file('main.yaml', '''---
             include: 
                     - file: include1.yml
                       as: inc1
                     - file: include2.yml
                       as: inc2
             ''')
     self.populate_file('include1.yml', '''---
             include:
                 - file: include2.yml
                   as: inc2
     ''')
     self.populate_file('include2.yml', '''---
     variables:
         foo: 123
     steps:
         - echo: {from: '{{ foo }}', to: other.output}
     ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     self.assertTrue(runner.run_tests())
Пример #13
0
 def test_run_from_template(self):
     self.populate_file(
         'main.yaml', '''---
     include: 
         - file: one.yaml
           as: one
         - file: two.yaml
           as: two
         - file: determine_include.yaml
           as: determine_include
     steps:
         - run: 'determine_include'
         - run: '{{ include }}'
     ''')
     self.populate_file(
         'one.yaml', '''---
     steps:
         - echo: {from: 'bar', to: foo.output}
     ''')
     self.populate_file(
         'two.yaml', '''---
     steps:
         - echo: {from: 'baz', to: foo.output}
     ''')
     self.populate_file(
         'determine_include.yaml', '''---
     steps:
         - echo: {from: 'hello', register: {include: one}}
     ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     runner.run_tests()
     self.assertTrue(check_file(join(self.test_dir, 'foo.output'), 'bar'))
     self.assertTrue(not os.path.exists(join(self.test_dir, 'baz.output')))
Пример #14
0
    def test_populate_int(self):
        self.populate_file('resources/pg_schema.sql', '''
                CREATE TABLE foo(
                    user_id      integer    primary key,
                    email        varchar(36)    NOT NULL
                );
                ''')

        self.populate_file('resources/foo.csv', "user_id,email\n"
                                                "1,[email protected]\n"
                                                "2,[email protected]\n"
                           )

        self.populate_file('test_inventory.yml', '''
                        postgres: 'test:test@localhost:5433/test'
                ''')

        self.populate_file('main.yaml', '''---
                    steps:
                        - prepare:
                            populate:
                                postgres:
                                    conf: '{{ postgres }}'
                                    schema: pg_schema.sql
                                    data:
                                        foo: foo.csv
                    ''')
        runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), join(self.test_dir, 'test_inventory.yml'))
        self.assertTrue(runner.run_tests())
        response = self.get_values('foo')
        self.assertEqual(2, len(response))
        self.assertEqual(1, response[0][0])
        self.assertEqual('*****@*****.**', response[0][1])
        self.assertEqual(2, response[1][0])
        self.assertEqual('*****@*****.**', response[1][1])
Пример #15
0
 def test_register_run_tags_with_dot(self):
     self.populate_file(
         'main.yaml', '''---
     include: 
         file: simple_file.yaml
         as: simple.with_dot
     steps:
         - run: 
             include: 'simple.with_dot.one'
     ''')
     self.populate_file(
         'simple_file.yaml', '''---
     variables:
         foo: 1
         baz: 2
         bar: 3
     steps:
         - echo: {from: '{{ foo }}', to: foo.output, tag: one}
         - echo: {from: '{{ baz }}', to: baz.output}
         - echo: {from: '{{ bar }}', to: bar.output, tag: one}
     ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     runner.run_tests()
     self.assertTrue(check_file(join(self.test_dir, 'foo.output'), '1'))
     self.assertTrue(not os.path.exists(join(self.test_dir, 'baz.output')))
     self.assertTrue(check_file(join(self.test_dir, 'bar.output'), '3'))
Пример #16
0
 def test_compose(self):
     self.populate_resource('docker-compose.yml', '''
     version: '3.1'
     services:
         mockserver:
             image: jamesdbloom/mockserver
             ports:
             - "8000:1080"
     ''')
     self.populate_file('main.yaml', '''---
                         steps:
                              - wait:
                                 seconds: 5
                                 for:
                                     http:
                                         put:
                                             url: 'http://localhost:8000/mockserver/expectation'
                                             body:
                                                 httpRequest: {'path': '/some/path'}
                                                 httpResponse: {'body': 'hello world'}
                                             response_code: 201
                             - http: 
                                 get: 
                                     url: 'http://localhost:8000/mockserver/expectation',
                                     response_code: 200
                         ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None,
                     resources=join(test.get_test_dir(self.test_name), 'resources'))
     self.assertFalse(runner.run_tests())
Пример #17
0
    def test_cmd_override_all(self):
        self.populate_file(
            'inventory.yml', '''---
                foo2: baz
                ''')
        self.populate_file(
            'main.yaml', '''---
        variables:
            foo: baz
        steps:
            - echo: 
                actions: 
                    - {from: '{{ foo }}', to: one.output}
                    - {from: '{{ foo2 }}', to: two.output}

        ''')
        runner = Runner(self.test_dir,
                        join(self.test_dir, 'main.yaml'),
                        join(self.test_dir, 'inventory.yml'),
                        cmd_env={
                            'foo': 'bad',
                            'foo2': 'bad'
                        })
        runner.run_tests()
        self.assertTrue(check_file(join(self.test_dir, 'one.output'), 'bad'))
        self.assertTrue(check_file(join(self.test_dir, 'two.output'), 'bad'))
Пример #18
0
 def test_var_in_run_as_obj(self):
     self.populate_resource(
         'test.csv', "email,id\n"
         "{%- for user in users %}\n"
         "{{ user.email }},{{ user.id }}\n"
         "{%- endfor -%}")
     self.populate_file(
         'main.yaml', '''---
                             variables:
                                 users:
                                     - email: '*****@*****.**'
                                       id: 1
                                     - email: '*****@*****.**'
                                       id: 2
                             include: 
                                 file: one.yaml
                                 as: one
                             steps:
                                 - run: 
                                     include: 'one'
                                     variables:
                                         users: '{{ users[:1] }}'
                             ''')
     self.populate_file(
         'one.yaml', '''---
                             steps:
                                 - echo: {from_file: 'test.csv', to: res.output}
                             ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     runner.run_tests()
     self.assertTrue(
         check_file(join(self.test_dir, 'res.output'),
                    'email,id\[email protected],1'))
Пример #19
0
 def test_populate_sql(self):
     self.populate_file(
         'resources/schema.sql', '''
                                     CREATE TABLE if not exists foo(
                                         user_id      integer    primary key,
                                         email        varchar(36)    NOT NULL
                                     );
                                     {%- for user in users %}
                                     insert into foo values ({{user.num}}, '{{user.email}}');
                                     {%- endfor -%}
                                     ''')
     self.populate_file(
         'main.yaml', '''---
                                         variables:
                                             users:
                                                 - num: 1
                                                   email: [email protected]
                                                 - num: 2
                                                   email: [email protected]
                                         steps:
                                             - postgres:
                                                 request:
                                                     conf: 'test:test@localhost:5433/test'
                                                     sql: schema.sql
                                         ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     self.assertTrue(runner.run_tests())
     response = self.get_values('foo')
     self.assertEqual([(1, '*****@*****.**'), (2, '*****@*****.**')],
                      response)
Пример #20
0
def run_tests(path: str, arguments: dict):
    file_or_dir = arguments['<tests>']
    inventory = arguments['--inventory']
    environment = arguments['--environment']
    modules = arguments['--modules']
    resources = arguments['--resources']
    output_format = arguments['--format']
    filters = arguments['--filter']
    use_sys_vars = arguments['--system_env']
    output = 'full' if not arguments['--q'] else 'limited'
    if arguments['--qq']:
        output = 'final'
    if strtobool(use_sys_vars):
        sys_vars = dict(os.environ)
    else:
        sys_vars = None
    __load_modules(modules)
    runner = Runner(path, file_or_dir, inventory,
                    modules=modules,
                    cmd_env=__env_to_variables(environment),
                    resources=resources,
                    system_environment=sys_vars,
                    output_format=output_format,
                    filter_list=filters)
    return runner.run_tests(output=output)
Пример #21
0
 def test_run_tagged_tagged(self):
     self.populate_file(
         'main.yaml', '''---
                     include: 
                         file: one.yaml
                         as: one
                     steps:
                         - run: 'one.before'
                     ''')
     self.populate_file(
         'one.yaml', '''---
                     include: 
                         file: two.yaml
                         as: two
                     steps:
                         - run:
                             include: two.one
                             tag: before
                         - echo: {from: '{{ bar }}', to: after.output, tag: after}
                     ''')
     self.populate_file(
         'two.yaml', '''---
                     steps:
                         - echo: {from: '1', to: foo.output, tag: one}
                         - echo: {from: '2', to: baz.output, tag: two}
                         - echo: {from: '3', to: bar.output, tag: three}
                             ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     runner.run_tests()
     self.assertTrue(check_file(join(self.test_dir, 'foo.output'), '1'))
     self.assertTrue(not os.path.exists(join(self.test_dir, 'baz.output')))
     self.assertTrue(not os.path.exists(join(self.test_dir, 'bar.output')))
Пример #22
0
 def test_computed_equals_constant(self):
     self.populate_file('main.yaml', '''---
     steps:
         - echo: {from: 'hello', register: {'foo': 'value'}}
         - check: {equals: {the: '{{ foo }}', is: 'value'}}
     ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     self.assertTrue(runner.run_tests())
Пример #23
0
 def test_compate_dates(self):
     self.populate_file('main.yaml', '''---
     steps:
         - check:
             equals: {the: '2020-03-11', is_not: '2020-11-03' }
     ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     self.assertTrue(runner.run_tests())
Пример #24
0
 def test_no_compose(self, m):
     m.get('http://test.com', status_code=500)
     self.populate_file('main.yaml', '''---
                 steps:
                     - http: {get: {url: 'http://test.com', response_code: 200}}
                 ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     self.assertFalse(runner.run_tests())
Пример #25
0
 def test_check_short_form(self):
     self.populate_file('main.yaml', '''---
     variables:
         foo: true
     steps:
         - check: '{{ foo }}'
     ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     self.assertTrue(runner.run_tests())
Пример #26
0
 def test_random_functions(self):
     Faker.seed(4321)
     self.populate_file('main.yaml', '''---
     steps:
         - echo: {from: '{{ random("ipv4_private") }}', to: one.output}
     ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     self.assertTrue(runner.run_tests())
     self.assertTrue(check_file(join(self.test_dir, 'one.output'), '10.32.135.245'))
Пример #27
0
 def test_run_ignore_test(self):
     self.populate_file(
         'main.yaml', '''---
             ignore: true # for some reason this test is not working
             steps:
                 - check: {equals: {the: true, is: false}}
             ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     self.assertTrue(runner.run_tests())
Пример #28
0
 def test_run_one_action(self):
     self.populate_file(
         'main.yaml', '''---
     steps:
         - echo: {from: 'test', to: main.output}
     ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     runner.run_tests()
     self.assertTrue(check_file(join(self.test_dir, 'main.output'), 'test'))
Пример #29
0
 def test_await_range_xx(self, m):
     m.get('http://test.com', status_code=201)
     self.populate_file(
         'main.yaml', '''---
                                 steps:
                                     - http: {get: {url: 'http://test.com', response_code: 2xx-3xx}}
                                 ''')
     runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), None)
     self.assertTrue(runner.run_tests())
Пример #30
0
    def test_populate_from_scratch(self):
        self.populate_file('resources/pg_schema.sql', '''
       
        CREATE TABLE foo(
            user_id      varchar(36)    primary key,
            email        varchar(36)    NOT NULL
        );
        
        CREATE TABLE bar(
            key           varchar(36)    primary key,
            value         varchar(36)    NOT NULL
        );
        ''')

        self.populate_file('resources/foo.csv', "user_id,email\n"
                                                "1,[email protected]\n"
                                                "2,[email protected]\n"
                           )
        self.populate_file('resources/bar.csv', "key,value\n"
                                                "k1,v1\n"
                                                "k2,v2\n"
                           )

        self.populate_file('test_inventory.yml', '''
        postgres:
            dbname: test
            user: test
            password: test
            host: localhost
            port: 5433
        ''')

        self.populate_file('main.yaml', '''---
            steps:
                - prepare:
                    populate:
                        postgres:
                            conf: '{{ postgres }}'
                            schema: pg_schema.sql
                            data:
                                foo: foo.csv
                                bar: bar.csv
            ''')
        runner = Runner(self.test_dir, join(self.test_dir, 'main.yaml'), join(self.test_dir, 'test_inventory.yml'))
        self.assertTrue(runner.run_tests())
        response = self.get_values('foo')
        self.assertEqual(2, len(response))
        self.assertEqual('1', response[0][0])
        self.assertEqual('*****@*****.**', response[0][1])
        self.assertEqual('2', response[1][0])
        self.assertEqual('*****@*****.**', response[1][1])
        response = self.get_values('bar')
        self.assertEqual(2, len(response))
        self.assertEqual('k1', response[0][0])
        self.assertEqual('v1', response[0][1])
        self.assertEqual('k2', response[1][0])
        self.assertEqual('v2', response[1][1])