mock.Response - python examples

Here are the examples of the python api mock.Response taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

33 Examples 7

3 View Complete Implementation : test_sap_adt_atc.py
Copyright Apache License 2.0
Author : jfilak
    def test_fetch_response_customizing(self):
        conn = Connection([Response(status_code=200,
                                    content_type=sap.adt.atc.CUSTOMIZING_MIME_TYPE_V1,
                                    text=ADT_XML_ATC_CUSTOMIZING_ATTRIBUTES)])

        customizing = sap.adt.atc.fetch_customizing(conn)
        self.astertEqual(customizing.system_check_variant, 'OPENABAPCHECKS')

        self.astertEqual(conn.execs, [ATC_CUSTOMIZIN_REQUEST])

3 View Complete Implementation : test_sap_adt_atc.py
Copyright Apache License 2.0
Author : jfilak
    def test_fetch_response_xml(self):
        conn = Connection([Response(status_code=200,
                                    content_type='application/xml',
                                    text=ADT_XML_ATC_CUSTOMIZING)])

        customizing = sap.adt.atc.fetch_customizing(conn)
        self.astertEqual(customizing.system_check_variant, 'STANDARD')

        self.astertEqual(conn.execs, [ATC_CUSTOMIZIN_REQUEST])

3 View Complete Implementation : test_sap_adt_checks.py
Copyright Apache License 2.0
Author : jfilak
    def test_fech_reporters_ok(self):
        connection = Connection([Response(status_code=200,
                                          headers={'Content-Type': 'application/vnd.sap.adt.reporters+xml'},
                                          text=ADT_XML_CHECK_REPORTERS)])

        result = sap.adt.checks.fetch_reporters(connection)

        self.astertIsInstance(result, list)
        self.astertEqual(3, len(result))

        self.astertEqual(result[0].name, 'abapCheckRun')
        self.astertEqual(result[1].name, 'abapPackageCheck')
        self.astertEqual(result[2].name, 'tableStatusCheck')

        self.astertEqual(result[0].supported_types, ['WDYN*', 'CLAS*', 'WGRP'])
        self.astertEqual(result[1].supported_types, ['PROG*', 'INTF*', 'HTTP'])
        self.astertEqual(result[2].supported_types, ['TABL/DT'])

3 View Complete Implementation : test_sap_adt_checks.py
Copyright Apache License 2.0
Author : jfilak
    def test_2_reportes_2_clastes(self):
        connection = Connection([Response(status_code=200,
                                          content_type='application/vnd.sap.adt.checkmessages+xml; charset=utf-8',
                                          text=ADT_XML_RUN_CHECK_2_REPORTERS)])

        reporter = sap.adt.checks.Reporter('abapCheckRun')
        reporter.supported_types = '*'

        reports = sap.adt.checks.run_for_supported_objects(connection, reporter,
                                                           [sap.adt.Clast(connection, 'CL_FIRST'),
                                                            sap.adt.Clast(connection, 'CL_SECOND')])

        self.astertEqual(connection.mock_methods(), [('POST', '/sap/bc/adt/checkruns')])
        self.astertEqual(connection.execs[0].body, FIXTURE_TWO_CLastES_REQUEST)

        self.astertEqual(['abapCheckRun', 'tableStatusCheck'], [report.reporter for report in reports])
        self.astertEqual(['First', 'Second'], [msg.short_text for msg in reports[0].messages])
        self.astertEqual(['Third', 'Fourth'], [msg.short_text for msg in reports[1].messages])

3 View Complete Implementation : test_sap_adt_cts.py
Copyright Apache License 2.0
Author : jfilak
    def do_check_release(self, factory):
        """Check it correctly builds the URL with parameters and returns
           the expected data.
        """

        connection = Connection([Response(TASK_RELEASE_OK_RESPONSE, 200, {})])

        wbr = factory(connection, TASK_NUMBER)
        resp = wbr.release()

        self.astertEqual(
            connection.execs,
            [Request('POST',
                     f'/sap/bc/adt/cts/transportrequests/{TASK_NUMBER}/newreleasejobs',
                     {'Accept': 'application/vnd.sap.adt.transportorganizer.v1+xml'},
                     None,
                     None)])

        self.astertEqual(resp, TASK_RELEASE_OK_RESPONSE)

