Esempio n. 1
0
    def test_bool_nullable_field_with_none(self):
        with self.app.app_context():
            find_query = {'eating': [None]}

            db = self.app.config['db']
            res = list(find_items(db, **find_query))
            res = [res['_id'] for res in res]
            expected = [
                ObjectId('000000000000000000000003'),
                ObjectId('000000000000000000000004')
            ]
            self.assertCountEqual(res, expected)
def rename_filenames_in_items(db):
    # update documents
    filename_phrase_to_delete = '_trand1'
    filename_regex = f'^.*{filename_phrase_to_delete}.*$'
    items_docs = items.find_items(db, filename=filename_regex)

    bulks = []
    for item_doc in items_docs:
        fixed_filename = item_doc.filename.replace(filename_phrase_to_delete, '')
        bulk = UpdateOne({'filename': item_doc.filename}, {'$set': {'filename': fixed_filename}})
        bulks.append(bulk)

    if bulks:
        result = db.items.bulk_write(bulks)
        print(result.bulk_api_result)
Esempio n. 3
0
    def test_fields_combination(self):
        with self.app.app_context():
            find_query = {
                'species':
                'sp',
                'dead': [True, False],
                'acquisition_time_end':
                dateutil.parser.parse('2019-01-15T18:06:34.151Z')
            }

            db = self.app.config['db']
            res = list(find_items(db, **find_query))
            res = [res['_id'] for res in res]
            expected = [ObjectId('000000000000000000000002')]
            self.assertCountEqual(res, expected)
Esempio n. 4
0
    def test_datetime_field(self):
        with self.app.app_context():
            find_query = {
                'acquisition_time_start':
                dateutil.parser.parse('2019-01-11T18:06:34.151Z')
            }

            db = self.app.config['db']
            res = list(find_items(db, **find_query))
            res = [res['_id'] for res in res]
            expected = [
                ObjectId('000000000000000000000000'),
                ObjectId('000000000000000000000001')
            ]
            self.assertCountEqual(res, expected)