Beispiel #1
0
    def setUp(self):
        self.username = "******"
        self.email = "mailto:[email protected]"        
        self.password = "******"
        self.auth = "Basic %s" % base64.b64encode("%s:%s" % (self.username, self.password))
        form = {'username':self.username,'email': self.email,'password':self.password,'password2':self.password}
        response = self.client.post(reverse(views.register),form, X_Experience_API_Version="0.95")

        self.activity = models.activity(activity_id=self.activityId)
        self.activity.save()

        self.activity2 = models.activity(activity_id=self.activityId2)
        self.activity2.save()

        self.testparams1 = {"stateId": self.stateId, "activityId": self.activityId, "agent": self.testagent}
        path = '%s?%s' % (self.url, urllib.urlencode(self.testparams1))
        self.teststate1 = {"test":"put activity state 1","obj":{"agent":"test"}}
        self.put1 = self.client.put(path, self.teststate1, content_type=self.content_type, Authorization=self.auth, X_Experience_API_Version="0.95")

        self.testparams2 = {"stateId": self.stateId2, "activityId": self.activityId, "agent": self.testagent}
        path = '%s?%s' % (self.url, urllib.urlencode(self.testparams2))
        self.teststate2 = {"test":"put activity state 2","obj":{"agent":"test"}}
        self.put2 = self.client.put(path, self.teststate2, content_type=self.content_type, Authorization=self.auth, X_Experience_API_Version="0.95")

        self.testparams3 = {"stateId": self.stateId3, "activityId": self.activityId2, "agent": self.testagent}
        path = '%s?%s' % (self.url, urllib.urlencode(self.testparams3))
        self.teststate3 = {"test":"put activity state 3","obj":{"agent":"test"}}
        self.put3 = self.client.put(path, self.teststate3, content_type=self.content_type, Authorization=self.auth, X_Experience_API_Version="0.95")

        self.testparams4 = {"stateId": self.stateId4, "activityId": self.activityId2, "agent": self.otheragent}
        path = '%s?%s' % (self.url, urllib.urlencode(self.testparams4))
        self.teststate4 = {"test":"put activity state 4","obj":{"agent":"other"}}
        self.put4 = self.client.put(path, self.teststate4, content_type=self.content_type, Authorization=self.auth, X_Experience_API_Version="0.95")
Beispiel #2
0
    def setUp(self):
        self.username = "******"
        self.email = "mailto:[email protected]"        
        self.password = "******"
        self.auth = "Basic %s" % base64.b64encode("%s:%s" % (self.username, self.password))
        form = {'username':self.username,'email': self.email,'password':self.password,'password2':self.password}
        response = self.client.post(reverse(views.register),form, X_Experience_API_Version="0.95")

        self.activity = models.activity(activity_id=self.activityId)
        self.activity.save()

        self.activity2 = models.activity(activity_id=self.activityId2)
        self.activity2.save()

        self.testparams1 = {"stateId": self.stateId, "activityId": self.activityId, "agent": self.testagent}
        path = '%s?%s' % (self.url, urllib.urlencode(self.testparams1))
        self.teststate1 = {"test":"put activity state 1","obj":{"agent":"test"}}
        self.put1 = self.client.put(path, self.teststate1, content_type=self.content_type, Authorization=self.auth, X_Experience_API_Version="0.95")

        self.testparams2 = {"stateId": self.stateId2, "activityId": self.activityId, "agent": self.testagent}
        path = '%s?%s' % (self.url, urllib.urlencode(self.testparams2))
        self.teststate2 = {"test":"put activity state 2","obj":{"agent":"test"}}
        self.put2 = self.client.put(path, self.teststate2, content_type=self.content_type, Authorization=self.auth, X_Experience_API_Version="0.95")

        self.testparams3 = {"stateId": self.stateId3, "activityId": self.activityId2, "agent": self.testagent}
        path = '%s?%s' % (self.url, urllib.urlencode(self.testparams3))
        self.teststate3 = {"test":"put activity state 3","obj":{"agent":"test"}}
        self.put3 = self.client.put(path, self.teststate3, content_type=self.content_type, Authorization=self.auth, X_Experience_API_Version="0.95")

        self.testparams4 = {"stateId": self.stateId4, "activityId": self.activityId2, "agent": self.otheragent}
        path = '%s?%s' % (self.url, urllib.urlencode(self.testparams4))
        self.teststate4 = {"test":"put activity state 4","obj":{"agent":"other"}}
        self.put4 = self.client.put(path, self.teststate4, content_type=self.content_type, Authorization=self.auth, X_Experience_API_Version="0.95")
