def run_for(self, obj_sets, max_verdicts=100): """Executes checks for the given object sets""" run_request = RunRequest(obj_sets, max_verdicts) request = Marshal().serialize(run_request) worklist_id = self._get_id() resp = self._connection.execute('POST', 'atc/runs', params={'worklistId': worklist_id}, accept='application/xml', content_type='application/xml', body=request) run_response = RunResponse() Marshal.deserialize(resp.text, run_response) resp = self._connection.execute( 'GET', f'atc/worklists/{worklist_id}', params={'includeExemptedFindings': 'false'}, accept='application/atc.worklist.v1+xml') worklist = WorkList() Marshal.deserialize(resp.text, worklist) return WorkListRunResult(run_response, worklist)
def try_activate(adt_object): """Activates the given object and returns CheckResults with the activation results. """ request = ADTObjectReferences() request.add_object(adt_object) resp = _send_activate(adt_object, request, activation_params(pre_audit_requested=True)) if 'application/vnd.sap.adt.inactivectsobjects.v1+xml' in resp.headers.get( 'Content-Type', ''): ioc = Marshal.deserialize(resp.text, IOCList()) get_logger().debug(ioc.entries) request = ADTObjectReferences([ entry.object.reference for entry in ioc.entries if entry.object is not None and entry.object.deleted == 'false' ]) resp = _send_activate(adt_object, request, activation_params(pre_audit_requested=False)) results = CheckResults() if resp.text: Marshal.deserialize(resp.text, results) return (results, resp)
def test_deserialize_with_node_attribute_value(self): parent = XmlNodeAttributePropertyADTObject() Marshal.deserialize( '''<?xml version="1.0" encoding="UTF-8"?> <mock:xmlnode xmlns:mock="https://example.org/mock" mock:attribute="deserialize"/>''', parent) self.assertEqual(parent.attribute, 'deserialize')
def test_deserialize_with_node_attribute_missing(self): parent = XmlNodeAttributePropertyADTObject() Marshal.deserialize( '''<?xml version="1.0" encoding="UTF-8"?> <mock:xmlnode xmlns:mock="https://example.org/mock"/>''', parent) self.assertIsNone(parent.attribute)
def test_deserialize_with_node_object(self): parent = XmlNodePropertyADTObject() Marshal.deserialize( '''<?xml version="1.0" encoding="UTF-8"?> <mock:xmlnodeparent xmlns:mock="https://example.org/mock"> <mock:child attribute="deserialize"/> </mock:xmlnodeparent>''', parent) self.assertIsNotNone(parent.child) self.assertEqual(parent.child.attribute, 'deserialize')
def test_deserialize_with_elem_text_empty(self): parent = TextElementADTObject() Marshal.deserialize( '''<?xml version="1.0" encoding="UTF-8"?> <mock:have_child_with_text xmlns:mock="https://example.org/mock"> <mock:holdstext></mock:holdstext> </mock:have_child_with_text>''', parent) self.assertEqual(parent.text, '')
def fetch_reporters(connection): """Returns the list of supported ADT reporters""" reporters = ReportersContainer() resp = connection.execute('GET', reporters.objtype.basepath, accept=reporters.objtype.mimetype) Marshal.deserialize(resp.text, reporters) return reporters.items
def test_xml_formatting(self): marshal = Marshal() elem = Element('root') elem.add_attribute('one', '1') elem.add_attribute('two', '2') child = elem.add_child('child') xml = marshal._tree_to_xml(elem) self.assertEqual( xml, '<?xml version="1.0" encoding="UTF-8"?>\n<root one="1" two="2">\n<child/>\n</root>' )
def test_serialize_versioned_none(self): obj = DummyADTObjectWithVersions() marshal = Marshal() with self.assertRaises(RuntimeError) as caught: xml = marshal.serialize(obj) self.assertEqual( str(caught.exception), 'The XML item mock:elemverfst specifies but its parent class does not' )
def test_deserialize_with_factory(self): dummy = DummyWithChildFactory() Marshal.deserialize( """<?xml version="1.0" encoding="UTF-8"?> <dummyxmlns:dummyelem> <child attribute="implicit"/> <child_setter attribute="setter"/> </dummyxmlns:dummyelem> """, dummy) self.assertEqual(DummyChild.instances[0].attribute, 'implicit') self.assertEqual(dummy.child_setter.attribute, 'setter')
def test_serialize_versioned_ver3(self): obj = DummyADTObjectWithVersions() marshal = Marshal(object_schema_version='V3') xml = marshal.serialize(obj) self.maxDiff = None self.assertEqual( xml, '''<?xml version="1.0" encoding="UTF-8"?> <mock:versioned xmlns:mock="https://github.com/jfilak/sapcli/mock" mock:attrverall="Init-attr-all"> <adtcore:packageRef/> <mock:elemverall>Init-elem-all</mock:elemverall> </mock:versioned>''')
def run(connection, reporter, object_list): """Run the reporter :class Reporter: for the give object list :class CheckObjectList:""" xml = Marshal().serialize(object_list) resp = connection.execute('POST', object_list.objtype.basepath, accept=CheckReportList.objtype.mimetype, content_type=object_list.objtype.mimetype, params={'reporters': reporter.name}, body=xml) report_list = CheckReportList() Marshal.deserialize(resp.text, report_list) return report_list.items
def test_deserialization(self): obj = Dummy() marshal = Marshal() xml_data = marshal.serialize(obj) clone = DummyWithSetters() ret = Marshal.deserialize(xml_data, clone) self.assertEqual(clone, ret) self.assertEqual(obj.first, clone.first) self.assertEqual(obj.second, clone.second) self.assertEqual('EEE', clone.third) self.assertEqual(obj.value.first, clone.value.first) self.assertEqual(obj.value.second, clone.value.second) self.assertEqual(obj.value.supernested.yetanother, clone.value.supernested.yetanother)
def test_serialize_with_node_attribute_value_none(self): parent = XmlNodeAttributePropertyADTObject() self.assertIsNone(parent.attribute) act = Marshal().serialize(parent) self.assertEqual( act, '''<?xml version="1.0" encoding="UTF-8"?> <mock:xmlnode xmlns:mock="https://example.org/mock"/>''')
def test_serialize_adtcore_and_no_code(self): obj = DummyADTCore() act = Marshal().serialize(obj) self.assertEqual( act, '''<?xml version="1.0" encoding="UTF-8"?> <adtcore:root xmlns:adtcore="http://www.sap.com/adt/core"> <adtcore:packageRef/> </adtcore:root>''')
def test_serialize_with_elem_text(self): parent = TextElementADTObject() act = Marshal().serialize(parent) self.assertEqual( act, '''<?xml version="1.0" encoding="UTF-8"?> <mock:have_child_with_text xmlns:mock="https://example.org/mock"> <mock:holdstext>content</mock:holdstext> </mock:have_child_with_text>''')
def test_serialize_with_elem_from_object(self): parent = ParentADTObject() act = Marshal().serialize(parent) self.assertEqual( act, '''<?xml version="1.0" encoding="UTF-8"?> <mock:parent xmlns:mock="https://example.org/mock"> <mock:child xmlns:foo="bar" value="stub"/> </mock:parent>''')
def _send_activate(adt_object, request, params): return adt_object.connection.execute('POST', 'activation', params=params, headers={ 'Accept': 'application/xml', 'Content-Type': 'application/xml' }, body=Marshal().serialize(request))
def test_deserialize_versioned(self): obj = DummyADTObjectWithVersions() marshal = Marshal() marshal.deserialize( '''<?xml version="1.0" encoding="UTF-8"?> <mock:versioned xmlns:mock="https://github.com/jfilak/sapcli/mock" mock:attrverfst="de-attr-fst" mock:attrverboth="de-attr-both" mock:attrverall="de-attr-all"> <adtcore:packageRef/> <mock:elemverfst>de-elem-fst</mock:elemverfst> <mock:elemverboth>de-elem-both</mock:elemverboth> <mock:elemverall>de-elem-all</mock:elemverall> </mock:versioned>''', obj) self.assertEqual(obj.attrverfst, 'de-attr-fst') self.assertEqual(obj.attrverboth, 'de-attr-both') self.assertEqual(obj.attrverall, 'de-attr-all') self.assertEqual(obj.elemverfst, 'de-elem-fst') self.assertEqual(obj.elemverboth, 'de-elem-both') self.assertEqual(obj.elemverall, 'de-elem-all')
def execute(self, statements_bulk_request): """Executes ABAP Coverage Statements on the given statement bulk request""" request_config = Marshal().serialize(statements_bulk_request) return self._connection.execute( 'POST', statements_bulk_request.objtype.basepath, content_type=statements_bulk_request.objtype.mimetype, body=request_config)
def test_serialize_with_node_object_none(self): parent = XmlNodePropertyADTObject() self.assertIsNone(parent.child) act = Marshal().serialize(parent) self.assertEqual( act, '''<?xml version="1.0" encoding="UTF-8"?> <mock:xmlnodeparent xmlns:mock="https://example.org/mock"> <mock:child/> </mock:xmlnodeparent>''')
def test_run_request_serialization(self): conn = Connection() obj_sets = sap.adt.objects.ADTObjectSets() obj_sets.include_object(sap.adt.Class(conn, 'ZCL_Z001_DPC')) atc_run_req = sap.adt.atc.RunRequest(obj_sets, 100) atc_run_xml = Marshal().serialize(atc_run_req) self.maxDiff = None self.assertEqual(atc_run_xml, ADT_XML_ATC_RUN_REQUEST_CLASS)
def test_object_list_add_uri(self): connection = Connection() obj_list = sap.adt.checks.CheckObjectList() obj_list.add_uri(sap.adt.Class(connection, 'CL_FIRST').full_adt_uri) obj_list.add_uri(sap.adt.Class(connection, 'CL_SECOND').full_adt_uri) xml_obj_list = Marshal().serialize(obj_list) self.maxDiff = None self.assertEqual(xml_obj_list, FIXTURE_TWO_CLASSES_REQUEST)
def execute(self, adt_object_sets): """Executes ABAP Unit tests on the given ADT object set""" run_configuration = RunConfiguration(adt_object_sets) test_config = Marshal().serialize(run_configuration) return self._connection.execute( 'POST', run_configuration.objtype.basepath, content_type=run_configuration.objtype.mimetype, body=test_config)
def test_deserialize_xml_text_list(self): container = DummyWithTheTextList() act = Marshal.deserialize( '''<?xml version="1.0" encoding="UTF-8"?> <mock:withlist xmlns:mock="https://example.org/mock"> <mock:item>1</mock:item> <mock:item>2</mock:item> <mock:item>3</mock:item> </mock:withlist>''', container) self.assertEqual(container.the_text_list, ['1', '2', '3'])
def execute(self, identifier, adt_object_sets): """Executes ABAP Coverage on the given ADT object set""" query = Query(identifier, adt_object_sets) coverage_config = Marshal().serialize(query) return self._connection.execute( 'POST', query.objtype.basepath, content_type=query.objtype.mimetype, body=coverage_config )
def test_tree_generation(self): obj = Dummy() marshal = Marshal() xmltree = marshal._object_to_tree(obj) self.assertEqual(xmltree.name, 'dummyxmlns:dummyelem') self.assertEqual(xmltree.attributes['attr_first'], '11111') self.assertEqual(xmltree.attributes['attr_second'], '22222') self.assertEqual(xmltree.children[0].name, 'adtcore:packageRef') self.assertEqual(xmltree.children[1].name, 'first_elem') self.assertEqual(xmltree.children[1].attributes['nst_fst'], 'nst_fst_val') self.assertEqual(xmltree.children[1].attributes['nst_scn'], 'nst_scn_val') self.assertEqual(xmltree.children[1].children[0].name, 'child_nst') self.assertEqual( xmltree.children[1].children[0].attributes['sup_nst_fst'], 'yetanother')
def execute(self, adt_object_sets, activate_coverage=False): """Executes ABAP Unit tests on the given ADT object set""" run_configuration = RunConfiguration(adt_object_sets) run_configuration.external.coverage.active = str( activate_coverage).lower() test_config = Marshal().serialize(run_configuration) return self._connection.execute( 'POST', run_configuration.objtype.basepath, content_type=run_configuration.objtype.mimetype, body=test_config)
def test_serialize_list(self): container = DummyContainer() act = Marshal().serialize(container) self.assertEqual( act, '''<?xml version="1.0" encoding="UTF-8"?> <adtcore:container xmlns:adtcore="http://www.sap.com/adt/core"> <adtcore:packageRef/> <item number="1"/> <item number="2"/> <item number="3"/> </adtcore:container>''')
def test_serialize_with_node_attribute_value(self): parent = XmlNodeAttributePropertyADTObject() parent.attribute = 'foo' self.assertIsNotNone(parent.attribute) # TODO: why it does not mind invalid attr name parent.attribute = 'foo' self.assertEqual(parent.attribute, 'foo') act = Marshal().serialize(parent) self.assertEqual( act, '''<?xml version="1.0" encoding="UTF-8"?> <mock:xmlnode xmlns:mock="https://example.org/mock" mock:attribute="foo"/>''')