Esempio n. 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
    }
Esempio n. 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)
Esempio n. 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]
    }
Esempio n. 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)
Esempio n. 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}
Esempio n. 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}
Esempio n. 7
0
def test_to_doted_notation_one():
    data = {'a': 1, 'b': {'a': 3}}
    assert to_doted_notation(data) == {'a': 1, 'b.a': 3}
Esempio n. 8
0
def test_to_doted_notation_flat():
    data = {'a': 1, 'b': 2}
    assert data == to_doted_notation(data)
Esempio n. 9
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)
Esempio n. 10
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)
Esempio n. 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]}
Esempio n. 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}
Esempio n. 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}
Esempio n. 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}
Esempio n. 15
0
def test_to_doted_notation_one():
    data = {'a': 1, 'b': {'a': 3}}
    assert to_doted_notation(data) == {'a': 1, 'b.a': 3}
Esempio n. 16
0
def test_to_doted_notation_flat():
    data = {'a': 1, 'b': 2}
    assert data == to_doted_notation(data)