Exemplo n.º 1
0
    def test_get_crp_other(self):
        act = Activity.Activity(
            json.dumps({
                'objectType': 'Activity',
                'id': 'foobar12',
                'definition': {
                    'name': {
                        'en-US': 'testname2'
                    },
                    'description': {
                        'en-US': 'testdesc2'
                    },
                    'type': 'cmi.interaction',
                    'interactionType': 'other',
                    'correctResponsesPattern': ['(35.937432,-86.868896)']
                }
            }))

        response = self.client.get(reverse(views.activities),
                                   {'activityId': 'foobar12'},
                                   X_Experience_API_Version="0.95")
        rsp = response.content

        self.assertEqual(response.status_code, 200)
        self.assertIn('foobar12', rsp)
        self.assertIn('cmi.interaction', rsp)
        self.assertIn('other', rsp)
        self.assertIn('(35.937432,-86.868896)', rsp)
        self.assertIn('en-US', rsp)
        self.assertIn('testname2', rsp)
        self.assertIn('testdesc2', rsp)
        self.assertIn('correctResponsesPattern', rsp)
Exemplo n.º 2
0
 def test_get_def(self):
     act = Activity.Activity(
         json.dumps({
             'objectType': 'Activity',
             'id': 'foobar1',
             'definition': {
                 'name': {
                     'en-US': 'testname',
                     'en-GB': 'altname'
                 },
                 'description': {
                     'en-US': 'testdesc',
                     'en-GB': 'altdesc'
                 },
                 'type': 'course',
                 'interactionType': 'intType'
             }
         }))
     response = self.client.get(reverse(views.activities),
                                {'activityId': 'foobar1'},
                                X_Experience_API_Version="0.95")
     rsp = response.content
     self.assertEqual(response.status_code, 200)
     self.assertIn('foobar1', rsp)
     self.assertIn('course', rsp)
     self.assertIn('intType', rsp)
     self.assertIn('en-US', rsp)
     self.assertIn('testname', rsp)
     self.assertIn('testdesc', rsp)
     self.assertIn('en-GB', rsp)
     self.assertIn('altdesc', rsp)
     self.assertIn('altname', rsp)
Exemplo n.º 3
0
    def test_get_crp_long_fill_in(self):
        act = Activity.Activity(
            json.dumps({
                'objectType': 'Activity',
                'id': 'foobar6',
                'definition': {
                    'name': {
                        'en-FR': 'testname2'
                    },
                    'description': {
                        'en-FR': 'testdesc2'
                    },
                    'type': 'cmi.interaction',
                    'interactionType': 'fill-in',
                    'correctResponsesPattern': ['Long fill in answer']
                }
            }))

        response = self.client.get(reverse(views.activities),
                                   {'activityId': 'foobar6'},
                                   X_Experience_API_Version="0.95")

        rsp = response.content
        # pdb.set_trace()
        self.assertEqual(response.status_code, 200)
        self.assertIn('foobar6', rsp)
        self.assertIn('cmi.interaction', rsp)
        self.assertIn('fill-in', rsp)
        self.assertIn('en-FR', rsp)
        self.assertIn('testname2', rsp)
        self.assertIn('testdesc2', rsp)
        self.assertIn('correctResponsesPattern', rsp)
        self.assertIn('Long fill in answer', rsp)
Exemplo n.º 4
0
    def test_cors_put_etag(self):
        pid = 'http://ie.cors.etag/test'
        aid = 'ie.cors.etag/test'

        actaid = Activity.Activity(json.dumps({'objectType':'Activity', 'id': aid}))
        
        params = {"profileId": pid, "activityId": aid}
        path = '%s?%s' % (reverse(views.activity_profile), urllib.urlencode(self.testparams1))
        tp = {"test":"put example profile for test_cors_put_etag","obj":{"activity":"this should be replaced -- ie cors post/put"}}
        put1 = self.client.put(path, tp, content_type=self.content_type, Authorization=self.auth, X_Experience_API_Version="0.95")
        path = '%s?%s' % (reverse(views.activity_profile), urllib.urlencode({"method":"PUT"}))
        
        params['content'] = {"test":"good - trying to put new profile w/ etag header - IE cors","obj":{"activity":"test IE cors etag"}}
        thehash = '"%s"' % hashlib.sha1('%s' % tp).hexdigest()
        params['If-Match'] = thehash
        params['Authorization'] = self.auth
        params['CONTENT_TYPE'] = "application/x-www-form-urlencoded"

        response = self.client.post(path, params, content_type="application/x-www-form-urlencoded", X_Experience_API_Version="0.95")
        
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, 'Success -- activity profile - method = PUT - profileId = %s' % pid)

        r = self.client.get(reverse(views.activity_profile), {'activityId': aid, 'profileId': pid}, X_Experience_API_Version="0.95", Authorization=self.auth)
        self.assertEqual(r.status_code, 200)
        self.assertEqual(r.content, '%s' % params['content'])

        self.client.delete(reverse(views.activity_profile), {'activityId': aid, 'profileId': pid}, Authorization=self.auth, X_Experience_API_Version="0.95")
