Example #1
0
    def get(self, startKey=None):
        '''
        Return activities by pack of LIMIT at JSON format. If a start key
        is given in URL (it means a date like 2010-10-05-12-30-48),
        activities until this date are returned. Else latest activities are
        returned.

        Arguments:
            *startKey* The date until where activities should be returned.
        '''


        if startKey:
            dateString = date_util.get_db_utc_date_from_url_date(startKey)
            docs = ActivityManager.get_all(startKey=dateString, tag="all")
        else:
            docs = ActivityManager.get_all()

        for doc in docs:
            try:
                subdoc = Activity.get_db().get(doc.docId)
                doc.subdoc = subdoc
            except:
                pass

        self.return_documents(docs)
Example #2
0
def clear_all_activities_from_database(step):

    activities = ActivityManager.get_all()
    while activities:
        for activity in activities:
            activity.delete()
        activities = ActivityManager.get_all()
Example #3
0
    def post(self, key):
        '''
        Resend post with *key* as key to the contact given in the posted
        JSON. Corresponding activity ID is given inside the posted json.
        Here is the format : {"contactId":"data","activityId":"data"}
        '''

        micropost = MicroPostManager.get_micropost(key)

        data = self.get_body_as_dict(expectedFields=["contactId",
                                                     "activityId"])

        if micropost and data:

            contactId = data["contactId"]
            activityId = data["activityId"]

            contact = ContactManager.getTrustedContact(contactId)
            activity = ActivityManager.get_activity(activityId)

            if not contact:
                self.return_failure("Contact not found", 404)
            elif not activity:
                self.return_failure("Activity not found", 404)
            else:
                if contact.name:
                    info_str = "Attempt to resend a post to contact: %s."
                    logger.info(info_str % contact.name)
                self.forward_to_contact(micropost, contact, activity)
        else:
            self.return_failure("Micropost not found", 404)
Example #4
0
    def put(self, key):
        '''
        Resend deletion of micropost with *key* as key to the contact given in
        the posted JSON. Corresponding activity ID is given inside the posted
        json.
        Here is the format : {"contactId":"data","activityId":"data"}
        '''

        data = self.get_body_as_dict(
                expectedFields=["contactId", "activityId", "extra"])

        if data:

            contactId = data["contactId"]
            activityId = data["activityId"]
            date = data["extra"]

            contact = ContactManager.getTrustedContact(contactId)
            activity = ActivityManager.get_activity(activityId)

            if not contact:
                self.return_failure("Contact not found", 404)
            elif not activity:
                self.return_failure("Activity not found", 404)
            else:

                user = UserManager.getUser()
                micropost = MicroPost(
                    authorKey=user.key,
                    date=date_util.get_date_from_db_date(date)
                )

                logger.info(
                    "Attempt to resend a post deletion to contact: {}.".format(
                        contact.name))
                httpClient = ContactClient()
                body = micropost.toJson(localized=False)

                try:
                    httpClient.put(contact, CONTACT_PATH, body,
                                   callback=(yield gen.Callback("retry")))
                    response = yield gen.Wait("retry")

                    if response.error:
                        self.return_failure(
                                "Deleting micropost to contact failed.")

                    else:
                        for error in activity.errors:
                            if error["contactKey"] == contact.key:
                                activity.errors.remove(error)
                                activity.save()
                                self.return_success(
                                        "Micropost correctly redeleted.")

                except:
                    self.return_failure("Deleting micropost to contact failed.")

        else:
            self.return_failure("Micropost not found", 404)
Example #5
0
    def put(self, key):
        """
        Resend deletion of micropost with *key* as key to the contact given in
        the posted JSON. Corresponding activity ID is given inside the posted
        json.
        Here is the format : {"contactId":"data","activityId":"data"}
        """
        data = self.get_body_as_dict(expectedFields=["contactId", "activityId", "extra"])

        if data:

            contactId = data["contactId"]
            activityId = data["activityId"]
            date = data["extra"]

            contact = ContactManager.getTrustedContact(contactId)
            activity = ActivityManager.get_activity(activityId)

            if not contact:
                self.return_failure("Contact not found", 404)

            elif not activity:
                self.return_failure("Activity not found", 404)

            else:
                user = UserManager.getUser()
                picture = Picture(authorKey=user.key, date=date_util.get_date_from_db_date(date))

                info = "Attempt to resend a picture deletion to contact: {}."
                logger.info(info.format(contact.name))

                self.forward_to_contact(picture, contact, activity, method="PUT")

        else:
            self.return_failure("Micropost not found", 404)
