Esempio n. 1
0
    def setUp(self):

        self.database_name = 'testcase_transaction_123'
        self.db = Database.create(name=self.database_name)

        self.operating_collection = 'foo_test'
        self.test_1_col = Collection.create(name=self.operating_collection)
Esempio n. 2
0
    def setUp(self):

        self.database_name = 'testcase_transaction_123'
        self.db = Database.create(name=self.database_name)

        self.operating_collection = 'foo_test'
        self.test_1_col = Collection.create(name=self.operating_collection)
Esempio n. 3
0
    def setUp(self):

        self.database_name = 'testcase_index_222_123'
        self.db = Database.create(name=self.database_name)

        self.operating_collection = 'bar_extra'
        self.test_1_col = Collection.create(name=self.operating_collection)
Esempio n. 4
0
    def init(cls):
        """
        """

        name = cls.get_collection_name()

        # Set type
        try:
            collection_type = getattr(cls, 'collection_type')
        except:
            collection_type = 2

        # Create collection
        try:
            cls.collection_instance = Collection.create(name=name, type=collection_type)
        except:
            cls.collection_instance = Collection.get_loaded_collection(name=name)

        try:
            if not isinstance(cls.objects, CollectionModelManager):
                cls.objects = cls.objects(cls)
        except:
            pass # This is the case if init was called more than once

        # Create meta data for collection
        cls._model_meta_data = cls.MetaDataObj()

        # Go through all fields
        for attribute in cls.get_collection_fields():
            attribute.on_init(cls)
Esempio n. 5
0
    def setUp(self):

        self.database_name = 'testcase_index_222_123'
        self.db = Database.create(name=self.database_name)

        self.operating_collection = 'bar_extra'
        self.test_1_col = Collection.create(name=self.operating_collection)
Esempio n. 6
0
    def test_create_and_delete_collection_without_extra_db(self):

        collection_name = 'test_foo_123'

        col = Collection.create(name=collection_name)

        self.assertIsNotNone(col)

        Collection.remove(name=collection_name)
Esempio n. 7
0
    def test_create_and_delete_collection_without_extra_db(self):

        collection_name = 'test_foo_123'

        col = Collection.create(name=collection_name)

        self.assertIsNotNone(col)

        Collection.remove(name=collection_name)
Esempio n. 8
0
    def init(cls):
        """
        """

        # TODO: Deal with super classes

        name = cls.get_collection_name()

        # Set type
        try:
            collection_type = getattr(cls, 'collection_type')
        except:
            collection_type = 2

        # TODO: Database is not set for the collection

        # Create collection
        try:
            cls.collection_instance = Collection.create(name=name, type=collection_type)
        except:
            cls.collection_instance = Collection.get_loaded_collection(name=name)

        try:
            if not isinstance(cls.objects, CollectionModelManager):
                cls.objects = cls.objects(cls)
        except:
            pass # This is the case if init was called more than once

        # Create meta data for collection
        cls._model_meta_data = cls.MetaDataObj()

        # Go through all fields
        fields_dict = cls.get_collection_fields_dict()
        for attribute_name in fields_dict:
            attribute = fields_dict[attribute_name]
            # Trigger init event
            attribute.on_init(cls, attribute_name)

        # Go through all index
        model_index_list = cls.get_model_fields_index()
        for index_attribute_name in model_index_list:
            # Save created index
            index_obj = model_index_list[index_attribute_name]
            created_index = Index(collection=cls.collection_instance, index_type_obj=index_obj)
            # Reset class attribute
            setattr(cls, index_attribute_name, created_index)
            # Save index
            created_index.save()

            if not created_index.index_type_obj.is_new:
                created_index.overwrite()
Esempio n. 9
0
    def init(cls):
        """
        """

        name = cls.get_collection_name()

        # Set type
        try:
            collection_type = getattr(cls, 'collection_type')
        except:
            collection_type = 2

        # TODO: Database is not set for the collection

        # Create collection
        try:
            cls.collection_instance = Collection.create(name=name,
                                                        type=collection_type)
        except:
            cls.collection_instance = Collection.get_loaded_collection(
                name=name)

        try:
            if not isinstance(cls.objects, CollectionModelManager):
                cls.objects = cls.objects(cls)
        except:
            pass  # This is the case if init was called more than once

        # Create meta data for collection
        cls._model_meta_data = cls.MetaDataObj()

        # Go through all fields
        for attribute in cls.get_collection_fields():
            # Trigger init event
            attribute.on_init(cls)

        # Go through all index
        model_index_list = cls.get_model_fields_index()
        for index_attribute_name in model_index_list:
            # Save created index
            index_obj = model_index_list[index_attribute_name]
            created_index = Index(collection=cls.collection_instance,
                                  index_type_obj=index_obj)
            # Reset class attribute
            setattr(cls, index_attribute_name, created_index)
            # Save index
            created_index.save()

            if not created_index.index_type_obj.is_new:
                created_index.overwrite()
Esempio n. 10
0
    def on_init(self, model_class):
        """
        """

        if not self.related_name is None:
            relation_name = self._get_relation_collection_name(model_class)

            try:
                self.relation_collection = Collection.create(name=relation_name, database=Client.instance().database, type=3)
            except:
                self.relation_collection = Collection.get_loaded_collection(name=relation_name)

            fields = self.relation_class._model_meta_data._fields
            fields[self.related_name] = ManyToManyField(to=model_class, related_name=None)
Esempio n. 11
0
    def test_get_collection(self):

        collection_name = 'test_foo_123'

        col = Collection.create(name=collection_name)

        self.assertIsNotNone(col)

        retrieved_col = Collection.get_loaded_collection(name=collection_name)

        self.assertEqual(col.id, retrieved_col.id)
        self.assertEqual(col.name, retrieved_col.name)
        self.assertEqual(col.type, retrieved_col.type)

        Collection.remove(name=collection_name)
Esempio n. 12
0
    def test_getting_new_info_for_collection(self):

        collection_name = 'test_foo_123'

        col = Collection.create(name=collection_name)

        retrieved_col = Collection.get_loaded_collection(name=collection_name)
        retrieved_col.set_data(waitForSync=True)
        retrieved_col.save()

        col.get()

        self.assertEqual(col.waitForSync, True)

        Collection.remove(name=collection_name)
Esempio n. 13
0
    def test_get_collection(self):

        collection_name = 'test_foo_123'

        col = Collection.create(name=collection_name)

        self.assertIsNotNone(col)

        retrieved_col = Collection.get_loaded_collection(name=collection_name)

        self.assertEqual(col.id, retrieved_col.id)
        self.assertEqual(col.name, retrieved_col.name)
        self.assertEqual(col.type, retrieved_col.type)

        Collection.remove(name=collection_name)
Esempio n. 14
0
    def test_getting_new_info_for_collection(self):

        collection_name = 'test_foo_123'

        col = Collection.create(name=collection_name)

        retrieved_col = Collection.get_loaded_collection(name=collection_name)
        retrieved_col.set_data(waitForSync=True)
        retrieved_col.save()

        col.get()

        self.assertEqual(col.waitForSync, True)

        Collection.remove(name=collection_name)
Esempio n. 15
0
    def test_remove_document_from_collection(self):

        collection_name = 'test_remove_document_from_collection'

        col = Collection.create(name=collection_name)
        doc1 = col.create_document()
        doc1.save()

        all_documents = col.documents()
        self.assertEqual(len(all_documents), 1)
        doc = all_documents[0]

        doc.delete()

        all_documents = col.documents()
        self.assertEqual(len(all_documents), 0)

        Collection.remove(name=collection_name)
Esempio n. 16
0
    def test_different_document_revisions(self):

        collection_name = 'test_revision_documents'

        col = Collection.create(name=collection_name)
        doc1 = col.create_document()
        doc1.save()

        all_documents = col.documents()
        self.assertEqual(len(all_documents), 1)
        doc = all_documents[0]

        self.assertEqual(doc.revision, doc1.revision)

        doc.foo = 'bar'
        doc.save()

        self.assertNotEqual(doc.revision, doc1.revision)

        Collection.remove(name=collection_name)
Esempio n. 17
0
    def on_init(self, model_class):
        """
        """

        if not self.related_name is None:
            relation_name = self._get_relation_collection_name(model_class)

            try:
                self.relation_collection = Collection.create(name=relation_name, database=Client.instance().database, type=3)
            except:
                self.relation_collection = Collection.get_loaded_collection(name=relation_name)

            fields = self.relation_class._model_meta_data._fields
            otherside_field = ManyToManyField(to=model_class, related_name=None)
            fields[self.related_name] = otherside_field

            # Configure other side field
            otherside_field.related_queryset = self.relation_class.objects.all()
            otherside_field.relation_collection = self.relation_collection

            self.related_queryset = self.relation_class.objects.all()
Esempio n. 18
0
    def init(cls):
        """
        """

        # TODO: Deal with super classes

        name = cls.get_collection_name()

        # Set type
        try:
            collection_type = getattr(cls, 'collection_type')
        except:
            collection_type = 2

        # TODO: Database is not set for the collection

        # Create collection
        try:
            cls.collection_instance = Collection.create(name=name,
                                                        type=collection_type)
        except:
            cls.collection_instance = Collection.get_loaded_collection(
                name=name)

        try:
            if not isinstance(cls.objects, CollectionModelManager):
                cls.objects = cls.objects(cls)
        except:
            pass  # This is the case if init was called more than once

        cls._default_manager = cls.objects

        # Create meta data for collection
        cls._model_meta_data = cls.MetaDataObj()

        if hasattr(cls, 'Meta'):
            cls._meta = cls.Meta()
            cls._meta.model_name = name
            cls._meta.object_name = name

            # Giving other classes the chance to extend the meta data on init
            if hasattr(cls, 'extend_meta_data'):
                cls.extend_meta_data(cls, cls._meta)

        # Go through all fields
        fields_dict = cls.get_collection_fields_dict()
        for attribute_name in fields_dict:
            attribute = fields_dict[attribute_name]
            # Trigger init event
            attribute.on_init(cls, attribute_name)

        # Go through all index
        model_index_list = cls.get_model_fields_index()
        for index_attribute_name in model_index_list:
            # Save created index
            index_obj = model_index_list[index_attribute_name]
            created_index = Index(collection=cls.collection_instance,
                                  index_type_obj=index_obj)
            # Reset class attribute
            setattr(cls, index_attribute_name, created_index)
            # Save index
            created_index.save()

            if not created_index.index_type_obj.is_new:
                created_index.overwrite()
Esempio n. 19
0
    SimpleQuery.all(collection=big_collection)

@timer_decorator2('Retrieving %s documents via aql from the collection took %s seconds')
def retrieve_aql_documents(big_collection):
    """
    """

    all_aql_query = Query()
    all_aql_query.append_collection(collection_name=big_collection.name)
    all_aql_query.execute()

# Everything needs to be in one try-catch so we can clean up afterwards
try:

    big_collection_name = 'big_collection'
    big_collection = Collection.create(big_collection_name)

    print('All tests are using either %s documents, edges or models' % document_number)

    # Create first all documents
    create_big_number_of_documents(big_collection)

    # Get all documents normally
    retrieve_normally_documents(big_collection)

    # Get documents with simple query
    retrieve_simply_documents(big_collection)

    # Get documents with aql
    retrieve_aql_documents(big_collection)