예제 #1
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
    }
예제 #2
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)
예제 #3
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]
    }
예제 #4
0
    def update(cls, contributor_id, data_source_id=None, dataset={}):
        if data_source_id is None:
            raise ValueError('A data_source id is required')
        if not [
                ds for ds in get_contributor(contributor_id).data_sources
                if ds.id == data_source_id
        ]:
            raise ValueError(
                "No data_source id {} exists in contributor with id {}".format(
                    contributor_id, data_source_id))
        if 'id' in dataset and dataset['id'] != data_source_id:
            raise ValueError(
                "Id from request {} doesn't match id from url {}".format(
                    dataset['id'], data_source_id))

        # `$` acts as a placeholder of the first match in the list
        contrib_dataset = {'data_sources': {'$': dataset}}
        raw = mongo.db[Contributor.mongo_collection].update_one(
            {'data_sources.id': data_source_id},
            {'$set': to_doted_notation(contrib_dataset)})
        if raw.matched_count == 0:
            return None

        return cls.get(contributor_id, data_source_id)
예제 #5
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}
예제 #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}
예제 #7
0
def test_to_doted_notation_one():
    data = {'a': 1, 'b': {'a': 3}}
    assert to_doted_notation(data) == {'a': 1, 'b.a': 3}
예제 #8
0
def test_to_doted_notation_flat():
    data = {'a': 1, 'b': 2}
    assert data == to_doted_notation(data)
예제 #9
0
파일: models.py 프로젝트: CanalTP/tartare
    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)
예제 #10
0
파일: models.py 프로젝트: CanalTP/tartare
    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)
예제 #11
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]}
예제 #12
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}
예제 #13
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}
예제 #14
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}
예제 #15
0
def test_to_doted_notation_one():
    data = {'a': 1, 'b': {'a': 3}}
    assert to_doted_notation(data) == {'a': 1, 'b.a': 3}
예제 #16
0
def test_to_doted_notation_flat():
    data = {'a': 1, 'b': 2}
    assert data == to_doted_notation(data)