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_list_did_meta(self):
        """ DID Meta (Hardcoded): List did meta """
        dsns = []
        tmp_dsn1 = 'dsn_%s' % generate_uuid()

        dsns.append(tmp_dsn1)

        dataset_meta = {'project': 'data12_8TeV',
                        'run_number': 400000,
                        'stream_name': 'physics_CosmicCalo',
                        'prod_step': 'merge',
                        'datatype': 'NTUP_TRIG',
                        'version': 'f392_m920',
                        }

        add_did(scope=self.tmp_scope, name=tmp_dsn1, type="DATASET", account=self.root, meta=dataset_meta)

        tmp_dsn2 = 'dsn_%s' % generate_uuid()
        dsns.append(tmp_dsn2)
        dataset_meta['run_number'] = 400001
        add_did(scope=self.tmp_scope, name=tmp_dsn2, type="DATASET", account=self.root, meta=dataset_meta)

        tmp_dsn3 = 'dsn_%s' % generate_uuid()
        dsns.append(tmp_dsn3)
        dataset_meta['stream_name'] = 'physics_Egamma'
        dataset_meta['datatype'] = 'NTUP_SMWZ'
        add_did(scope=self.tmp_scope, name=tmp_dsn3, type="DATASET", account=self.root, meta=dataset_meta)

        dids = list_dids(self.tmp_scope, {'project': 'data12_8TeV', 'version': 'f392_m920'})
        results = []
        for d in dids:
            results.append(d)
        for dsn in dsns:
            assert dsn in results
        dsns.remove(tmp_dsn1)

        dids = list_dids(self.tmp_scope, {'project': 'data12_8TeV', 'run_number': 400001})
        results = []
        for d in dids:
            results.append(d)
        for dsn in dsns:
            assert dsn in results
        dsns.remove(tmp_dsn2)

        dids = list_dids(self.tmp_scope, {'project': 'data12_8TeV', 'stream_name': 'physics_Egamma', 'datatype': 'NTUP_SMWZ'})
        results = []
        for d in dids:
            results.append(d)
        for dsn in dsns:
            assert dsn in results
Example #3
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)