Example #1
0
    def test_add_and_search_client(self):
        count = 0
        clientids = []
        while (count < 20):
            client_doc = copy.deepcopy(self.fake_client_doc)
            clientid = common.get_fake_client_id()
            client_doc['client_id'] = clientid
            client_id = self.dbapi.add_client(user_id=self.fake_user_id,
                                              doc=client_doc)
            self.assertIsNotNone(client_id)
            self.assertEqual(clientid, client_id)
            clientids.append(client_id)
            count += 1

        result = self.dbapi.get_client(user_id=self.fake_user_id,
                                       limit=10,
                                       offset=0)

        self.assertIsNotNone(result)
        self.assertEqual(len(result), 10)

        for index in range(len(result)):
            clientmap = result[index]
            clientid = clientmap['client'].get('client_id')
            self.assertEqual(clientids[index], clientid)
Example #2
0
    def test_add_and_search_client_with_all_opt_one_match(self):
        count = 0
        clientids = []
        while (count < 20):
            client_doc = copy.deepcopy(self.fake_client_doc)
            clientid = common.get_fake_client_id()
            client_doc['client_id'] = clientid
            client_doc['hostname'] = "node1"
            if count in [0, 4, 8, 12, 16]:
                client_doc['description'] = "tecs"

            client_id = self.dbapi.add_client(user_id=self.fake_user_id,
                                              doc=client_doc)
            self.assertIsNotNone(client_id)
            self.assertEqual(clientid, client_id)
            clientids.append(client_id)
            count += 1

        search_opt = {'match': [{'_all': '[{"description": "tecs"}]'}]}

        result = self.dbapi.get_client(user_id=self.fake_user_id,
                                       limit=20,
                                       offset=0,
                                       search=search_opt)

        self.assertIsNotNone(result)
        self.assertEqual(len(result), 5)

        for index in range(len(result)):
            clientmap = result[index]
            description = clientmap['client'].get('description')
            self.assertEqual('tecs', description)
Example #3
0
    def test_add_and_search_client_with_error_all_opt_return_alltuples(self):
        count = 0
        clientids = []
        while (count < 20):
            client_doc = copy.deepcopy(self.fake_client_doc)
            clientid = common.get_fake_client_id()
            client_doc['client_id'] = clientid
            client_doc['hostname'] = "node1"
            if count in [0, 4, 8, 12, 16]:
                client_doc['hostname'] = "node2"

            client_id = self.dbapi.add_client(user_id=self.fake_user_id,
                                              doc=client_doc)
            self.assertIsNotNone(client_id)
            self.assertEqual(clientid, client_id)
            clientids.append(client_id)
            count += 1

        search_opt = {'match': [{'_all': '{"hostname": "node2"}'}]}
        result = self.dbapi.get_client(user_id=self.fake_user_id,
                                       limit=20,
                                       offset=0,
                                       search=search_opt)

        self.assertIsNotNone(result)
        self.assertEqual(len(result), 20)

        search_opt = {'match': [{'_all': 'hostname=node2'}]}
        result = self.dbapi.get_client(user_id=self.fake_user_id,
                                       limit=20,
                                       offset=0,
                                       search=search_opt)

        self.assertIsNotNone(result)
        self.assertEqual(len(result), 20)
Example #4
0
    def test_add_and_search_client_with_search_match_and_match_not(self):
        count = 0
        clientids = []
        while (count < 20):
            client_doc = copy.deepcopy(self.fake_client_doc)
            clientid = common.get_fake_client_id()
            client_doc['client_id'] = clientid
            client_doc['hostname'] = "node1"
            if count in [0, 4, 8, 12, 16]:
                client_doc['description'] = "tecs"
                if count in [4, 12]:
                    client_doc['hostname'] = 'node2'

            client_id = self.dbapi.add_client(user_id=self.fake_user_id,
                                              doc=client_doc,
                                              project_id=self.fake_project_id)
            self.assertIsNotNone(client_id)
            self.assertEqual(clientid, client_id)
            clientids.append(client_id)
            count += 1

        search_opt = {
            'match_not': [{
                'hostname': 'node2'
            }],
            'match': [{
                'description': 'tecs'
            }]
        }

        result = self.dbapi.get_client(project_id=self.fake_project_id,
                                       user_id=self.fake_user_id,
                                       limit=20,
                                       offset=0,
                                       search=search_opt)

        self.assertIsNotNone(result)
        self.assertEqual(len(result), 3)

        for index in range(len(result)):
            clientmap = result[index]
            hostname = clientmap['client'].get('hostname')
            description = clientmap['client'].get('description')
            self.assertEqual('node1', hostname)
            self.assertEqual('tecs', description)