Exemplo n.º 5
0
    def test_get_crp_performance(self):
        act = Activity.Activity(
            json.dumps({
                'objectType': 'activity',
                'id': 'foobar9',
                'definition': {
                    'name': {
                        'en-US': 'testname2',
                        'en-GB': 'altname'
                    },
                    'description': {
                        'en-US': 'testdesc2'
                    },
                    'type':
                    'cmi.interaction',
                    'interactionType':
                    'performance',
                    'correctResponsesPattern': ['pong.1,dg.10,lunch.4'],
                    'steps': [{
                        'id': 'pong',
                        'description': {
                            'en-US': 'Net pong matches won'
                        }
                    }, {
                        'id': 'dg',
                        'description': {
                            'en-US': 'Strokes over par in disc golf at Liberty'
                        }
                    }, {
                        'id': 'lunch',
                        'description': {
                            'en-US': 'Lunch having been eaten',
                            'en-FR': 'altlunch'
                        }
                    }]
                }
            }))

        response = self.client.get(reverse(views.activities),
                                   {'activityId': 'foobar9'},
                                   X_Experience_API_Version="0.95")
        rsp = response.content
        self.assertEqual(response.status_code, 200)
        self.assertIn('foobar9', rsp)
        self.assertIn('cmi.interaction', rsp)
        self.assertIn('performance', rsp)
        self.assertIn('steps', rsp)
        self.assertIn('en-US', rsp)
        self.assertIn('testname2', rsp)
        self.assertIn('testdesc2', rsp)
        self.assertIn('correctResponsesPattern', rsp)
        self.assertIn('pong.1,dg.10,lunch.4', rsp)
        self.assertIn('Strokes over par in disc golf at Liberty', rsp)
        self.assertIn('Lunch having been eaten', rsp)
        self.assertIn('en-GB', rsp)
        self.assertIn('en-FR', rsp)
        self.assertIn('altlunch', rsp)
Exemplo n.º 6
0
    def test_get_crp_likert(self):
        act = Activity.Activity(
            json.dumps({
                'objectType': 'Still gonna be activity',
                'id': 'foobar7',
                'definition': {
                    'name': {
                        'en-US': 'testname2'
                    },
                    'description': {
                        'en-US': 'testdesc2'
                    },
                    'type':
                    'cmi.interaction',
                    'interactionType':
                    'likert',
                    'correctResponsesPattern': ['likert_3'],
                    'scale': [{
                        'id': 'likert_0',
                        'description': {
                            'en-US': 'Its OK'
                        }
                    }, {
                        'id': 'likert_1',
                        'description': {
                            'en-US': 'Its Pretty Cool'
                        }
                    }, {
                        'id': 'likert_2',
                        'description': {
                            'en-US': 'Its Cool Cool'
                        }
                    }, {
                        'id': 'likert_3',
                        'description': {
                            'en-US': 'Its Gonna Change the World'
                        }
                    }]
                }
            }))

        response = self.client.get(reverse(views.activities),
                                   {'activityId': 'foobar7'},
                                   X_Experience_API_Version="0.95")

        rsp = response.content
        self.assertEqual(response.status_code, 200)
        self.assertIn('foobar7', rsp)
        self.assertIn('cmi.interaction', rsp)
        self.assertIn('likert', rsp)
        self.assertIn('en-US', rsp)
        self.assertIn('testname2', rsp)
        self.assertIn('testdesc2', rsp)
        self.assertIn('correctResponsesPattern', rsp)
        self.assertIn('likert_3', rsp)
        self.assertIn('likert_2', rsp)
        self.assertIn('likert_1', rsp)
