Пример #1
0
    def generate(self):
        """
        return None if records data not found
        :return:
        """

        import codecs

        records = []
        with codecs.open(self._filepath, 'r', 'utf-8') as record_file:
            while True:
                result = self._formatter.read_record(record_file)
                if not result:
                    break
                records.append(result)

        from zerotest.generator.python.render import Renderer

        if len(records) == 0:
            return None

        renderer = Renderer(options=self._options,
                            match_options=self._match_options)

        return renderer.render(records)
Пример #2
0
def test_renderer_with_ignore_headers():
    options = dict()
    match_options = dict(ignore_headers=('date', 'auth'))
    records = list()
    records.append((Request(scheme='http',
                            method='GET',
                            host='for_test.org',
                            path='/',
                            headers=dict(header_1='1'),
                            data='just_for_test'),
                    Response(status=200,
                             headers=dict(content_type="text",
                                          date='yesterday',
                                          auth='secret'),
                             body='ok')))
    records.append((Request(scheme='https',
                            method='POST',
                            host='for_test.org',
                            path='/second_request',
                            headers=dict(header_a='a'),
                            data='second_request'),
                    Response(status=200,
                             headers=dict(content_type="text", date='today'),
                             body='ok')))
    renderer = Renderer(options=options, match_options=match_options)

    cases = [
        dict(request=Request(scheme='http',
                             method='GET',
                             host='for_test.org',
                             path='/',
                             headers=dict(header_1='1'),
                             data='just_for_test'),
             response=Response(status=200,
                               headers=dict(content_type="text"),
                               body='ok'),
             func_name='get_root'),
        dict(request=Request(scheme='https',
                             method='POST',
                             host='for_test.org',
                             path='/second_request',
                             headers=dict(header_a='a'),
                             data='second_request'),
             response=Response(status=200,
                               headers=dict(content_type="text"),
                               body='ok'),
             func_name='post_second_request'),
    ]

    assert renderer.prepare(records) == cases