Skip to content

Commit

Permalink
adt/repository: ensure uniqness of node keys
Browse files Browse the repository at this point in the history
The read_node() method can be used to walk through function group
components (just like package walk()). However, reading a function
group node could cause an error in case that the group specifies
multiple components with the same node key ('Function Group Includes'
and 'Includes' have the same node key).

Note, the order of keys has no significance; hence converting the list
ot set works just fine.
  • Loading branch information
palubaj authored and jfilak committed Jul 27, 2023
1 parent 2fe19ad commit 66c20d4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions sap/adt/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def read_node(self, adt_object, withdescr=False, nodekeys=None):
if nodekeys is None:
keys = nodekeys_list_table(('000000',))
else:
nodekeys = set(nodekeys) # remove duplicates
keys = nodekeys_list_table(nodekeys)

resp = self._connection.execute(
Expand Down
9 changes: 6 additions & 3 deletions test/unit/test_sap_adt_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import sap.errors
import sap.adt

from mock import Connection, Response

from mock import Connection, Response, PatcherTestCase
from fixtures_adt_package import GET_PACKAGE_ADT_XML
from fixtures_adt_repository import (PACKAGE_ROOT_NODESTRUCTURE_OK_RESPONSE,
PACKAGE_ROOT_REQUEST_XML,
Expand Down Expand Up @@ -91,7 +90,11 @@ def test_adt_package_fetch(self):
self.assertEqual(package.description, 'This is a package')


class TestADTPackageWalk(unittest.TestCase):
class TestADTPackageWalk(unittest.TestCase, PatcherTestCase):

def setUp(self) -> None:
super().setUp()
self.patch('sap.adt.repository.set', new=lambda x: x)

def test_with_empty_subpackage(self):
connection = Connection([PACKAGE_ROOT_NODESTRUCTURE_OK_RESPONSE,
Expand Down
19 changes: 16 additions & 3 deletions test/unit/test_sap_adt_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@

import sap.adt

from mock import Connection

from mock import Connection, PatcherTestCase
from fixtures_adt_repository import (PACKAGE_ROOT_NODESTRUCTURE_OK_RESPONSE,
PACKAGE_ROOT_REQUEST_XML,
PACKAGE_SOURCE_LIBRARY_NODESTRUCUTRE_OK_RESPONSE,
PACKAGE_SOURCE_LIBRARY_REQUEST_XML)


class TestRepository(unittest.TestCase):
class TestRepository(unittest.TestCase, PatcherTestCase):

@staticmethod
def get_ordered_set(items):
return dict.fromkeys(items) # as of Python 3.7, dict keeps insertion order

def setUp(self) -> None:
super().setUp()
self.patch('sap.adt.repository.set', new=lambda items: self.get_ordered_set(items))

def read_package_node(self, responses, nodekeys):
connection = Connection(responses)
Expand Down Expand Up @@ -154,6 +161,12 @@ def test_read_node(self):
))
])

def test_read_node_not_unique_nodekeys(self):
node, connection = self.read_package_node([PACKAGE_SOURCE_LIBRARY_NODESTRUCUTRE_OK_RESPONSE],
('000005', '000011', '000002', '000005'))

self.assertEqual(connection.execs[0].body, PACKAGE_SOURCE_LIBRARY_REQUEST_XML)


if __name__ == '__main__':
unittest.main()

0 comments on commit 66c20d4

Please sign in to comment.