Exemplo n.º 7
0
    def test_get_crp_sequencing(self):
        act = Activity.Activity(
            json.dumps({
                'objectType': 'activity',
                'id': 'foobar10',
                'definition': {
                    'name': {
                        'en-US': 'testname2'
                    },
                    'description': {
                        'en-US': 'testdesc2'
                    },
                    'type':
                    'cmi.interaction',
                    'interactionType':
                    'sequencing',
                    'correctResponsesPattern': ['lou,tom,andy,aaron'],
                    'choices': [{
                        'id': 'lou',
                        'description': {
                            'en-US': 'Lou'
                        }
                    }, {
                        'id': 'tom',
                        'description': {
                            'en-US': 'Tom'
                        }
                    }, {
                        'id': 'andy',
                        'description': {
                            'en-US': 'Andy'
                        }
                    }, {
                        'id': 'aaron',
                        'description': {
                            'en-US': 'Aaron'
                        }
                    }]
                }
            }))

        response = self.client.get(reverse(views.activities),
                                   {'activityId': 'foobar10'},
                                   X_Experience_API_Version="0.95")
        rsp = response.content

        self.assertEqual(response.status_code, 200)
        self.assertIn('foobar10', rsp)
        self.assertIn('cmi.interaction', rsp)
        self.assertIn('sequencing', rsp)
        self.assertIn('choices', rsp)
        self.assertIn('en-US', rsp)
        self.assertIn('testname2', rsp)
        self.assertIn('testdesc2', rsp)
        self.assertIn('correctResponsesPattern', rsp)
        self.assertIn('lou,tom,andy,aaron', rsp)
Exemplo n.º 8
0
 def test_cors_put(self):
     profileid = 'http://test.cors.put'
     activityid = 'test_cors_put-activity'
     testparams1 = {"profileId": profileid, "activityId": activityid, "Authorization": self.auth}
     testparams1['content'] = {"test":"put profile 1","obj":{"activity":"test"}}
     path = path = '%s?%s' % (reverse(views.activity_profile), urllib.urlencode({"method":"PUT"}))
     the_act = Activity.Activity(json.dumps({'objectType':'Activity', 'id': activityid}))
     put1 = self.client.post(path, testparams1, content_type="application/x-www-form-urlencoded", X_Experience_API_Version="0.95")
     self.assertEqual(put1.status_code, 200)
     self.assertEqual(put1.content, 'Success -- activity profile - method = PUT - profileId = %s' % testparams1['profileId'])
     self.client.delete(reverse(views.activity_profile), testparams1, Authorization=self.auth, X_Experience_API_Version="0.95")
Exemplo n.º 9
0
    def test_tetris_snafu(self):

        params = {"profileId": "http://test.tetris/", "activityId": "tetris.snafu"}
        path = '%s?%s' % (reverse(views.activity_profile), urllib.urlencode(params))
        profile = {"test":"put profile 1","obj":{"activity":"test"}}
        the_act = Activity.Activity(json.dumps({'objectType':'Activity', 'id': "tetris.snafu"}))
        p_r = self.client.put(path, json.dumps(profile), content_type=self.content_type, Authorization=self.auth, X_Experience_API_Version="0.95")
        self.assertEqual(p_r.status_code, 200)
        r = self.client.get(reverse(views.activity_profile), {'activityId': "tetris.snafu", 'profileId': "http://test.tetris/"}, X_Experience_API_Version="0.95", Authorization=self.auth)
        self.assertEqual(r.status_code, 200)
        self.assertEqual(r['Content-Type'], self.content_type)
        self.assertIn("\"", r.content)        
Exemplo n.º 10
0
 def test_get(self):
     act = Activity.Activity(
         json.dumps({
             'objectType': 'Activity',
             'id': 'foobar'
         }))
     response = self.client.get(reverse(views.activities),
                                {'activityId': 'foobar'},
                                X_Experience_API_Version="0.95")
     rsp = response.content
     self.assertEqual(response.status_code, 200)
     self.assertIn('foobar', rsp)
     self.assertIn('Activity', rsp)
     self.assertIn('objectType', rsp)
