| Conditions | 6 |
| Total Lines | 89 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | from authorizenet.constants import constants |
||
| 124 | def testGetCustomerProfile(self): |
||
| 125 | loggingfilename = utility.helper.getproperty(constants.propertiesloggingfilename) |
||
| 126 | logginglevel = utility.helper.getproperty(constants.propertiesexecutionlogginglevel) |
||
| 127 | logging.basicConfig(filename=loggingfilename, level=logginglevel, format=constants.defaultlogformat) |
||
| 128 | |||
| 129 | merchantAuth = apicontractsv1.merchantAuthenticationType() |
||
| 130 | merchantAuth.name = "unknown" |
||
| 131 | merchantAuth.transactionKey = "anon" |
||
| 132 | |||
| 133 | getCustomerProfileRequest = apicontractsv1.getCustomerProfileRequest() |
||
| 134 | getCustomerProfileRequest.merchantAuthentication = merchantAuth |
||
| 135 | getCustomerProfileRequest.customerProfileId = '36152115' |
||
| 136 | getCustomerProfileRequest.abc = 'aaaaaaaa' #extra property not in getCustomerProfileRequest object |
||
| 137 | |||
| 138 | logging.debug( "Request: %s " % datetime.datetime.now()) |
||
| 139 | logging.debug( " : %s " % getCustomerProfileRequest ) |
||
| 140 | |||
| 141 | try: |
||
| 142 | '''serialzing object to XML ''' |
||
| 143 | xmlRequest = getCustomerProfileRequest.toxml(encoding=constants.xml_encoding, element_name='getCustomerProfileRequest') |
||
| 144 | xmlRequest = xmlRequest.replace(constants.nsNamespace1, '') |
||
| 145 | xmlRequest = xmlRequest.replace(constants.nsNamespace2, '') |
||
| 146 | logging.debug( "Xml Request: %s" % xmlRequest) |
||
| 147 | #print( "Xml Request: %s" % xmlRequest) |
||
| 148 | except Exception as ex: |
||
| 149 | logging.debug( "Xml Exception: %s" % ex) |
||
| 150 | |||
| 151 | try: |
||
| 152 | '''deserialize XML to object ''' |
||
| 153 | deserializedObject = None |
||
| 154 | deserializedObject = apicontractsv1.CreateFromDocument(xmlRequest) |
||
| 155 | self.assertIsNotNone(deserializedObject, "Null deserializedObject ") |
||
| 156 | |||
| 157 | if type(getCustomerProfileRequest) == type(deserializedObject): |
||
| 158 | #print ("objects are equal") |
||
| 159 | logging.debug( "createtransactionrequest object is equal to deserializedObject") |
||
| 160 | else: |
||
| 161 | #print ("some error: objects are NOT equal" ) |
||
| 162 | logging.debug( "createtransactionrequest object is NOT equal to deserializedObject") |
||
| 163 | |||
| 164 | deseriaziedObjectXmlRequest = deserializedObject.toxml(encoding=constants.xml_encoding, element_name='deserializedObject') |
||
| 165 | deseriaziedObjectXmlRequest = deseriaziedObjectXmlRequest.replace(constants.nsNamespace1, '') |
||
| 166 | deseriaziedObjectXmlRequest = deseriaziedObjectXmlRequest.replace(constants.nsNamespace2, '') |
||
| 167 | logging.debug( "Good Dom Request: %s " % deseriaziedObjectXmlRequest ) |
||
| 168 | #print( "Good Dom Request: %s " % deseriaziedObjectXmlRequest ) |
||
| 169 | #print("de-serialized successfully. GOOD CASE COMPLETE \n ") |
||
| 170 | except Exception as ex: |
||
| 171 | |||
| 172 | logging.error( 'Create Document Exception: %s, %s', type(ex), ex.args ) |
||
| 173 | |||
| 174 | self.assertEquals(type(getCustomerProfileRequest), type(deserializedObject), "deseriaziedObject does not match original object") |
||
| 175 | |||
| 176 | try: |
||
| 177 | #print("starting with element in mid") |
||
| 178 | newxml = '<?xml version="1.0" encoding="utf-8"?><getCustomerProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"><merchantAuthentication><name>unknown</name><transactionKey>anon</transactionKey></merchantAuthentication><kriti>11Jan</kriti><customerProfileId>36152115</customerProfileId></getCustomerProfileRequest>' |
||
| 179 | |||
| 180 | #print ("newxml: %s" %newxml) |
||
| 181 | DEserializedNEWObject = apicontractsv1.CreateFromDocument(newxml) |
||
| 182 | self.assertIsNotNone(DEserializedNEWObject, "Null deserializedObject ") |
||
| 183 | |||
| 184 | |||
| 185 | DEseriaziedNEWObjectXmlRequest = DEserializedNEWObject.toxml(encoding=constants.xml_encoding, element_name='deserializedObject') |
||
| 186 | DEseriaziedNEWObjectXmlRequest = DEseriaziedNEWObjectXmlRequest.replace(constants.nsNamespace1, '') |
||
| 187 | DEseriaziedNEWObjectXmlRequest = DEseriaziedNEWObjectXmlRequest.replace(constants.nsNamespace2, '') |
||
| 188 | logging.debug( "Good Dom Request: %s " % DEseriaziedNEWObjectXmlRequest ) |
||
| 189 | #print( " DEseriaziedNEWObjectXmlRequest Request: %s " % DEseriaziedNEWObjectXmlRequest ) |
||
| 190 | #print("de-serialized successfully") |
||
| 191 | #print("FINISHED element in mid \n ") |
||
| 192 | except Exception as ex: |
||
| 193 | #print("DEseriaziedNEWObjectXmlRequest is NOT DESerialized") |
||
| 194 | logging.error( 'Create Document Exception: %s, %s', type(ex), ex.args ) |
||
| 195 | |||
| 196 | |||
| 197 | try: |
||
| 198 | #print("starting with element at last") |
||
| 199 | newxmlATLAst = '<?xml version="1.0" encoding="utf-8"?><getCustomerProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"><merchantAuthentication><name>unknown</name><transactionKey>anon</transactionKey></merchantAuthentication><customerProfileId>36152115</customerProfileId><gupta>11Jan</gupta></getCustomerProfileRequest>' |
||
| 200 | #print ("newxmlATLAst: %s" %newxmlATLAst) |
||
| 201 | DEserializedNEWObject = apicontractsv1.CreateFromDocument(newxmlATLAst) |
||
| 202 | self.assertIsNotNone(DEserializedNEWObject, "Null deserializedObject ") |
||
| 203 | DEseriaziedNEWObjectXmlRequest = DEserializedNEWObject.toxml(encoding=constants.xml_encoding, element_name='deserializedObject') |
||
| 204 | DEseriaziedNEWObjectXmlRequest = DEseriaziedNEWObjectXmlRequest.replace(constants.nsNamespace1, '') |
||
| 205 | DEseriaziedNEWObjectXmlRequest = DEseriaziedNEWObjectXmlRequest.replace(constants.nsNamespace2, '') |
||
| 206 | logging.debug( "Good Dom Request: %s " % DEseriaziedNEWObjectXmlRequest ) |
||
| 207 | #print( " DEseriaziedNEWATLASTObjectXmlRequest Request: %s " % DEseriaziedNEWObjectXmlRequest ) |
||
| 208 | #print("de-serialized successfully") |
||
| 209 | #print("Finished element at last \n " ) |
||
| 210 | except Exception as ex: |
||
| 211 | #print("DEseriaziedNEWATLASTObjectXmlRequest is NOT DESerialized") |
||
| 212 | logging.error( 'Create Document Exception: %s, %s', type(ex), ex.args ) |
||
| 213 | |||
| 216 |