1818from tincan .context import Context
1919from tincan .context_activities import ContextActivities
2020from tincan .score import Score
21+ from tincan .group import Group
22+ from tincan .base import Base
2123from tincan .result import Result
2224from tincan .substatement import SubStatement
2325from tincan .statement_ref import StatementRef
3335class RemoteLRSTest (unittest .TestCase ):
3436
3537 def setUp (self ):
36- if not hasattr ( self , "set" ):
37- self .endpoint = lrs_properties .endpoint
38- self .version = lrs_properties .version
39- self .username = lrs_properties .username
40- self .password = lrs_properties . password
41- self .lrs = RemoteLRS (
42- version = self .version ,
43- endpoint = self .endpoint ,
44- username = self .username ,
45- password = self . password ,
46- )
47-
48- self .agent = Agent (mbox = "mailto:tincanpython@tincanapi.com" )
49- self .agent2 = Agent ( mbox = "Agent2.mailto:tincanpython@tincanapi.com" )
50- self . verb = Verb (
51- id = "http://adlnet.gov/expapi/verbs/ experienced",
52- display = LanguageMap ({ "en-US" : "experienced" } )
53- )
54-
55- self . activity = Activity (
56- id = "http://tincanapi.com/TinCanPython/Test/Unit/0" ,
57- definition = ActivityDefinition ()
58- )
59- self . activity . definition . type = "http://id.tincanapi.com/activitytype/unit-test"
60- self .activity .definition .name = LanguageMap ({ "en-US" : "Python Tests" })
61- self .activity .definition .description = LanguageMap (
62- { "en-US" : "Unit test in the test suite for the Python library" }
63- )
64-
65- self . parent = Activity (
66- id = "http://tincanapi.com/TinCanPython/Test" ,
67- definition = ActivityDefinition ())
68- self . activity . definition . type = "http://id.tincanapi.com/activitytype/unit-test-suite"
69- self .parent .definition .name = LanguageMap ({ "en-US" : "Python Tests" })
70- self .parent .definition .description = LanguageMap (
71- { "en-US" : "Unit test in the test suite for the Python library" }
72- )
73-
74- self . statement_ref = StatementRef ( id = uuid . uuid4 ())
75-
76- self . context = Context ( registration = uuid . uuid4 (), statement = self . statement_ref )
77- # self.context.context_activities = ContextActivities(parent=[ self.parent] )
78-
79- self . score = Score (
80- raw = 97 ,
81- scaled = 0. 97 ,
82- max = 100 ,
83- min = 0
84- )
85-
86- self . result = Result (
87- score = self .score ,
88- success = True ,
89- completion = True ,
90- duration = "PT120S"
91- )
92-
93- self . substatement = SubStatement (
94- actor = self .agent ,
95- verb = self .verb ,
96- object = self .activity ,
97- )
98- self . set = True
38+ self . endpoint = lrs_properties . endpoint
39+ self .version = lrs_properties .version
40+ self .username = lrs_properties .username
41+ self .password = lrs_properties .password
42+ self .lrs = RemoteLRS (
43+ version = self .version ,
44+ endpoint = self .endpoint ,
45+ username = self .username ,
46+ password = self .password ,
47+ )
48+
49+ self . agent = Agent ( mbox = "mailto:tincanpython@tincanapi.com" )
50+ self .agent2 = Agent (mbox = "Agent2. mailto:tincanpython@tincanapi.com" )
51+ self .verb = Verb (
52+ id = "http://adlnet.gov/expapi/verbs/experienced" ,
53+ display = LanguageMap ({ "en-US" : " experienced"})
54+ )
55+
56+ self . group = Group ( member = [ self . agent , self . agent2 ])
57+
58+ self . activity = Activity (
59+ id = "http://tincanapi.com/TinCanPython/Test/Unit/0" ,
60+ definition = ActivityDefinition ( )
61+ )
62+ self .activity .definition .type = "http://id.tincanapi.com/activitytype/unit-test"
63+ self .activity .definition .name = LanguageMap ({ "en-US" : "Python Tests" })
64+ self . activity . definition . description = LanguageMap (
65+ { "en-US" : "Unit test in the test suite for the Python library" }
66+ )
67+
68+ self . parent = Activity (
69+ id = "http://tincanapi.com/TinCanPython/Test" ,
70+ definition = ActivityDefinition ())
71+ self .activity .definition .type = "http://id.tincanapi.com/activitytype/unit-test-suite"
72+ self .parent .definition .name = LanguageMap ({ "en-US" : "Python Tests" })
73+ self . parent . definition . description = LanguageMap (
74+ { "en-US" : "Unit test in the test suite for the Python library" }
75+ )
76+
77+ self . statement_ref = StatementRef ( id = uuid . uuid4 ())
78+
79+ self .context = Context ( registration = uuid . uuid4 (), statement = self .statement_ref )
80+ #self.context.context_activities = ContextActivities(parent=[self.parent])
81+
82+ self . score = Score (
83+ raw = 97 ,
84+ scaled = 0.97 ,
85+ max = 100 ,
86+ min = 0
87+ )
88+
89+ self .result = Result (
90+ score = self . score ,
91+ success = True ,
92+ completion = True ,
93+ duration = "PT120S"
94+ )
95+
96+ self .substatement = SubStatement (
97+ actor = self .agent ,
98+ verb = self .verb ,
99+ object = self . activity ,
100+ )
99101
100102 def tearDown (self ):
101103 pass
@@ -130,8 +132,8 @@ def test_save_statement(self):
130132
131133 self .assertIsInstance (response , LRSResponse )
132134 self .assertTrue (response .success )
133- self .assertEqual (statement , response .content )
134135 self .assertIsNotNone (response .content .id )
136+ self .shallow_compare (statement , response .content )
135137
136138 def test_save_statement_with_id (self ):
137139 statement = Statement (
@@ -144,21 +146,21 @@ def test_save_statement_with_id(self):
144146
145147 self .assertIsInstance (response , LRSResponse )
146148 self .assertTrue (response .success )
147- self .assertEqual (statement , response .content )
149+ self .shallow_compare (statement , response .content , True )
148150
149151 def test_save_statement_conflict (self ):
150- test_id = str (uuid .uuid4 ())
152+ test_id = unicode (uuid .uuid4 ())
151153
152154 statement1 = Statement (
153155 actor = self .agent ,
154156 verb = self .verb ,
155- object = self .statement_ref ,
157+ object = self .substatement ,
156158 id = test_id
157159 )
158160 statement2 = Statement (
159161 actor = self .agent2 ,
160162 verb = self .verb ,
161- object = self .statement_ref ,
163+ object = self .substatement ,
162164 id = test_id
163165 )
164166 response = self .lrs .save_statement (statement1 )
@@ -183,7 +185,20 @@ def test_save_statement_ref(self):
183185
184186 self .assertIsInstance (response , LRSResponse )
185187 self .assertTrue (response .success )
186- self .assertEqual (statement , response .content )
188+ self .shallow_compare (statement , response .content , True )
189+
190+ def test_save_statement_group (self ):
191+ statement = Statement (
192+ actor = self .agent ,
193+ verb = self .verb ,
194+ object = self .group ,
195+ id = str (uuid .uuid4 ())
196+ )
197+ response = self .lrs .save_statement (statement )
198+
199+ self .assertIsInstance (response , LRSResponse )
200+ self .assertTrue (response .success )
201+ self .shallow_compare (statement , response .content , True )
187202
188203 def test_save_statement_substatement (self ):
189204 statement = Statement (
@@ -196,7 +211,7 @@ def test_save_statement_substatement(self):
196211
197212 self .assertIsInstance (response , LRSResponse )
198213 self .assertTrue (response .success )
199- self .assertEqual (statement , response .content )
214+ self .shallow_compare (statement , response .content , True )
200215
201216 def test_save_statements (self ):
202217 statement1 = Statement (
@@ -216,8 +231,8 @@ def test_save_statements(self):
216231 self .assertTrue (response .success )
217232 self .assertIsNotNone (response .content [0 ].id )
218233 self .assertIsNotNone (response .content [1 ].id )
219- self .assertEquals (statement1 , response .content [0 ])
220- self .assertEquals (statement2 , response .content [1 ])
234+ self .shallow_compare (statement1 , response .content [0 ])
235+ self .shallow_compare (statement2 , response .content [1 ])
221236
222237 def test_retrieve_statement (self ):
223238 statement = Statement (
@@ -230,44 +245,126 @@ def test_retrieve_statement(self):
230245 )
231246 save_resp = self .lrs .save_statement (statement )
232247
233- if (save_resp .success ):
234- response = self .lrs .retrieve_statement (save_resp .content .id )
235- self .assertIsInstance (response , LRSResponse )
236- self .assertTrue (response .success )
237- self .assertEquals (statement , response .content )
238- else :
239- print "test_retrieve_statement: save_statement failed"
248+ self .assertTrue (save_resp .success )
249+
250+ response = self .lrs .retrieve_statement (save_resp .content .id )
251+ self .assertIsInstance (response , LRSResponse )
252+ self .assertTrue (response .success )
253+ self .shallow_compare (statement , response .content )
240254
241255 def test_query_statements (self ):
256+ s1 = Statement (
257+ actor = self .agent ,
258+ verb = self .verb ,
259+ object = self .parent ,
260+ result = self .result ,
261+ id = str (uuid .uuid4 ())
262+ )
263+ self .lrs .save_statement (s1 )
264+
265+ s2 = Statement (
266+ actor = self .agent ,
267+ verb = self .verb ,
268+ object = self .parent ,
269+ result = self .result ,
270+ id = str (uuid .uuid4 ())
271+ )
272+ self .lrs .save_statement (s2 )
273+
274+ s3 = Statement (
275+ actor = self .agent ,
276+ verb = self .verb ,
277+ object = self .parent ,
278+ result = self .result ,
279+ id = str (uuid .uuid4 ())
280+ )
281+ self .lrs .save_statement (s3 )
282+
242283 query = {
243284 "agent" : self .agent ,
244285 "verb" : self .verb ,
245286 "activity" : self .parent ,
246287 "related_activities" : True ,
247288 "related_agents" : True ,
248289 "format" : "ids" ,
249- "limit" : 10
290+ "limit" : 2
250291 }
251292 response = self .lrs .query_statements (query )
252293
253294 self .assertIsInstance (response , LRSResponse )
254295 self .assertTrue (response .success )
255296 self .assertIsInstance (response .content , StatementsResult )
297+ self .assertTrue (hasattr (response .content , 'more' ))
298+ self .assertIsNotNone (response .content .more )
299+ self .shallow_compare (s1 , response .content .statements [0 ])
300+ self .shallow_compare (s2 , response .content .statements [1 ])
301+
302+ def test_query_none (self ):
303+ query = {
304+ "agent" : Agent (mbox = "unique@tincanapi.com" ),
305+ "verb" : self .verb ,
306+ "activity" : self .parent ,
307+ "related_activities" : True ,
308+ "related_agents" : True ,
309+ "format" : "ids" ,
310+ "limit" : 2
311+ }
312+ response = self .lrs .query_statements (query )
313+
314+ self .assertIsInstance (response , LRSResponse )
315+ self .assertTrue (response .success )
316+ self .assertIsInstance (response .content , StatementsResult )
317+ self .assertTrue (hasattr (response .content , 'more' ))
318+ self .assertTrue (hasattr (response .content , 'statements' ))
319+ self .assertEquals (response .content .statements , [])
256320
257321 def test_more_statements (self ):
322+ s1 = Statement (
323+ actor = self .agent ,
324+ verb = self .verb ,
325+ object = self .parent ,
326+ result = self .result ,
327+ id = str (uuid .uuid4 ())
328+ )
329+ self .lrs .save_statement (s1 )
330+
331+ s2 = Statement (
332+ actor = self .agent ,
333+ verb = self .verb ,
334+ object = self .parent ,
335+ result = self .result ,
336+ id = str (uuid .uuid4 ())
337+ )
338+ self .lrs .save_statement (s2 )
339+
340+ s3 = Statement (
341+ actor = self .agent ,
342+ verb = self .verb ,
343+ object = self .parent ,
344+ result = self .result ,
345+ id = str (uuid .uuid4 ())
346+ )
347+ self .lrs .save_statement (s3 )
348+
258349 query = {
350+ "agent" : self .agent ,
351+ "verb" : self .verb ,
352+ "activity" : self .parent ,
353+ "related_activities" : True ,
354+ "related_agents" : True ,
259355 "format" : "ids" ,
260356 "limit" : 2
261357 }
262358 query_resp = self .lrs .query_statements (query )
263359
264- if query_resp .success and query_resp .content .more is not None :
265- response = self .lrs .more_statements (query_resp .content )
266- self .assertIsInstance (response , LRSResponse )
267- self .assertTrue (response .success )
268- self .assertIsInstance (response .content , StatementsResult )
269- else :
270- print "test_more_statements: query_statements failed or did not return a more url"
360+ self .assertIsInstance (query_resp , LRSResponse )
361+ self .assertTrue (query_resp .success )
362+ self .assertIsNotNone (query_resp .content .more )
363+
364+ response = self .lrs .more_statements (query_resp .content )
365+ self .assertIsInstance (response , LRSResponse )
366+ self .assertTrue (response .success )
367+ self .assertIsInstance (response .content , StatementsResult )
271368
272369 def test_retrieve_state_ids (self ):
273370 response = self .lrs .retrieve_state_ids (activity = self .activity , agent = self .agent )
@@ -369,6 +466,15 @@ def test_delete_agent_profile(self):
369466 self .assertIsInstance (response , LRSResponse )
370467 self .assertTrue (response .success )
371468
469+ def shallow_compare (self , s1 , s2 , compare_ids = False ):
470+ for k , v in vars (s1 ).iteritems ():
471+ if not k == '_id' or compare_ids :
472+ self .assertTrue (hasattr (s2 , k ))
473+ if isinstance (v , Base ):
474+ self .shallow_compare (v , getattr (s2 , k ), True )
475+ else :
476+ self .assertEqual (v , getattr (s2 , k ))
477+
372478if __name__ == "__main__" :
373479 suite = unittest .TestLoader ().loadTestsFromTestCase (RemoteLRSTest )
374480 unittest .TextTestRunner (verbosity = 2 ).run (suite )
0 commit comments