Beispiel #3
0
    def _save_actvity_to_db(self, act_id, objType, act_def=None):
        if act_def:
            if self.auth is not None:
                act = models.activity(activity_id=act_id, objectType=objType, activity_definition=act_def, authoritative=self.auth)
            else:
                act = models.activity(activity_id=act_id, objectType=objType, activity_definition=act_def)
        else:
            if self.auth is not None:
                act = models.activity(activity_id=act_id, objectType=objType, authoritative=self.auth)
            else:
                act = models.activity(activity_id=act_id, objectType=objType)

        act.save()
        return act
Beispiel #4
0
    def __populate(self, the_object):
        #Must include activity_id, default objectType is Activity - set object's activity_id and objectType
        try:
            self.activity_id = the_object['activity_id']
        except KeyError:
            raise Exception("No activity_id provided, must provide activity_id")
        try:
            self.objectType = the_object['objectType']
        except KeyError:
            self.objectType = 'Activity'
        
        #Save activity to DB
        the_act = models.activity(activity_id=self.activity_id, objectType=self.objectType)
        the_act.save()

        '''
        ot = models.activity.objects.get(activity_id=self.activity_id).objectType
        ai = models.activity.objects.get(activity_id=self.activity_id).activity_id
        aid = models.activity.objects.get(activity_id=self.activity_id).id
        print 'act_objType ' + str(ot)
        print 'act_act_id ' + str(ai)
        print 'act_id ' + str(aid)
        '''

        #See if activity has definition included
        try:   
            the_act_def = the_object['definition']
        except KeyError:
            the_act_def = None        
        
        #If definition is included, populate the activity definition
        if the_act_def:
            self.__populate_definition(the_act, the_act_def, the_object)
Beispiel #5
0
    def populate(self, the_object):        
        #Must include activity_id - set object's activity_id
        try:
            activity_id = the_object['id']
            if not uri.validate_uri(activity_id):
                raise exceptions.ParamError('Activity ID %s is not a valid URI' % activity_id)
        except KeyError:
            err_msg = "No id provided, must provide 'id' field"
            log_message(self.log_dict, err_msg, __name__, self.populate.__name__, True) 
            update_parent_log_status(self.log_dict, 400)          
            raise exceptions.ParamError(err_msg)

        # If allowed to define activities-create or get the global version
        if self.define:
            self.activity, act_created = models.activity.objects.get_or_create(activity_id=activity_id,
                global_representation=True)
        else:
            # Not allowed to create global version b/c don't have define permissions
            self.activity = models.activity(activity_id=activity_id, global_representation=False)
            self.activity.save()
            act_created = False
        if act_created: 
            log_message(self.log_dict, "Populating Activity - created Activity in database", __name__, self.populate.__name__)            
            if self.auth:
                self.activity.authoritative = self.auth
                self.activity.save()
        else:
            log_message(self.log_dict, "Populating Activity - retrieved Activity from database", __name__, self.populate.__name__)            

        valid_schema = False
        xml_data = {}
        
        #Try to grab XML from ID if no other JSON is provided - since it won't have a definition it's not a link
        #therefore it can be allowed to not resolve and will just return an empty dictionary
        if not 'definition' in the_object.keys():
            xml_data = self.validateID(activity_id)

            #If the ID validated against the XML schema then proceed with populating the definition with the info
            #from the XML - else just save the activity (someone sent in an ID that doesn't resolve and an objectType
            #with no other data)                
            if xml_data:
                self.populate_definition(xml_data, act_created)
        
        #Definition is provided
        else:
            self.validate_definition(the_object, act_created)