Example #6
0
    def post(self, key):
        '''
        Resend post with *key* as key to the contact given in the posted
        JSON. Corresponding activity ID is given inside the posted json.
        Here is the format : {"contactId":"data","activityId":"data"}
        '''
        common = CommonManager.get_common(key)
        idInfos = self.request.body

        ids = json_decode(idInfos)

        if common and idInfos:

            contactId = ids["contactId"]
            activityId = ids["activityId"]

            contact = ContactManager.getTrustedContact(contactId)
            activity = ActivityManager.get_activity(activityId)

            if not contact:
                self.return_failure("Contact not found", 404)
            elif not activity:
                self.return_failure("Activity not found", 404)
            else:
                info = "Attemp to resend a common to contact: {}."
                logger.info(info.format(contact.name))
                self.forward_to_contact(common, contact, activity)
        else:
            self.return_failure("Common not found", 404)
Example #7
0
    def post(self, key):
        '''
        Resend post with *key* as key to the contact given in the posted
        JSON. Corresponding activity ID is given inside the posted json.
        Here is the format : {"contactId":"data","activityId":"data"}
        '''
        picture = PictureManager.get_picture(key)
        idInfos = self.request.body

        ids = json_decode(idInfos)

        if picture and idInfos:

            contactId = ids["contactId"]
            activityId = ids["activityId"]

            contact = ContactManager.getTrustedContact(contactId)
            activity = ActivityManager.get_activity(activityId)

            if not contact:
                self.return_failure("Contact not found", 404)
            elif not activity:
                self.return_failure("Activity not found", 404)
            else:
                info = "Attemp to resend a picture to contact: {}."
                logger.info(info.format(contact.name))
                self.forward_to_contact(picture, contact, activity)
        else:
            self.return_failure("Picture not found", 404)
Example #8
0
    def post(self, key):
        '''
        Resend post with *key* as key to the contact given in the posted
        JSON. Corresponding activity ID is given inside the posted json.
        Here is the format : {"contactId":"data","activityId":"data"}
        '''

        micropost = MicroPostManager.get_micropost(key)

        data = self.get_body_as_dict(
            expectedFields=["contactId", "activityId"])

        if micropost and data:

            contactId = data["contactId"]
            activityId = data["activityId"]

            contact = ContactManager.getTrustedContact(contactId)
            activity = ActivityManager.get_activity(activityId)

            if not contact:
                self.return_failure("Contact not found", 404)
            elif not activity:
                self.return_failure("Activity not found", 404)
            else:
                if contact.name:
                    info_str = "Attempt to resend a post to contact: %s."
                    logger.info(info_str % contact.name)
                self.forward_to_contact(micropost, contact, activity)
        else:
            self.return_failure("Micropost not found", 404)
Example #9
0
    def get(self, startKey=None):
        '''
        Return activities by pack of LIMIT at JSON format. If a start key
        is given in URL (it means a date like 2010-10-05-12-30-48),
        activities until this date are returned. Else latest activities are
        returned.

        Arguments:
            *startKey* The date until where activities should be returned.
        '''
        if startKey:
            dateString = date_util.get_db_utc_date_from_url_date(startKey)
            docs = ActivityManager.get_all(startKey=dateString, tag="all")
        else:
            docs = ActivityManager.get_all()

        for doc in docs:
            try:
                subdoc = Activity.get_db().get(doc.docId)
                doc.subdoc = subdoc
            except:
                pass

        self.return_documents(docs)
