示例#1
0
文件: steps.py 项目: rakoo/newebe
def clear_all_activities_from_database(step):

    activities = ActivityManager.get_all()
    while activities:
        for activity in activities:
            activity.delete()
        activities = ActivityManager.get_all()
示例#2
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:
                    logger.info("Attempt to resend a post to contact: %s." % contact.name)
                self.forward_to_contact(micropost, contact, activity)
        else:
            self.return_failure("Micropost not found", 404)
示例#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"}
        '''

        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:           
                logger.info("Attemp to resend a picture to contact: {}.".format(
                    contact.name))
                self.forward_to_contact(picture, contact, activity)
        else:
            self.return_failure("Picture not found", 404)
示例#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()
                picture = Picture(
                    authorKey = user.key, 
                    date = date_util.get_date_from_db_date(date)
                )
                
                logger.info(
                    "Attemp to resend a picture deletion to contact: {}.".format(
                        contact.name))

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

        else:
            self.return_failure("Micropost not found", 404)
示例#5
0
文件: steps.py 项目: rakoo/newebe
def retrieve_last_activities(step):
    world.activities = ActivityManager.get_all()
示例#6
0
文件: steps.py 项目: rakoo/newebe
def get_activity_with_default_activity_id(step):

    world.new_activity = ActivityManager.get_activity(world.activity._id)
    assert world.new_activity is not None
示例#7
0
文件: steps.py 项目: rakoo/newebe
def retrieve_owner_activities_from_date(step, date):

    world.activities = ActivityManager.get_mine(date)
示例#8
0
文件: steps.py 项目: rakoo/newebe
def retrieve_activities_from_date(step, date):

    world.activities = ActivityManager.get_all(date)
示例#9
0
文件: steps.py 项目: rakoo/newebe
def retrieve_last_activities_of_owner(step):

    world.activities = ActivityManager.get_mine()
示例#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()
                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)
示例#11
0
def and_first_activity_has_no_more_errors(step):
    activity = ActivityManager.get_activity(world.activity._id)
    assert 0 == len(activity.errors)
示例#12
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
示例#13
0
文件: steps.py 项目: rakoo/newebe
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