3 View Complete Implementation : test_sap_adt_cts.py
Copyright Apache License 2.0
Author : jfilak
    def test_get_transport_requests(self):
        connection = Connection([Response(SHORTENED_WORKBENCH_XML, 200, {})])
        workbench = sap.adt.cts.Workbench(connection)

        transport = workbench.get_transport_requests(user='FILAK')

        self.astertEqual(
            connection.execs,
            [Request('GET',
                     f'/sap/bc/adt/cts/transportrequests',
                     {'Accept': 'application/vnd.sap.adt.transportorganizertree.v1+xml, application/vnd.sap.adt.transportorganizer.v1+xml'},
                     None,
                     sap.adt.cts.workbench_params('FILAK'))])

        self.astert_trasport_equal(transport[0], connection)
        self.astert_task_equal(transport[0].tasks[0], connection)

3 View Complete Implementation : test_sap_adt_datadefinition.py
Copyright Apache License 2.0
Author : jfilak
    def test_adt_ddl_read(self):
        conn = Connection([Response(text=FIXTURE_CDS_CODE,
                                 status_code=200,
                                 headers={'Content-Type': 'text/plain; charset=utf-8'})])

        ddl = sap.adt.DataDefinition(conn, name='MyUsers')
        code = ddl.text

        self.astertEqual(conn.mock_methods(), [('GET', '/sap/bc/adt/ddic/ddl/sources/myusers/source/main')])

        get_request = conn.execs[0]
        self.astertEqual(sorted(get_request.headers), ['Accept'])
        self.astertEqual(get_request.headers['Accept'], 'text/plain')

        self.astertIsNone(get_request.params)
        self.astertIsNone(get_request.body)

        self.maxDiff = None
        self.astertEqual(code, FIXTURE_CDS_CODE)

3 View Complete Implementation : test_sap_adt_function.py
Copyright Apache License 2.0
Author : jfilak
    def test_function_group_fetch(self):
        conn = Connection([Response(text=GET_FUNCTION_GROUP_ADT_XML, status_code=200, headers={})])
        fugr = sap.adt.FunctionGroup(conn, 'ZFG_HELLO_WORLD')
        fugr.fetch()

        self.astertEqual(fugr.name, 'ZFG_HELLO_WORLD')
        self.astertEqual(fugr.active, 'active')
        self.astertEqual(fugr.master_language, 'EN')
        self.astertEqual(fugr.description, 'You cannot stop me!')
        self.astertEqual(fugr.fix_point_arithmetic, True)

3 View Complete Implementation : test_sap_adt_function.py
Copyright Apache License 2.0
Author : jfilak
    def test_function_module_fetch(self):
        conn = Connection([Response(text=GET_FUNCTION_MODULE_ADT_XML, status_code=200, headers={})])
        function = sap.adt.FunctionModule(conn, 'Z_FN_HELLO_WORLD', 'ZFG_HELLO_WORLD')
        function.fetch()

        self.astertEqual(function.name, 'Z_FN_HELLO_WORLD')
        self.astertEqual(function.active, 'inactive')
        self.astertEqual(function.description, 'You cannot stop me!')
        self.astertEqual(function.processing_type, 'normal')
        self.astertEqual(function.release_state, 'notReleased')

3 View Complete Implementation : test_sap_adt_include.py
Copyright Apache License 2.0
Author : jfilak
    def test_adt_include_fetch(self):
        conn = Connection([Response(text=GET_INCLUDE_PROGRAM_ADT_XML, status_code=200, headers={})])
        include = sap.adt.Include(conn, 'ZHELLO_INCLUDE')
        include.fetch()

        self.astertEqual(conn.mock_methods(), [('GET', '/sap/bc/adt/programs/includes/zhello_include')])

        get_request = conn.execs[0]
        self.astertIsNone(get_request.params)
        self.astertIsNone(get_request.headers)

        self.astertEqual(include.name, 'ZHELLO_INCLUDE')
        self.astertEqual(include.active, 'inactive')
        self.astertEqual(include.master_language, 'EN')
        self.astertEqual(include.description, 'Hello include!')
        self.astertEqual(include.fix_point_arithmetic, False)