コード例 #1
0
def get_identifier(entity_name, object):
    """Get identifier from BrAPI object or generate one from hashed string json representation"""
    entity_id = entity_name + 'DbId'
    object_id = object.get(entity_id)
    if not object_id:
        simplified_object = remove_falsey(object, predicate=lambda x: x and not isinstance(x, set))
        object_id = str(hash(json.dumps(simplified_object, sort_keys=True)))
        object[entity_id] = object_id
    return object_id
コード例 #2
0
def get_identifier(entity_name, data):
    """
    Get identifier from BrAPI object or generate one from hashed string json representation
    """
    entity_id = entity_name + 'DbId'
    data_id = data.get(entity_id)
    if not data_id:
        simplified_object = remove_falsey(
            data, predicate=lambda x: x and not isinstance(x, set))
        json_rep = json.dumps(simplified_object, sort_keys=True)
        data_id = str(hashxx(json_rep.encode()))
    data[entity_id] = str(data_id)
    return data_id
コード例 #3
0
 def test_remove_in_composed_value(self):
     input_value = [
         None, {
             "a": None,
             "b": 2,
             "c": [{
                 "a": None,
                 "b": "",
                 "c": 1
             }, ""]
         }
     ]
     expected = [{'b': 2, 'c': [{'c': 1}]}]
     actual = remove_falsey(input_value)
     self.assertEqual(expected, actual)
コード例 #4
0
 def test_remove_in_dict(self):
     input_value = {"a": None, "b": 2}
     expected = {"b": 2}
     actual = remove_falsey(input_value)
     self.assertEqual(expected, actual)
コード例 #5
0
 def test_remove_heterogeneous(self):
     input_value = [None, "", {1, 2, None}, 0]
     expected = [{1, 2}]
     actual = remove_falsey(input_value)
     self.assertEqual(expected, actual)
コード例 #6
0
 def test_remove_empty(self):
     input_value = []
     expected = None
     actual = remove_falsey(input_value)
     self.assertEqual(expected, actual)