Пример #1
0
    def test_BackwardsCompatibilityLength(self, session=None):
        did_name = self._create_tmp_DID()
        set_metadata(scope=self.tmp_scope, name=did_name, key='length', value='10')

        dids = []
        q = FilterEngine('length >= 10', model_class=models.DataIdentifier).create_sqla_query(additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(list(map(lambda did: did.name == did_name, dids)).count(True), 1)

        dids = []
        q = FilterEngine('length > 9', model_class=models.DataIdentifier).create_sqla_query(additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(list(map(lambda did: did.name == did_name, dids)).count(True), 1)

        dids = []
        q = FilterEngine('length <= 10', model_class=models.DataIdentifier).create_sqla_query(additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(list(map(lambda did: did.name == did_name, dids)).count(True), 1)

        dids = []
        q = FilterEngine('length < 11', model_class=models.DataIdentifier).create_sqla_query(additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(list(map(lambda did: did.name == did_name, dids)).count(True), 1)
    def test_list_did_meta(self):
        """ DID Meta (JSON): List did meta """
        skip_without_json()

        meta_key1 = 'my_key_%s' % generate_uuid()
        meta_key2 = 'my_key_%s' % generate_uuid()
        meta_value1 = 'my_value_%s' % generate_uuid()
        meta_value2 = 'my_value_%s' % generate_uuid()

        tmp_dsn1 = 'dsn_%s' % generate_uuid()
        add_did(scope=self.tmp_scope, name=tmp_dsn1, type="DATASET", account=self.root)
        set_metadata(scope=self.tmp_scope, name=tmp_dsn1, key=meta_key1, value=meta_value1)

        tmp_dsn2 = 'dsn_%s' % generate_uuid()
        add_did(scope=self.tmp_scope, name=tmp_dsn2, type="DATASET", account=self.root)
        set_metadata(scope=self.tmp_scope, name=tmp_dsn2, key=meta_key1, value=meta_value2)

        tmp_dsn3 = 'dsn_%s' % generate_uuid()
        add_did(scope=self.tmp_scope, name=tmp_dsn3, type="DATASET", account=self.root)
        set_metadata(scope=self.tmp_scope, name=tmp_dsn3, key=meta_key2, value=meta_value1)

        tmp_dsn4 = 'dsn_%s' % generate_uuid()
        add_did(scope=self.tmp_scope, name=tmp_dsn4, type="DATASET", account=self.root)
        set_metadata(scope=self.tmp_scope, name=tmp_dsn4, key=meta_key1, value=meta_value1)
        set_metadata(scope=self.tmp_scope, name=tmp_dsn4, key=meta_key2, value=meta_value2)

        dids = list_dids(self.tmp_scope, {meta_key1: meta_value1})
        results = sorted(list(dids))

        assert len(results) == 2
        # assert sorted([{'scope': tmp_scope, 'name': tmp_dsn1}, {'scope': tmp_scope, 'name': tmp_dsn4}]) == sorted(results)
        expected = sorted([tmp_dsn1, tmp_dsn4])
        assert expected == results

        dids = list_dids(self.tmp_scope, {meta_key1: meta_value2})
        results = []
        for d in dids:
            results.append(d)
        assert len(results) == 1
        # assert [{'scope': (tmp_scope), 'name': str(tmp_dsn2)}] == results
        assert [tmp_dsn2] == results

        dids = list_dids(self.tmp_scope, {meta_key2: meta_value1})
        results = []
        for d in dids:
            results.append(d)
        assert len(results) == 1
        # assert [{'scope': (tmp_scope), 'name': tmp_dsn3}] == results
        assert [tmp_dsn3] == results

        dids = list_dids(self.tmp_scope, {meta_key1: meta_value1, meta_key2: meta_value2})
        results = []
        for d in dids:
            results.append(d)
        assert len(results) == 1
        # assert [{'scope': (tmp_scope), 'name': tmp_dsn4}] == results
        assert [tmp_dsn4] == results
    def test_get_metadata(self):
        """ DID Meta (JSON): Get did meta """
        skip_without_json()

        did_name = 'mock_did_%s' % generate_uuid()
        meta_key = 'my_key_%s' % generate_uuid()
        meta_value = 'my_value_%s' % generate_uuid()
        add_did(scope=self.tmp_scope, name=did_name, type='DATASET', account=self.root)
        set_metadata(scope=self.tmp_scope, name=did_name, key=meta_key, value=meta_value)
        assert get_metadata(scope=self.tmp_scope, name=did_name, plugin='JSON')[meta_key] == meta_value
Пример #4
0
    def test_OperatorsEqualNotEqual(self, session=None):
        # Plugin: DID
        #
        did_name1 = self._create_tmp_DID()
        did_name2 = self._create_tmp_DID()
        did_name3 = self._create_tmp_DID()
        set_metadata(scope=self.tmp_scope, name=did_name1, key='run_number', value=1)
        set_metadata(scope=self.tmp_scope, name=did_name2, key='run_number', value=2)

        dids = []
        q = FilterEngine('run_number=1', model_class=models.DataIdentifier).create_sqla_query(
            additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(list(map(lambda did: did.name in (did_name1, did_name2, did_name3), dids)).count(True), 1)

        dids = []
        q = FilterEngine('run_number!=1', model_class=models.DataIdentifier).create_sqla_query(
            additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(list(map(lambda did: did.name in (did_name1, did_name2, did_name3), dids)).count(True), 2)     # 1, 3 (NULL counted in not equals)

        # Plugin: JSON
        #
        if json_implemented(session=session):
            did_name1 = self._create_tmp_DID()
            did_name2 = self._create_tmp_DID()
            did_name3 = self._create_tmp_DID()
            set_metadata(scope=self.tmp_scope, name=did_name1, key='testkeyint1', value=1)
            set_metadata(scope=self.tmp_scope, name=did_name2, key='testkeyint2', value=2)
            set_metadata(scope=self.tmp_scope, name=did_name3, key='testkeyint3', value=2)

            dids = []
            q = FilterEngine('testkeyint1=1', model_class=models.DidMeta, strict_coerce=False).create_sqla_query(
                additional_model_attributes=[
                    models.DidMeta.scope,
                    models.DidMeta.name
                ],
                json_column=models.DidMeta.meta)
            dids += [did for did in q.yield_per(5)]
            dids = set(dids)
            self.assertEqual(list(map(lambda did: did.name in (did_name1, did_name2, did_name3), dids)).count(True), 1)

        if session.bind.dialect.name != 'oracle' and json_implemented(session=session):
            dids = []
            q = FilterEngine('testkeyint1!=1', model_class=models.DidMeta, strict_coerce=False).create_sqla_query(
                additional_model_attributes=[
                    models.DidMeta.scope,
                    models.DidMeta.name
                ],
                json_column=models.DidMeta.meta)
            dids += [did for did in q.yield_per(5)]
            dids = set(dids)
            self.assertEqual(list(map(lambda did: did.name in (did_name1, did_name2, did_name3), dids)).count(True), 2)
Пример #5
0
 def test_add_did_meta(self):
     """ DID Meta (Hardcoded): Add did meta """
     did_name = 'mock_did_%s' % generate_uuid()
     add_did(scope=self.tmp_scope,
             name=did_name,
             type='DATASET',
             account=self.root)
     set_metadata(scope=self.tmp_scope,
                  name=did_name,
                  key='project',
                  value='data12_8TeV')
     assert get_metadata(scope=self.tmp_scope,
                         name=did_name)['project'] == 'data12_8TeV'
Пример #6
0
    def test_OneSidedInequality(self, session=None):
        did_name = self._create_tmp_DID()
        set_metadata(scope=self.tmp_scope,
                     name=did_name,
                     key='run_number',
                     value=1)

        dids = []
        q = FilterEngine(
            'run_number > 0',
            model_class=models.DataIdentifier).create_sqla_query(
                additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(
            list(map(lambda did: did.name == did_name, dids)).count(True), 1)

        dids = []
        q = FilterEngine(
            'run_number < 2',
            model_class=models.DataIdentifier).create_sqla_query(
                additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(
            list(map(lambda did: did.name == did_name, dids)).count(True), 1)

        dids = []
        q = FilterEngine(
            'run_number < 0',
            model_class=models.DataIdentifier).create_sqla_query(
                additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertNotEqual(
            list(map(lambda did: did.name == did_name, dids)).count(True), 1)

        dids = []
        q = FilterEngine(
            'run_number > 2',
            model_class=models.DataIdentifier).create_sqla_query(
                additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertNotEqual(
            list(map(lambda did: did.name == did_name, dids)).count(True), 1)
Пример #7
0
 def test_get_metadata(self):
     """ DID Meta (JSON): Get did meta """
     if not self.implemented:
         # For some oracle and sqlite version json support is not implemented
         return
     did_name = 'mock_did_%s' % generate_uuid()
     meta_key = 'my_key_%s' % generate_uuid()
     meta_value = 'my_value_%s' % generate_uuid()
     add_did(scope=self.tmp_scope,
             name=did_name,
             type='DATASET',
             account=self.root)
     set_metadata(scope=self.tmp_scope,
                  name=did_name,
                  key=meta_key,
                  value=meta_value)
     assert get_metadata(scope=self.tmp_scope, name=did_name,
                         plugin='JSON')[meta_key] == meta_value
Пример #8
0
    def test_OperatorsEqualNotEqual(self, session=None):
        did_name1 = self._create_tmp_DID()
        did_name2 = self._create_tmp_DID()
        did_name3 = self._create_tmp_DID()
        set_metadata(scope=self.tmp_scope,
                     name=did_name1,
                     key='run_number',
                     value=1)
        set_metadata(scope=self.tmp_scope,
                     name=did_name2,
                     key='run_number',
                     value=2)

        dids = []
        q = FilterEngine(
            'run_number=1',
            model_class=models.DataIdentifier).create_sqla_query(
                additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(
            list(
                map(lambda did: did.name in (did_name1, did_name2, did_name3),
                    dids)).count(True), 1)

        dids = []
        q = FilterEngine(
            'run_number!=1',
            model_class=models.DataIdentifier).create_sqla_query(
                additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(
            list(
                map(lambda did: did.name in (did_name1, did_name2, did_name3),
                    dids)).count(True), 2)  # 1, 3 (NULL counted in not equals)
Пример #9
0
    def test_AndOrGroups(self, session=None):
        did_name1 = self._create_tmp_DID()
        did_name2 = self._create_tmp_DID()
        did_name3 = self._create_tmp_DID()
        set_metadata(scope=self.tmp_scope,
                     name=did_name1,
                     key='run_number',
                     value='1')
        set_metadata(scope=self.tmp_scope,
                     name=did_name2,
                     key='project',
                     value="test")
        set_metadata(scope=self.tmp_scope,
                     name=did_name3,
                     key='run_number',
                     value='1')
        set_metadata(scope=self.tmp_scope,
                     name=did_name3,
                     key='project',
                     value="test")

        dids = []
        q = FilterEngine(
            'run_number = 1, project != test; project = test',
            model_class=models.DataIdentifier).create_sqla_query(
                additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(
            list(
                map(lambda did: did.name in (did_name1, did_name2, did_name3),
                    dids)).count(True), 3)  # 1, 2, 3

        dids = []
        q = FilterEngine(
            'run_number = 1, project = test; run_number != 1',
            model_class=models.DataIdentifier).create_sqla_query(
                additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(
            list(
                map(lambda did: did.name in (did_name1, did_name2, did_name3),
                    dids)).count(True), 2)  # 2, 3
Пример #10
0
    def test_list_did_meta(self):
        """ DID Meta (JSON): List did meta """
        if not self.implemented:
            # For some oracle and sqlite version json support is not implemented
            return

        meta_key1 = 'my_key_%s' % generate_uuid()
        meta_key2 = 'my_key_%s' % generate_uuid()
        meta_value1 = 'my_value_%s' % generate_uuid()
        meta_value2 = 'my_value_%s' % generate_uuid()

        tmp_dsn1 = 'dsn_%s' % generate_uuid()
        add_did(scope=self.tmp_scope,
                name=tmp_dsn1,
                type="DATASET",
                account=self.root)
        set_metadata(scope=self.tmp_scope,
                     name=tmp_dsn1,
                     key=meta_key1,
                     value=meta_value1)

        tmp_dsn2 = 'dsn_%s' % generate_uuid()
        add_did(scope=self.tmp_scope,
                name=tmp_dsn2,
                type="DATASET",
                account=self.root)
        set_metadata(scope=self.tmp_scope,
                     name=tmp_dsn2,
                     key=meta_key1,
                     value=meta_value2)

        tmp_dsn3 = 'dsn_%s' % generate_uuid()
        add_did(scope=self.tmp_scope,
                name=tmp_dsn3,
                type="DATASET",
                account=self.root)
        set_metadata(scope=self.tmp_scope,
                     name=tmp_dsn3,
                     key=meta_key2,
                     value=meta_value1)

        tmp_dsn4 = 'dsn_%s' % generate_uuid()
        add_did(scope=self.tmp_scope,
                name=tmp_dsn4,
                type="DATASET",
                account=self.root)
        set_metadata(scope=self.tmp_scope,
                     name=tmp_dsn4,
                     key=meta_key1,
                     value=meta_value1)
        set_metadata(scope=self.tmp_scope,
                     name=tmp_dsn4,
                     key=meta_key2,
                     value=meta_value2)

        dids = list_dids(self.tmp_scope, {meta_key1: meta_value1})
        results = []
        for d in dids:
            results.append(d)

        assert_equal(len(results), 2)
        # assert_equal(sorted([{'scope': tmp_scope, 'name': tmp_dsn1}, {'scope': tmp_scope, 'name': tmp_dsn4}]), sorted(results))
        assert_equal(sorted([tmp_dsn1, tmp_dsn4]), sorted(results))

        dids = list_dids(self.tmp_scope, {meta_key1: meta_value2})
        results = []
        for d in dids:
            results.append(d)
        assert_equal(len(results), 1)
        # assert_equal([{'scope': (tmp_scope), 'name': str(tmp_dsn2)}], results)
        assert_equal([tmp_dsn2], results)

        dids = list_dids(self.tmp_scope, {meta_key2: meta_value1})
        results = []
        for d in dids:
            results.append(d)
        assert_equal(len(results), 1)
        # assert_equal([{'scope': (tmp_scope), 'name': tmp_dsn3}], results)
        assert_equal([tmp_dsn3], results)

        dids = list_dids(self.tmp_scope, {
            meta_key1: meta_value1,
            meta_key2: meta_value2
        })
        results = []
        for d in dids:
            results.append(d)
        assert_equal(len(results), 1)
        # assert_equal([{'scope': (tmp_scope), 'name': tmp_dsn4}], results)
        assert_equal([tmp_dsn4], results)
Пример #11
0
    def test_Wildcards(self, session=None):
        did_name1 = self._create_tmp_DID()
        did_name2 = self._create_tmp_DID()
        did_name3 = self._create_tmp_DID()
        did_name4 = self._create_tmp_DID()
        did_name5 = self._create_tmp_DID()
        set_metadata(scope=self.tmp_scope,
                     name=did_name1,
                     key='project',
                     value="test1")
        set_metadata(scope=self.tmp_scope,
                     name=did_name2,
                     key='project',
                     value="test2")
        set_metadata(scope=self.tmp_scope,
                     name=did_name3,
                     key='project',
                     value="anothertest1")
        set_metadata(scope=self.tmp_scope,
                     name=did_name4,
                     key='project',
                     value="anothertest2")

        dids = []
        q = FilterEngine(
            'project = test*',
            model_class=models.DataIdentifier).create_sqla_query(
                additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(
            list(
                map(
                    lambda did: did.name in
                    (did_name1, did_name2, did_name3, did_name4, did_name5),
                    dids)).count(True), 2)  # 1, 2

        dids = []
        q = FilterEngine(
            'project = *test*',
            model_class=models.DataIdentifier).create_sqla_query(
                additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(
            list(
                map(
                    lambda did: did.name in
                    (did_name1, did_name2, did_name3, did_name4, did_name5),
                    dids)).count(True), 4)  # 1, 2, 3, 4

        dids = []
        q = FilterEngine(
            'project != *anothertest*',
            model_class=models.DataIdentifier).create_sqla_query(
                additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(
            list(
                map(
                    lambda did: did.name in
                    (did_name1, did_name2, did_name3, did_name4, did_name5),
                    dids)).count(True),
            3)  # 3, 4, 5 (NULL counted in not equals)

        dids = []
        q = FilterEngine(
            'project != *test*',
            model_class=models.DataIdentifier).create_sqla_query(
                additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(
            list(
                map(
                    lambda did: did.name in
                    (did_name1, did_name2, did_name3, did_name4, did_name5),
                    dids)).count(True), 1)  # 5 (NULL counted in not equals)
Пример #12
0
    def test_Wildcards(self, session=None):
        # Plugin: DID
        #
        did_name1 = self._create_tmp_DID()
        did_name2 = self._create_tmp_DID()
        did_name3 = self._create_tmp_DID()
        did_name4 = self._create_tmp_DID()
        did_name5 = self._create_tmp_DID()
        set_metadata(scope=self.tmp_scope, name=did_name1, key='project', value="test1")
        set_metadata(scope=self.tmp_scope, name=did_name2, key='project', value="test2")
        set_metadata(scope=self.tmp_scope, name=did_name3, key='project', value="anothertest1")
        set_metadata(scope=self.tmp_scope, name=did_name4, key='project', value="anothertest2")

        dids = []
        q = FilterEngine('project = test*', model_class=models.DataIdentifier).create_sqla_query(additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(list(map(lambda did: did.name in (did_name1, did_name2, did_name3, did_name4, did_name5), dids)).count(True), 2)  # 1, 2

        dids = []
        q = FilterEngine('project = *test*', model_class=models.DataIdentifier).create_sqla_query(additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(list(map(lambda did: did.name in (did_name1, did_name2, did_name3, did_name4, did_name5), dids)).count(True), 4)  # 1, 2, 3, 4

        dids = []
        q = FilterEngine('project != *anothertest*', model_class=models.DataIdentifier).create_sqla_query(additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(list(map(lambda did: did.name in (did_name1, did_name2, did_name3, did_name4, did_name5), dids)).count(True), 3)  # 3, 4, 5 (NULL counted in not equals)

        dids = []
        q = FilterEngine('project != *test*', model_class=models.DataIdentifier).create_sqla_query(additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(list(map(lambda did: did.name in (did_name1, did_name2, did_name3, did_name4, did_name5), dids)).count(True), 1)  # 5 (NULL counted in not equals)

        # Plugin: JSON
        #
        if session.bind.dialect.name != 'oracle' and json_implemented(session=session):
            did_name1 = self._create_tmp_DID()
            did_name2 = self._create_tmp_DID()
            did_name3 = self._create_tmp_DID()
            did_name4 = self._create_tmp_DID()
            did_name5 = self._create_tmp_DID()
            set_metadata(scope=self.tmp_scope, name=did_name1, key='testkeystr1', value="test1")
            set_metadata(scope=self.tmp_scope, name=did_name2, key='testkeystr1', value="test2")
            set_metadata(scope=self.tmp_scope, name=did_name3, key='testkeystr1', value="anothertest1")
            set_metadata(scope=self.tmp_scope, name=did_name4, key='testkeystr1', value="anothertest2")

            dids = []
            q = FilterEngine('testkeystr1 = test*', model_class=models.DidMeta, strict_coerce=False).create_sqla_query(
                additional_model_attributes=[
                    models.DidMeta.scope,
                    models.DidMeta.name
                ],
                json_column=models.DidMeta.meta)
            dids += [did for did in q.yield_per(5)]
            dids = set(dids)
            self.assertEqual(list(map(lambda did: did.name in (did_name1, did_name2, did_name3, did_name4, did_name5), dids)).count(True), 2)  # 1, 2

            dids = []
            q = FilterEngine('testkeystr1 = *test*', model_class=models.DidMeta, strict_coerce=False).create_sqla_query(
                additional_model_attributes=[
                    models.DidMeta.scope,
                    models.DidMeta.name
                ],
                json_column=models.DidMeta.meta)
            dids += [did for did in q.yield_per(5)]
            dids = set(dids)
            self.assertEqual(list(map(lambda did: did.name in (did_name1, did_name2, did_name3, did_name4, did_name5), dids)).count(True), 4)  # 1, 2, 3, 4

            dids = []
            q = FilterEngine('testkeystr1 != *anothertest*', model_class=models.DidMeta, strict_coerce=False).create_sqla_query(
                additional_model_attributes=[
                    models.DidMeta.scope,
                    models.DidMeta.name
                ],
                json_column=models.DidMeta.meta)
            dids += [did for did in q.yield_per(5)]
            dids = set(dids)
            self.assertEqual(list(map(lambda did: did.name in (did_name1, did_name2, did_name3, did_name4, did_name5), dids)).count(True), 2)  # 3, 4

            dids = []
            q = FilterEngine('testkeystr1 != *test*', model_class=models.DidMeta, strict_coerce=False).create_sqla_query(
                additional_model_attributes=[
                    models.DidMeta.scope,
                    models.DidMeta.name
                ],
                json_column=models.DidMeta.meta)
            dids += [did for did in q.yield_per(5)]
            dids = set(dids)
            self.assertEqual(list(map(lambda did: did.name in (did_name1, did_name2, did_name3, did_name4, did_name5), dids)).count(True), 0)
Пример #13
0
    def test_AndOrGroups(self, session=None):
        # Plugin: DID
        #
        did_name1 = self._create_tmp_DID()
        did_name2 = self._create_tmp_DID()
        did_name3 = self._create_tmp_DID()
        set_metadata(scope=self.tmp_scope, name=did_name1, key='run_number', value='1')
        set_metadata(scope=self.tmp_scope, name=did_name2, key='project', value="test")
        set_metadata(scope=self.tmp_scope, name=did_name3, key='run_number', value='1')
        set_metadata(scope=self.tmp_scope, name=did_name3, key='project', value="test")

        dids = []
        q = FilterEngine('run_number = 1, project != test; project = test', model_class=models.DataIdentifier).create_sqla_query(additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(list(map(lambda did: did.name in (did_name1, did_name2, did_name3), dids)).count(True), 3)     # 1, 2, 3

        dids = []
        q = FilterEngine('run_number = 1, project = test; run_number != 1', model_class=models.DataIdentifier).create_sqla_query(additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(list(map(lambda did: did.name in (did_name1, did_name2, did_name3), dids)).count(True), 2)     # 2, 3

        # Plugin: JSON
        #
        if session.bind.dialect.name != 'oracle' and json_implemented(session=session):
            did_name1 = self._create_tmp_DID()
            did_name2 = self._create_tmp_DID()
            did_name3 = self._create_tmp_DID()
            set_metadata(scope=self.tmp_scope, name=did_name1, key='testkeyint1', value='1')
            set_metadata(scope=self.tmp_scope, name=did_name2, key='testkeystr1', value="test")
            set_metadata(scope=self.tmp_scope, name=did_name3, key='testkeyint1', value='1')
            set_metadata(scope=self.tmp_scope, name=did_name3, key='testkeystr1', value="test")

            dids = []
            q = FilterEngine('testkeyint1 = 1, testkeystr1 != test; testkeystr1 = test', model_class=models.DidMeta, strict_coerce=False).create_sqla_query(
                additional_model_attributes=[
                    models.DidMeta.scope,
                    models.DidMeta.name
                ],
                json_column=models.DidMeta.meta)
            dids += [did for did in q.yield_per(5)]
            dids = set(dids)
            self.assertEqual(list(map(lambda did: did.name in (did_name1, did_name2, did_name3), dids)).count(True), 3)     # 1, 2, 3

            dids = []
            q = FilterEngine('testkeyint1 = 1, testkeystr1 = test; testkeyint1 != 1', model_class=models.DidMeta, strict_coerce=False).create_sqla_query(
                additional_model_attributes=[
                    models.DidMeta.scope,
                    models.DidMeta.name
                ],
                json_column=models.DidMeta.meta)
            dids += [did for did in q.yield_per(5)]
            dids = set(dids)
            self.assertEqual(list(map(lambda did: did.name in (did_name1, did_name2, did_name3), dids)).count(True), 2)     # 2, 3
Пример #14
0
    def test_CompoundInequality(self, session=None):
        # Plugin: DID
        #
        did_name = self._create_tmp_DID()
        set_metadata(scope=self.tmp_scope, name=did_name, key='run_number', value=1)

        dids = []
        q = FilterEngine('0 < run_number < 2', model_class=models.DataIdentifier).create_sqla_query(
            additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(list(map(lambda did: did.name == did_name, dids)).count(True), 1)

        dids = []
        q = FilterEngine('0 < run_number <= 1', model_class=models.DataIdentifier).create_sqla_query(
            additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertEqual(list(map(lambda did: did.name == did_name, dids)).count(True), 1)

        dids = []
        q = FilterEngine('0 <= run_number < 1', model_class=models.DataIdentifier).create_sqla_query(
            additional_model_attributes=[models.DataIdentifier.name])
        dids += [did for did in q.yield_per(5)]
        dids = set(dids)
        self.assertNotEqual(list(map(lambda did: did.name == did_name, dids)).count(True), 1)

        # Plugin: JSON
        #
        if session.bind.dialect.name != 'oracle' and json_implemented(session=session):
            did_name = self._create_tmp_DID()
            set_metadata(scope=self.tmp_scope, name=did_name, key='testkeyint1', value=1)

            dids = []
            q = FilterEngine('0 < testkeyint1 < 2', model_class=models.DidMeta, strict_coerce=False).create_sqla_query(
                additional_model_attributes=[
                    models.DidMeta.scope,
                    models.DidMeta.name
                ],
                json_column=models.DidMeta.meta)
            dids += [did for did in q.yield_per(5)]
            dids = set(dids)
            self.assertEqual(list(map(lambda did: did.name == did_name, dids)).count(True), 1)

            dids = []
            q = FilterEngine('0 < testkeyint1 <= 1', model_class=models.DidMeta, strict_coerce=False).create_sqla_query(
                additional_model_attributes=[
                    models.DidMeta.scope,
                    models.DidMeta.name
                ],
                json_column=models.DidMeta.meta)
            dids += [did for did in q.yield_per(5)]
            dids = set(dids)
            self.assertEqual(list(map(lambda did: did.name == did_name, dids)).count(True), 1)

            dids = []
            q = FilterEngine('0 <= testkeyint1 < 1', model_class=models.DidMeta, strict_coerce=False).create_sqla_query(
                additional_model_attributes=[
                    models.DidMeta.scope,
                    models.DidMeta.name
                ],
                json_column=models.DidMeta.meta)
            dids += [did for did in q.yield_per(5)]
            dids = set(dids)
            self.assertNotEqual(list(map(lambda did: did.name == did_name, dids)).count(True), 1)