Exemplo n.º 11
0
    def setUp(self):
        self.username = "******"
        self.email = "*****@*****.**"
        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.act1 = Activity.Activity(json.dumps({'objectType':'Activity', 'id': self.test_activityId1}))
        self.act2 = Activity.Activity(json.dumps({'objectType':'Activity', 'id': self.test_activityId2}))
        self.act3 = Activity.Activity(json.dumps({'objectType':'Activity', 'id': self.test_activityId3}))
        self.actother = Activity.Activity(json.dumps({'objectType':'Activity', 'id': self.other_activityId}))

        self.testparams1 = {"profileId": self.testprofileId1, "activityId": self.test_activityId1}
        path = '%s?%s' % (reverse(views.activity_profile), urllib.urlencode(self.testparams1))
        self.testprofile1 = {"test":"put profile 1","obj":{"activity":"test"}}
        self.put1 = self.client.put(path, self.testprofile1, content_type=self.content_type, Authorization=self.auth,  X_Experience_API_Version="0.95")
        
        self.testparams2 = {"profileId": self.testprofileId2, "activityId": self.test_activityId2}
        path = '%s?%s' % (reverse(views.activity_profile), urllib.urlencode(self.testparams2))
        self.testprofile2 = {"test":"put profile 2","obj":{"activity":"test"}}
        self.put2 = self.client.put(path, self.testprofile2, content_type=self.content_type, Authorization=self.auth,  X_Experience_API_Version="0.95")

        self.testparams3 = {"profileId": self.testprofileId3, "activityId": self.test_activityId3}
        path = '%s?%s' % (reverse(views.activity_profile), urllib.urlencode(self.testparams3))
        self.testprofile3 = {"test":"put profile 3","obj":{"activity":"test"}}
        self.put3 = self.client.put(path, self.testprofile3, content_type=self.content_type, Authorization=self.auth,  X_Experience_API_Version="0.95")

        self.testparams4 = {"profileId": self.otherprofileId1, "activityId": self.other_activityId}
        path = '%s?%s' % (reverse(views.activity_profile), urllib.urlencode(self.testparams4))
        self.otherprofile1 = {"test":"put profile other","obj":{"activity":"other"}}
        self.put4 = self.client.put(path, self.otherprofile1, content_type=self.content_type, Authorization=self.auth,  X_Experience_API_Version="0.95")

        self.testparams5 = {"profileId": self.otherprofileId1, "activityId": self.test_activityId1}
        path = '%s?%s' % (reverse(views.activity_profile), urllib.urlencode(self.testparams5))
        self.anotherprofile1 = {"test":"put another profile 1","obj":{"activity":"other"}}
        self.put5 = self.client.put(path, self.anotherprofile1, content_type=self.content_type, Authorization=self.auth,  X_Experience_API_Version="0.95")
Exemplo n.º 12
0
    def test_get_crp_numeric(self):
        act = Activity.Activity(
            json.dumps({
                'objectType': 'Activity',
                'id': 'foobar11',
                'definition': {
                    'name': {
                        'en-US': 'testname2'
                    },
                    'description': {
                        'en-US': 'testdesc2'
                    },
                    'type': 'cmi.interaction',
                    'interactionType': 'numeric',
                    'correctResponsesPattern': ['4'],
                    'extensions': {
                        'key1': 'value1',
                        'key2': 'value2',
                        'key3': 'value3'
                    }
                }
            }))

        response = self.client.get(reverse(views.activities),
                                   {'activityId': 'foobar11'},
                                   X_Experience_API_Version="0.95")
        rsp = response.content
        # pdb.set_trace()

        self.assertEqual(response.status_code, 200)
        self.assertIn('foobar11', rsp)
        self.assertIn('cmi.interaction', rsp)
        self.assertIn('numeric', rsp)
        self.assertIn('4', rsp)
        self.assertIn('en-US', rsp)
        self.assertIn('testname2', rsp)
        self.assertIn('testdesc2', rsp)
        self.assertIn('correctResponsesPattern', rsp)
        self.assertIn('extensions', rsp)
        self.assertIn('key1', rsp)
        self.assertIn('value1', rsp)
        self.assertIn('key2', rsp)
        self.assertIn('value2', rsp)
        self.assertIn('key3', rsp)
        self.assertIn('value3', rsp)
Exemplo n.º 13
0
    def test_get_ext(self):
        act = Activity.Activity(
            json.dumps({
                'objectType': 'Activity',
                'id': 'foobar2',
                'definition': {
                    'name': {
                        'en-FR': 'testname2'
                    },
                    'description': {
                        'en-FR': 'testdesc2'
                    },
                    'type': 'course',
                    'interactionType': 'intType2',
                    'extensions': {
                        'key1': 'value1',
                        'key2': 'value2'
                    }
                }
            }))

        response = self.client.get(reverse(views.activities),
                                   {'activityId': 'foobar2'},
                                   X_Experience_API_Version="0.95")
        rsp = response.content
        self.assertEqual(response.status_code, 200)
        self.assertIn('foobar2', rsp)
        self.assertIn('course', rsp)
        self.assertIn('intType2', rsp)
        self.assertIn('en-FR', rsp)
        self.assertIn('testname2', rsp)
        self.assertIn('testdesc2', rsp)
        self.assertIn('key1', rsp)
        self.assertIn('key2', rsp)
        self.assertIn('value1', rsp)
        self.assertIn('value2', rsp)
