Beispiel #1
0
    def test_stack_can_migrate_a_legacy_object_automatically(self):
        """Test the stack can migrate a legacy object automatically for the user"""
        client = BaseAsyncMotorDocument("test_fixture", settings)
        revisions = BaseAsyncMotorDocument("test_fixture_revisions", settings)

        fixture = self.test_fixture

        master_id = yield client.insert(fixture)

        stack = AsyncSchedulableDocumentRevisionStack("test_fixture",
                                                      settings,
                                                      master_id=master_id)

        fixture["baz"] = "bop"
        yield stack.push(self.test_fixture,
                         self.three_min_past_now,
                         meta={
                             "author": "UnitTest",
                             "comment": "Just a test, BRO."
                         })

        fixture["new_persistent"] = True
        yield stack.push(fixture, self.two_min_past_now)

        del fixture["new_persistent"]
        fixture["baz"] = "bit"
        id = yield stack.push(fixture, self.two_min_past_now)

        #response = yield stack.preview(id)
        list = yield revisions.find({"master_id": master_id})
        self.assertEqual(len(list), 4)
Beispiel #2
0
    def post(self, id=None):
        """
        Create a revision manually without the stack

        :param id: BSON id
        :return: JSON
        """
        collection_name = self.request.headers.get("collection")

        if not collection_name:
            self.raise_error(400, "Missing a collection name header")

        self.client = BaseAsyncMotorDocument("%s_revisions" % collection_name)

        super(self.__class__, self).post(id)
Beispiel #3
0
    def delete(self, id):
        """
        Delete a revision by ID

        :param id: BSON id
        :return:
        """

        collection_name = self.request.headers.get("collection")

        if not collection_name:
            self.raise_error(400, "Missing a collection name header")

        self.client = BaseAsyncMotorDocument("%s_revisions" % collection_name)

        super(self.__class__, self).delete(id)
Beispiel #4
0
    def delete(self, bulk_id):
        """Update many objects with a single toa

        :param str bulk_id: The bulk id for the job you want to delete
        """

        collection_name = self.request.headers.get("collection")

        if not collection_name:
            self.raise_error(400, "Missing a collection name header")

        self.revisions = BaseAsyncMotorDocument("%s_revisions" %
                                                collection_name)

        self.logger.info("Deleting revisions with bulk_id %s" % (bulk_id))

        result = yield self.revisions.collection.remove(
            {"meta.bulk_id": bulk_id})

        self.write(result)
Beispiel #5
0
    def setUp(self):
        """Setup the test, runs before each test"""

        self.mini_doc = {"my doc": "little bitty doc"}

        self.test_fixture = {
            "attr1": "attr1_val",
            "date1": time.mktime(datetime.datetime.now().timetuple()),
            "bool_val": True,
            "list_val": ["My Item", "Item 2", 1],
            "loc": [-75.22, 39.25],
            "sub_document": self.mini_doc
        }

        self.client = BaseAsyncMotorDocument("test_collection",
                                             settings=settings)

        BaseAsyncTest.setUp(self)

        # Setup the state of the test
        self.setup_database()
Beispiel #6
0
 def setUp(self):
     super(self.__class__, self).setUp()
     self.collection = BaseAsyncMotorDocument("test_fixture", settings)
     self.stack = AsyncSchedulableDocumentRevisionStack(
         "test_fixture", settings)
     self.setup_database()
Beispiel #7
0
    def get(self, master_id):
        """
        Get a list of revisions by master ID

        :param master_id:
        :return:
        """
        collection_name = self.request.headers.get("collection")
        self.client = BaseAsyncMotorDocument("%s_revisions" % collection_name)

        limit = self.get_query_argument("limit", 2)
        add_current_revision = self.get_arg_value_as_type(
            "addCurrent", "false")
        show_history = self.get_arg_value_as_type("showHistory", "false")

        objects_processed = []

        if isinstance(limit, unicode):
            limit = int(limit)

        objects = yield self.client.find(
            {
                "master_id": master_id,
                "processed": False
            },
            orderby="toa",
            order_by_direction=1,
            page=0,
            limit=20)

        # If this is a document that should have a revision and doesn't we
        # orchestratioin creation of the first one
        if len(objects) == 0:

            new_revision = yield self.__lazy_migration(master_id)
            if not new_revision:
                return

        if show_history:
            objects_processed = yield self.client.find(
                {
                    "master_id": master_id,
                    "processed": True
                },
                orderby="toa",
                order_by_direction=-1,
                page=0,
                limit=limit)

        elif add_current_revision:
            objects_processed = yield self.client.find(
                {
                    "master_id": master_id,
                    "processed": True
                },
                orderby="toa",
                order_by_direction=-1,
                page=0,
                limit=1)

        if len(objects_processed) > 0:
            objects_processed = objects_processed[::-1]
            objects_processed[-1]["current"] = True
            objects = objects_processed + objects

        self.write({"count": len(objects), "results": objects})
Beispiel #8
0
 def initialize(self):
     super(self.__class__, self).initialize()
     self.object_name = "comment"
     self.client = BaseAsyncMotorDocument(self.object_name,
                                          self.settings,
                                          schema=self.SCHEMA)