Ejemplo n.º 1
0
    def test_delete_entry(self):
        register_documents(self._es, self._es._index)

        # delete entry-0
        entry = self.entries[0]
        Entry.objects.get(id=entry.id).delete()

        delete_unnecessary_documents(self._es, self._es._index)
        ret = Entry.search_entries(self.user, [self.entity.id])

        self.assertEqual(ret["ret_count"], 2)
        self.assertFalse(
            any(x["entry"]["id"] == entry.id for x in ret["ret_values"]))
Ejemplo n.º 2
0
    def test_delete_entry(self):
        register_documents(self._es, self._es._index)

        # delete entry-0
        entry = self.entries[0]
        Entry.objects.filter(id=entry.id).delete()

        delete_unnecessary_documents(self._es, self._es._index)
        ret = Entry.search_entries(self.user, [self.entity.id])

        self.assertEqual(ret['ret_count'], 2)
        self.assertFalse(
            any(x['entry']['id'] == entry.id for x in ret['ret_values']))
Ejemplo n.º 3
0
    def test_register_entries(self):
        ret = Entry.search_entries(self.user, [self.entity.id])
        self.assertEqual(ret["ret_count"], 0)
        self.assertEqual(ret["ret_values"], [])

        register_documents(self._es, self._es._index)

        ret = Entry.search_entries(self.user, [self.entity.id])
        self.assertEqual(ret["ret_count"], 3)
        self.assertTrue(
            all([
                x["entity"]["id"] == self.entity.id for x in ret["ret_values"]
            ]))
        self.assertTrue(
            all([
                x["entry"]["id"] in [y.id for y in self.entries]
                for x in ret["ret_values"]
            ]))
Ejemplo n.º 4
0
    def test_register_entries(self):
        ret = Entry.search_entries(self.user, [self.entity.id])
        self.assertEqual(ret['ret_count'], 0)
        self.assertEqual(ret['ret_values'], [])

        register_documents(self._es, self._es._index)

        ret = Entry.search_entries(self.user, [self.entity.id])
        self.assertEqual(ret['ret_count'], 3)
        self.assertTrue(
            all([
                x['entity']['id'] == self.entity.id for x in ret['ret_values']
            ]))
        self.assertTrue(
            all([
                x['entry']['id'] in [y.id for y in self.entries]
                for x in ret['ret_values']
            ]))
Ejemplo n.º 5
0
    def test_update_entry(self):
        register_documents(self._es, self._es._index)

        # update entry-0
        entry = self.entries[0]
        entry.attrs.first().add_value(self.user, 'new-attr-value')
        entry.name = 'new-entry-name'
        entry.save()

        register_documents(self._es, self._es._index)

        ret = Entry.search_entries(self.user, [self.entity.id])
        self.assertEqual(ret['ret_count'], 3)

        entry_info = [
            x for x in ret['ret_values'] if x['entry']['id'] == entry.id
        ][0]
        self.assertEqual(entry_info['entry']['name'], 'new-entry-name')
        self.assertEqual(entry_info['attrs']['attr']['value'],
                         'new-attr-value')
Ejemplo n.º 6
0
    def test_update_entry(self):
        register_documents(self._es, self._es._index)

        # update entry-0
        entry = self.entries[0]
        entry.attrs.first().add_value(self.user, "new-attr-value")
        entry.name = "new-entry-name"
        entry.save()

        register_documents(self._es, self._es._index)

        ret = Entry.search_entries(self.user, [self.entity.id], [{
            "name": "attr"
        }])
        self.assertEqual(ret["ret_count"], 3)

        entry_info = [
            x for x in ret["ret_values"] if x["entry"]["id"] == entry.id
        ][0]
        self.assertEqual(entry_info["entry"]["name"], "new-entry-name")
        self.assertEqual(entry_info["attrs"]["attr"]["value"],
                         "new-attr-value")