|
| 1 | +""" |
| 2 | +Test module for the Fedex Tools. |
| 3 | +""" |
| 4 | + |
| 5 | +import unittest |
| 6 | + |
| 7 | +import sys |
| 8 | + |
| 9 | +sys.path.insert(0, '..') |
| 10 | + |
| 11 | +import fedex.config |
| 12 | +import fedex.services.ship_service as service # Any request object will do. |
| 13 | +import fedex.tools.conversion |
| 14 | + |
| 15 | + |
| 16 | +class FedexToolsTests(unittest.TestCase): |
| 17 | + """ |
| 18 | + These tests verify that the fedex tools are working properly. |
| 19 | + """ |
| 20 | + |
| 21 | + def test_conversion_tools(self): |
| 22 | + # Empty config, since we are not actually sending anything |
| 23 | + config = fedex.config.FedexConfig(key='', password='', |
| 24 | + account_number='', meter_number='', |
| 25 | + use_test_server=True) |
| 26 | + |
| 27 | + # We need a mock suds object, a request object or sub-object will do. |
| 28 | + waybill_request = service.FedexProcessShipmentRequest(config) |
| 29 | + obj = waybill_request.create_wsdl_object_of_type('ProcessShipmentRequest') |
| 30 | + |
| 31 | + # Test basic sobject to dict. |
| 32 | + dict_obj = fedex.tools.conversion.basic_sobject_to_dict(obj) |
| 33 | + assert type(dict_obj) == dict |
| 34 | + |
| 35 | + # Test with serialization and case conversion. |
| 36 | + dict_obj = fedex.tools.conversion.sobject_to_dict(obj, key_to_lower=True, json_serialize=True) |
| 37 | + assert type(dict_obj) == dict |
| 38 | + |
| 39 | + # JSON string object test |
| 40 | + dict_obj = fedex.tools.conversion.sobject_to_json(obj) |
| 41 | + assert dict_obj, "Expecting a JSON string object." |
| 42 | + |
| 43 | +if __name__ == "__main__": |
| 44 | + unittest.main() |
0 commit comments