Exemplo n.º 14
0
    def test_get_crp_multiple_choice(self):
        act = Activity.Activity(
            json.dumps({
                'objectType': 'Activity',
                'id': 'foobar3',
                'definition': {
                    'name': {
                        'en-FR': 'testname2'
                    },
                    'description': {
                        'en-FR': 'testdesc2',
                        'en-CH': 'altdesc'
                    },
                    'type':
                    'cmi.interaction',
                    'interactionType':
                    'choice',
                    'correctResponsesPattern': ['golf', 'tetris'],
                    'choices': [{
                        'id': 'golf',
                        'description': {
                            'en-US': 'Golf Example',
                            'en-GB': 'alt golf'
                        }
                    }, {
                        'id': 'tetris',
                        'description': {
                            'en-US': 'Tetris Example'
                        }
                    }, {
                        'id': 'facebook',
                        'description': {
                            'en-US': 'Facebook App'
                        }
                    }, {
                        'id': 'scrabble',
                        'description': {
                            'en-US': 'Scrabble Example'
                        }
                    }]
                }
            }))

        response = self.client.get(reverse(views.activities),
                                   {'activityId': 'foobar3'},
                                   X_Experience_API_Version="0.95")

        rsp = response.content
        self.assertEqual(response.status_code, 200)
        self.assertIn('foobar3', rsp)
        self.assertIn('cmi.interaction', rsp)
        self.assertIn('choice', rsp)
        self.assertIn('en-FR', rsp)
        self.assertIn('testname2', rsp)
        self.assertIn('testdesc2', rsp)
        self.assertIn('golf', rsp)
        self.assertIn('tetris', rsp)
        self.assertIn('Golf Example', rsp)
        self.assertIn('Tetris Example', rsp)
        self.assertIn('Facebook App', rsp)
        self.assertIn('Scrabble Example', rsp)
        self.assertIn('scrabble', rsp)
        self.assertIn('facebook', rsp)
        self.assertIn('en-GB', rsp)
        self.assertIn('alt golf', rsp)
        self.assertIn('en-CH', rsp)
        self.assertIn('altdesc', rsp)
Exemplo n.º 15
0
    def test_get_crp_matching(self):
        act = Activity.Activity(
            json.dumps({
                'objectType': 'Still gonna be activity',
                'id': 'foobar8',
                'definition': {
                    'name': {
                        'en-US': 'testname2'
                    },
                    'description': {
                        'en-FR': 'testdesc2'
                    },
                    'type':
                    'cmi.interaction',
                    'interactionType':
                    'matching',
                    'correctResponsesPattern': ['lou.3,tom.2,andy.1'],
                    'source': [{
                        'id': 'lou',
                        'description': {
                            'en-US': 'Lou'
                        }
                    }, {
                        'id': 'tom',
                        'description': {
                            'en-US': 'Tom'
                        }
                    }, {
                        'id': 'andy',
                        'description': {
                            'en-US': 'Andy'
                        }
                    }],
                    'target': [{
                        'id': '1',
                        'description': {
                            'en-US': 'SCORM Engine'
                        }
                    }, {
                        'id': '2',
                        'description': {
                            'en-US': 'Pure-sewage'
                        }
                    }, {
                        'id': '3',
                        'description': {
                            'en-US': 'SCORM Cloud'
                        }
                    }]
                }
            }))

        response = self.client.get(reverse(views.activities),
                                   {'activityId': 'foobar8'},
                                   X_Experience_API_Version="0.95")
        rsp = response.content
        self.assertEqual(response.status_code, 200)
        self.assertIn('foobar8', rsp)
        self.assertIn('cmi.interaction', rsp)
        self.assertIn('matching', rsp)
        self.assertIn('en-FR', rsp)
        self.assertIn('en-US', rsp)
        self.assertIn('testname2', rsp)
        self.assertIn('testdesc2', rsp)
        self.assertIn('correctResponsesPattern', rsp)
        self.assertIn('lou.3,tom.2,andy.1', rsp)
        self.assertIn('source', rsp)
        self.assertIn('target', rsp)