Example #10
0
    def put(self, key):
        '''
        Resend deletion of micropost with *key* as key to the contact given in
        the posted JSON. Corresponding activity ID is given inside the posted
        json.
        Here is the format : {"contactId":"data","activityId":"data"}
        '''
        data = self.get_body_as_dict(
            expectedFields=["contactId", "activityId", "extra"])

        if data:

            contactId = data["contactId"]
            activityId = data["activityId"]
            date = data["extra"]

            contact = ContactManager.getTrustedContact(contactId)
            activity = ActivityManager.get_activity(activityId)

            if not contact:
                self.return_failure("Contact not found", 404)

            elif not activity:
                self.return_failure("Activity not found", 404)

            else:
                user = UserManager.getUser()
                common = Common(authorKey=user.key,
                                date=date_util.get_date_from_db_date(date))

                info = "Attemp to resend a common deletion to contact: {}."
                logger.info(info.format(contact.name))

                self.forward_to_contact(common,
                                        contact,
                                        activity,
                                        method="PUT")

        else:
            self.return_failure("Micropost not found", 404)
Example #11
0
def checks_that_contact_update_activity_is_properly_created(step):
    activity = ActivityManager.get_all().first()
    assert "modifies" == activity.verb
    assert "profile" == activity.docType
    assert False == activity.isMine
    assert "default contact 2" == activity.author
Example #12
0
def and_activity_has_no_more_errors(step):
    activity = ActivityManager.get_activity(world.activity._id)
    assert 0 == len(activity.errors)
Example #13
0
def and_first_activity_has_no_more_errors(step):
    activity = ActivityManager.get_activity(world.activity._id)
    assert 0 == len(activity.errors)
Example #14
0
def checks_that_deletion_activity_was_created(step):
    activity = ActivityManager.get_mine().first()
    assert activity is not None
    assert activity.verb == "deletes", activity.toDict()
    assert activity.docType == "note"
    assert activity.isMine
Example #15
0
def checks_that_deletion_activity_was_created(step):
    activity = ActivityManager.get_mine().first()
    assert activity is not None
    assert activity.verb == "deletes", activity.toDict()
    assert activity.docType == "note"
    assert activity.isMine
Example #16
0
def retrieve_last_activities(step):
    world.activities = ActivityManager.get_all()
Example #17
0
def retrieve_last_activities_of_owner(step):

    world.activities = ActivityManager.get_mine()
Example #18
0
def retrieve_activities_from_date(step, date):

    world.activities = ActivityManager.get_all(date)
Example #19
0
def retrieve_owner_activities_from_date(step, date):

    world.activities = ActivityManager.get_mine(date)
Example #20
0
def get_activity_with_default_activity_id(step):

    world.new_activity = ActivityManager.get_activity(world.activity._id)
    assert world.new_activity is not None
Example #21
0
    def put(self, key):
        '''
        Resend deletion of micropost with *key* as key to the contact given in
        the posted JSON. Corresponding activity ID is given inside the posted
        json.
        Here is the format : {"contactId":"data","activityId":"data"}
        '''

        data = self.get_body_as_dict(
            expectedFields=["contactId", "activityId", "extra"])

        if data:

            contactId = data["contactId"]
            activityId = data["activityId"]
            date = data["extra"]

            contact = ContactManager.getTrustedContact(contactId)
            activity = ActivityManager.get_activity(activityId)

            if not contact:
                self.return_failure("Contact not found", 404)
            elif not activity:
                self.return_failure("Activity not found", 404)
            else:

                user = UserManager.getUser()
                micropost = MicroPost(
                    authorKey=user.key,
                    date=date_util.get_date_from_db_date(date))

                logger.info(
                    "Attempt to resend a post deletion to contact: {}.".format(
                        contact.name))
                httpClient = ContactClient()
                body = micropost.toJson(localized=False)

                try:
                    httpClient.put(contact,
                                   CONTACT_PATH,
                                   body,
                                   callback=(yield gen.Callback("retry")))
                    response = yield gen.Wait("retry")

                    if response.error:
                        self.return_failure(
                            "Deleting micropost to contact failed.")

                    else:
                        for error in activity.errors:
                            if error["contactKey"] == contact.key:
                                activity.errors.remove(error)
                                activity.save()
                                self.return_success(
                                    "Micropost correctly redeleted.")

                except:
                    self.return_failure(
                        "Deleting micropost to contact failed.")

        else:
            self.return_failure("Micropost not found", 404)
Example #22
0
def checks_that_contact_update_activity_is_properly_created(step):
    activity = ActivityManager.get_all().first()
    assert "modifies" == activity.verb
    assert "profile" == activity.docType
    assert False == activity.isMine
    assert "default contact 2" == activity.author