def test_location_value(self): latitude = 12345.67890 longitude = 09876.54321 horizontal_accuracy = 10 vertical_accuracy = 20 altitude = 30 speed = 0 course = 90.0 timestamp = 1234567890 json = { 'latitude': latitude, 'longitude': longitude, 'horizontalAccuracy': horizontal_accuracy, 'verticalAccuracy': vertical_accuracy, 'altitude': altitude, 'speed': speed, 'course': course, 'timestamp': timestamp } location_json = Location(json).json() comp_value = { 'value': location_json, 'type': 'LOCATION' } gen_value = CKValue(location_json, 'LOCATION') gen_json_value = CKValue(json=comp_value) self.failUnless(comp_value == gen_value.json()) self.failUnless(comp_value == gen_json_value.json())
def test_record(self): record_name = 'Record Name' record_type = 'Type' record_change_tag = 'a1' fields = { 'intField': CKValue(1), 'stringField': CKValue('Hello World') } created = None modified = None deleted = True json = { 'recordName': record_name, 'recordType': record_type, 'recordChangeTag': record_change_tag, 'fields': fields, 'created': created, 'modified': modified, 'deleted': deleted } gen_recrod = Record(json) self.failUnless(record_name == gen_recrod.record_name) self.failUnless(record_type == gen_recrod.record_type) self.failUnless(record_change_tag == gen_recrod.record_change_tag) self.failUnless(fields == gen_recrod.fields) self.failUnless(created == gen_recrod.created) self.failUnless(modified == gen_recrod.modified) self.failUnless(deleted == gen_recrod.deleted)
def test_datetime_value(self): date = datetime.utcnow() timestamp = (date - datetime(1970, 1, 1)).total_seconds() comp_value = {'value': int(timestamp * 1000), 'type': 'TIMESTAMP'} gen_value = CKValue(date) gen_json_value = CKValue(json=comp_value) self.failUnless(comp_value == gen_value.json()) self.failUnless(date.timetuple() == gen_json_value.value.timetuple())
def test_list_value(self): list_array = ['a', 'b', 'c'] comp_value = { 'value': list_array, } gen_value = CKValue(list_array) gen_json_value = CKValue(json=comp_value) self.failUnless(comp_value == gen_value.json()) self.failUnless(comp_value == gen_json_value.json())
def test_bool_value(self): boolean = False comp_value = { 'value': boolean, } gen_value = CKValue(boolean) gen_json_value = CKValue(json=comp_value) self.failUnless(comp_value == gen_value.json()) self.failUnless(comp_value == gen_json_value.json())
def test_int_value(self): integer = 1234 comp_value = { 'value': integer, 'type': 'INT64' } gen_value = CKValue(integer) gen_json_value = CKValue(json=comp_value) self.failUnless(comp_value == gen_value.json()) self.failUnless(comp_value == gen_json_value.json())
def test_double_value(self): double = 1234.56789 comp_value = { 'value': double, 'type': 'DOUBLE' } gen_value = CKValue(double) gen_json_value = CKValue(json=comp_value) self.failUnless(comp_value == gen_value.json()) self.failUnless(comp_value == gen_json_value.json())
def test_string_value(self): string = 'Hello World' comp_value = { 'value': string, 'type': 'STRING' } gen_value = CKValue(string) gen_json_value = CKValue(json=comp_value) self.failUnless(comp_value == gen_value.json()) self.failUnless(comp_value == gen_json_value.json())
def test_datetime_value(self): date = datetime.utcnow() timestamp = (date - datetime(1970, 1, 1)).total_seconds() comp_value = { 'value': int(timestamp * 1000), 'type': 'TIMESTAMP' } gen_value = CKValue(date) gen_json_value = CKValue(json=comp_value) self.failUnless(comp_value == gen_value.json()) self.failUnless(date.timetuple() == gen_json_value.value.timetuple())
def test_location_value(self): latitude = 12345.67890 longitude = 09876.54321 horizontal_accuracy = 10 vertical_accuracy = 20 altitude = 30 speed = 0 course = 90.0 timestamp = 1234567890 json = { 'latitude': latitude, 'longitude': longitude, 'horizontalAccuracy': horizontal_accuracy, 'verticalAccuracy': vertical_accuracy, 'altitude': altitude, 'speed': speed, 'course': course, 'timestamp': timestamp } location_json = Location(json).json() comp_value = {'value': location_json, 'type': 'LOCATION'} gen_value = CKValue(location_json, 'LOCATION') gen_json_value = CKValue(json=comp_value) self.failUnless(comp_value == gen_value.json()) self.failUnless(comp_value == gen_json_value.json())
def test_double_value(self): double = 1234.56789 comp_value = {'value': double, 'type': 'DOUBLE'} gen_value = CKValue(double) gen_json_value = CKValue(json=comp_value) self.failUnless(comp_value == gen_value.json()) self.failUnless(comp_value == gen_json_value.json())
def test_int_value(self): integer = 1234 comp_value = {'value': integer, 'type': 'INT64'} gen_value = CKValue(integer) gen_json_value = CKValue(json=comp_value) self.failUnless(comp_value == gen_value.json()) self.failUnless(comp_value == gen_json_value.json())
def test_string_value(self): string = 'Hello World' comp_value = {'value': string, 'type': 'STRING'} gen_value = CKValue(string) gen_json_value = CKValue(json=comp_value) self.failUnless(comp_value == gen_value.json()) self.failUnless(comp_value == gen_json_value.json())
def test_reference_value(self): zone_name = 'Zone Name' zone_id_json = { 'zoneName': zone_name } record_name = 'Record Name' zone_id = ZoneID(zone_id_json).json() action = CloudKit.NONE json = { 'recordName': record_name, 'zoneID': zone_id, 'action': action } reference_json = Reference(json).json() comp_value = { 'value': reference_json, 'type': 'REFERENCE' } gen_value = CKValue(reference_json, 'REFERENCE') gen_json_value = CKValue(json=comp_value) self.failUnless(comp_value == gen_value.json()) self.failUnless(comp_value == gen_json_value.json())
def test_asset_value(self): file_checksum = 'qwerty1234567890' size = 1234567890 reference_checksum = '1234567890qwerty' wrapping_key = '12345qwerty67890' receipt = 'receipt' download_url = 'some/download/path' json = { 'fileChecksum': file_checksum, 'size': size, 'referenceChecksum': reference_checksum, 'wrappingKey': wrapping_key, 'receipt': receipt, 'downloadURL': download_url } asset_json = Asset(json).json() comp_value = { 'value': asset_json, 'type': 'ASSET' } gen_value = CKValue(asset_json, 'ASSET') gen_json_value = CKValue(json=comp_value) self.failUnless(comp_value == gen_value.json()) self.failUnless(comp_value == gen_json_value.json())
def test_fields_value_dict(self): string = 'Hello World' integer = 1234 double = 1234.56789 boolean = False value_dict = { 'my_string': string, 'my_int': integer, 'my_double': double, 'my_boolean': boolean } fields = { 'my_string': { 'value': string, 'type': 'STRING' }, 'my_int': { 'value': integer, 'type': 'INT64' }, 'my_double': { 'value': double, 'type': 'DOUBLE' }, 'my_boolean': { 'value': boolean, } } gen_fields = CKValue.fields(value_dict) gen_value_dict = CKValue.value_dict(fields) self.failUnless(fields == gen_fields) self.failUnless(value_dict == gen_value_dict)
def test_datetime_value(self): date = datetime.utcnow() timestamp = time.mktime(date.timetuple()) comp_value = { 'value': timestamp, } gen_value = CKValue(date) gen_json_value = CKValue(json=comp_value) self.failUnless(comp_value == gen_value.json()) self.failUnless(comp_value == gen_json_value.json())
def test_reference_value(self): zone_name = 'Zone Name' zone_id_json = {'zoneName': zone_name} record_name = 'Record Name' zone_id = ZoneID(zone_id_json).json() action = CloudKit.NONE json = {'recordName': record_name, 'zoneID': zone_id, 'action': action} reference_json = Reference(json).json() comp_value = {'value': reference_json, 'type': 'REFERENCE'} gen_value = CKValue(reference_json, 'REFERENCE') gen_json_value = CKValue(json=comp_value) self.failUnless(comp_value == gen_value.json()) self.failUnless(comp_value == gen_json_value.json())
def test_asset_value(self): file_checksum = 'qwerty1234567890' size = 1234567890 reference_checksum = '1234567890qwerty' wrapping_key = '12345qwerty67890' receipt = 'receipt' download_url = 'some/download/path' json = { 'fileChecksum': file_checksum, 'size': size, 'referenceChecksum': reference_checksum, 'wrappingKey': wrapping_key, 'receipt': receipt, 'downloadURL': download_url } asset_json = Asset(json).json() comp_value = {'value': asset_json, 'type': 'ASSET'} gen_value = CKValue(asset_json, 'ASSET') gen_json_value = CKValue(json=comp_value) self.failUnless(comp_value == gen_value.json()) self.failUnless(comp_value == gen_json_value.json())