• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Accruent / robotframework-zoomba / 7629307322

23 Jan 2024 05:09PM UTC coverage: 100.0%. Remained the same
7629307322

push

github

web-flow
Bump selenium from 4.16.0 to 4.17.2 (#388)

Bumps [selenium](https://github.com/SeleniumHQ/Selenium) from 4.16.0 to 4.17.2.
- [Release notes](https://github.com/SeleniumHQ/Selenium/releases)
- [Commits](https://github.com/SeleniumHQ/Selenium/commits)

---
updated-dependencies:
- dependency-name: selenium
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

621 of 621 relevant lines covered (100.0%)

5.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/Zoomba/SOAPLibrary.py
1
import json
5✔
2
from robot.libraries.BuiltIn import BuiltIn
5✔
3
from suds.plugin import DocumentPlugin
5✔
4
from suds.client import Client
5✔
5
from suds import WebFault
5✔
6

7
zoomba = BuiltIn()
5✔
8

9

10
class _ObjectNamespacePlugin(DocumentPlugin):
5✔
11
    """_ObjectNamespacePlugin
12

13
        This class contains a plugin for use in fixing broken WSDL Namespaces.\n
14
        defaultNamespace: (string) The default namespace found in the primary WSDL\n
15

16

17
    """
18
    defaultNamespace = None
5✔
19

20
    def loaded(self, context):
5✔
21
        """loaded. A plugin run after loading the WSDL but before using it to construct a client.\n
22
            context: (string) The Raw WSDL and imported schema.\n
23
        """
24
        if self.defaultNamespace is None:
5✔
25
            start = context.document.find(b'targetNamespace')
5✔
26
            first_quote = int(context.document.find(b'"', start)) + 1
5✔
27
            second_quote = int(context.document.find(b'"', first_quote))
5✔
28
            self.defaultNamespace = context.document[first_quote:second_quote]
5✔
29
        elif b'tns' not in context.document or b'targetNamespace' not in context.document:
5✔
30
            document_split = context.document.split(b'xmlns', 1)
5✔
31
            context.document = document_split[0]+b'xmlns:tns="'+self.defaultNamespace+b'" targetNamespace="' + self.defaultNamespace + b'" xmlns'+document_split[1]
5✔
32
            number_of_types = context.document.count(b'type="')
5✔
33
            start_location = context.document.find(b'type="')
5✔
34
            for _ in range(number_of_types):
5✔
35
                end_type = context.document.find(b'"', start_location+len(b'type="'))
5✔
36
                if b':' not in context.document[start_location:end_type]:
5✔
37
                    change_type = context.document[start_location:end_type]
5✔
38
                    change_type = change_type.replace(b'"', b'"tns:')
5✔
39
                    context.document = context.document[:start_location] + change_type + context.document[end_type:]
5✔
40
                start_location = context.document.find(b'type="', start_location+1)
5✔
41

42

43
class SOAPLibrary(object):
5✔
44
    """Zoomba SOAP Library
45

46
        This class is the base Library used to generate automated SOAP Tests in the Zoomba Automation Framework.
47

48
    """
49

50
    @staticmethod
5✔
51
    def create_soap_session_and_fix_wsdl(host=None, endpoint=None, alias=None, **kwargs):
5✔
52
        """Create Soap Session. This Keyword utilizes the WSDL and directly accesses calls from sudsLibrary.\n
53
            host: (string) The host url.\n
54
            endpoint: (string) SOAP API endpoint containing the actions to be referenced.\n
55
            alias: (string} Sets the alias for the SudsLibrary Framework
56
            **kwargs: (optional) Parameters that could be included to add options to client creation.
57
            Current supported parameters are:\n
58
                set_location: http address\n
59
        """
60
        pluginInstance = _ObjectNamespacePlugin()
5✔
61
        plugin_client = Client(host+endpoint + '?WSDL', plugins=[pluginInstance])
5✔
62
        suds_library = BuiltIn().get_library_instance("SudsLibrary")
5✔
63
        suds_library._add_client(plugin_client, alias)
5✔
64
        if 'set_location' in kwargs:
5✔
65
            suds_library.set_location(kwargs['set_location'])
5✔
66

67
    @staticmethod
5✔
68
    def create_soap_session(host=None, endpoint=None, alias=None, **kwargs):
5✔
69
        """ Create Soap Session. This Keyword utilizes the WSDL to create a soap client.\n
70
            host: (string) The host url.\n
71
            endpoint: (string) SOAP API endpoint containing the actions to be referenced.\n
72
            **kwargs: (optional) Parameters that could be included to add options to client creation.
73
            Current supported parameters are:\n
74
                set_location: http address\n
75
        """
76
        suds_library = BuiltIn().get_library_instance("SudsLibrary")
5✔
77
        if alias is not None:
5✔
78
            suds_library.create_soap_client(host+endpoint+'?WSDL', alias)
5✔
79
        else:
80
            suds_library.create_soap_client(host+endpoint+'?WSDL')
5✔
81
        if 'set_location' in kwargs:
5✔
82
            suds_library.set_location(kwargs['set_location'])
5✔
83

84
    def create_soap_session_and_set_location(self, host=None, endpoint=None, alias=None, set_location=None, fix=False):
5✔
85
        """ Create Soap Session and Set Location. In addition to the client creation, this keyword sets the location
86
            as specified.\n
87
            host: (string) The host url.\n
88
            endpoint: (string) SOAP API endpoint containing the actions to be referenced.\n
89
            set_location: (string) If set will overwrite the WSDL location with specified address.\n
90
            If set to None will replace location with host and endpoint specified\n
91
        """
92
        if set_location is None:
5✔
93
            set_location = host+endpoint
5✔
94
        if fix:
5✔
95
            self.create_soap_session_and_fix_wsdl(host, endpoint, alias, set_location=set_location)
5✔
96
        else:
97
            self.create_soap_session(host, endpoint, alias, set_location=set_location)
5✔
98

99
    @staticmethod
5✔
100
    def call_soap_method_with_list_object(action=None, soap_object=None):
5✔
101
        """ Call Soap Method. Calls soap method with list object \n
102
            action: (string) SOAP Action to be called.\n
103
            soap_object: (list) Soap Object in list format, list must be ordered wrt schema\n
104
        """
105
        suds_library = BuiltIn().get_library_instance("SudsLibrary")
5✔
106
        return suds_library.call_soap_method(action, *soap_object)
5✔
107

108
    @staticmethod
5✔
109
    def call_soap_method_with_object(action=None, **soap_object):
5✔
110
        """ Call Soap Method with dictionary object. Calls soap method \n
111
            action: (string) SOAP Action to be called.\n
112
            soap_object: (dict) Soap Object in dict format, dict must contain all required parts of schema object. \n
113
        """
114
        suds_library = BuiltIn().get_library_instance("SudsLibrary")
5✔
115
        client = suds_library._client()
5✔
116
        method = getattr(client.service, action)
5✔
117
        try:
5✔
118
            received = method(**soap_object)
5✔
119
        except WebFault as e:
5✔
120
            received = e.fault
5✔
121
        return received
5✔
122

123
    @staticmethod
5✔
124
    def create_wsdl_objects(wsdl_type=None, object_dict=None):
5✔
125
        """ Create Wsdl Objects. This Keyword utilizes the WSDL to create a WSDL object based on the information
126
            provided.\n
127
            wsdl_type: (string) Wsdl object to be created.\n
128
            object_dict: (dict) Python Dictionary containing values and nested dictionaries with construction similar to
129
            wsdl defined objects.\n
130
            return: (response object) Returns the SOAP client object.\n
131
        """
132
        client = BuiltIn().get_library_instance("SudsLibrary")._client()
5✔
133
        request_object = client.factory.create(wsdl_type)
5✔
134
        _build_wsdl_objects(client, request_object, object_dict)
5✔
135
        return request_object
5✔
136

137
    @staticmethod
5✔
138
    def convert_soap_response_to_json(soap_response=None):
5✔
139
        """ Convert Soap Response To Dictionary: This keyword builds a dictionary from the sudsLibrary response\n
140
            json_actual_response: (request response object) The response from an API.\n
141
            return: There is no actual returned output, other than error messages when comparisons fail.\n
142
        """
143
        a = _build_dict_from_response(soap_response)
5✔
144
        return json.dumps(a)
5✔
145

146

147
def _build_dict_from_response(soap_response=None):
5✔
148
    """
149
    Build Dict From Response: This keyword builds a dictionary from the sudsLibrary response.\n
150
    :param soap_response: sudsLibrary response.\n
151
    :return: python dictionary.\n
152
    """
153
    try:
5✔
154
        response_dictionary = dict(soap_response)
5✔
155
    except:  # lgtm [py/catch-base-exception]
5✔
156
        zoomba.log(message='Argument Passed Was Not Iterable', level='INFO')
5✔
157
        return soap_response
5✔
158
    new_response = {}
5✔
159

160
    for _ in range(len(response_dictionary)):
5✔
161
        key, value = response_dictionary.popitem()
5✔
162
        if isinstance(value, list):
5✔
163
            temp_list = []
5✔
164
            for item in value:
5✔
165
                if str(type(item)) == "<type 'instance'>" or 'sudsobject' in str(type(item)):
5✔
166
                    temp_item = _build_dict_from_response(item)
5✔
167
                    temp_list.append(temp_item)
5✔
168
                else:
169
                    temp_list.append(str(item))
5✔
170
            new_response[key] = temp_list
5✔
171
        elif str(type(value)) == "<type 'instance'>" or 'sudsobject' in str(type(value)):
5✔
172
            temp_dict = _build_dict_from_response(value)
5✔
173
            new_response[key] = temp_dict
5✔
174
        else:
175
            new_response[key] = str(value)
5✔
176
    return new_response
5✔
177

178

179
def _build_wsdl_objects(client=None, request_object=None, object_dict=None):
5✔
180
    """ Build Wsdl Objects. This Keyword utilizes the WSDL to build a wsdl object in a recursive manner.\n
181
        client: (SudsLibrary._client() instance) The current client session.\n
182
        request_object: (SudsLibrary._client.factory() instance) Wsdl object to be built.\n
183
        object_dict: (dict) Dictionary containing data to create request_object.\n
184

185
    """
186
    for key, value in object_dict.items():
5✔
187
        if isinstance(value, dict):
5✔
188
            try:
5✔
189
                temp_object = _wsdl_sub_builder(client, value)
5✔
190
                request_object.__setattr__(key, temp_object)
5✔
191
            except BaseException as ex:   #lgtm [py/catch-base-exception]
5✔
192
                if ex:
5✔
193
                    zoomba.log('Failed to define wsdl_object_type for child object. [' + key + ']', level='ERROR')
5✔
194
        elif isinstance(value, list):
5✔
195
            temp_list = []
5✔
196
            for item in value:
5✔
197
                if isinstance(item, dict):
5✔
198
                    temp_object = _wsdl_sub_builder(client, item)
5✔
199
                    temp_list.append(temp_object)
5✔
200
                else:
201
                    temp_list.append(item)
5✔
202
            request_object.__setattr__(key, temp_list)
5✔
203
        else:
204
            request_object.__setattr__(key, value)
5✔
205

206

207
def _wsdl_sub_builder(client=None, object_dict=None):
5✔
208
    """
209
    Wsdl Sub Builder. This Keyword creates children objects for wsdl objects.\n
210
    client: (SudsLibrary._client() instance) The current client session.\n
211
    object_dict:  (dict) Dictionary containing data to create request_object.\n
212
    (method only) wsdl_object_type: Wsdl object Type of wsdl sub-object.\n
213
    return: returns child object\n
214
    """
215
    sub_type = object_dict.pop('wsdl_object_type')
5✔
216
    temp_object = client.factory.create(sub_type)
5✔
217
    _build_wsdl_objects(client, temp_object, object_dict)
5✔
218
    return temp_object
5✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc