Example #1
0
    def update(cls, contributor_id=None, dataset={}):
        raw = mongo.db[cls.mongo_collection].update_one({'_id': contributor_id}, {'$set': to_doted_notation(dataset)})
        if raw.matched_count == 0:
            return None

        return cls.get(contributor_id)
Example #2
0
def test_to_doted_notation_with_list_of_scalars():
    data = {'a': 1, 'b': {'a': 3, 'b': {'c': 9, 'd': 10}}, 'e': [1, 2.6, "bar", True]}
    assert to_doted_notation(data) == {'a': 1, 'b.a': 3, 'b.b.c': 9, 'b.b.d': 10, 'e': [1, 2.6, "bar", True]}
Example #3
0
    def update(cls, coverage_id=None, dataset={}):
        #we have to use "doted notation' to only update some fields of a nested object
        raw = mongo.db[cls.mongo_collection].update_one({'_id': coverage_id}, {'$set': to_doted_notation(dataset)})
        if raw.matched_count == 0:
            return None

        return cls.get(coverage_id)
Example #4
0
def test_to_doted_notation_array():
    data = {'a': [{'b': 1}, {'c': 2}]}
    assert to_doted_notation(data) == {'a.0.b': 1, 'a.1.c': 2}
Example #5
0
def test_to_doted_notation_two():
    data = {'a': 1, 'b': {'a': 3, 'b': {'c': 9, 'd': 10}}}
    assert to_doted_notation(data) == {'a': 1, 'b.a': 3, 'b.b.c': 9, 'b.b.d': 10}
Example #6
0
def test_to_doted_notation_one_multiple():
    data = {'a': 1, 'b': {'a': 3, 'b': 5}}
    assert to_doted_notation(data) == {'a': 1, 'b.a': 3, 'b.b': 5}
Example #7
0
def test_to_doted_notation_one():
    data = {'a': 1, 'b': {'a': 3}}
    assert to_doted_notation(data) == {'a': 1, 'b.a': 3}
Example #8
0
def test_to_doted_notation_flat():
    data = {'a': 1, 'b': 2}
    assert data == to_doted_notation(data)