|
2 | 2 |
|
3 | 3 | import uuid |
4 | 4 |
|
5 | | -from resources import lrs_properties |
| 5 | +from test.resources import lrs_properties |
6 | 6 | from tincan import ( |
7 | 7 | RemoteLRS, |
8 | 8 | Statement, |
|
17 | 17 |
|
18 | 18 |
|
19 | 19 | # construct an LRS |
20 | | -print "constructing the LRS..." |
| 20 | +print("constructing the LRS...") |
21 | 21 | lrs = RemoteLRS( |
22 | 22 | version=lrs_properties.version, |
23 | 23 | endpoint=lrs_properties.endpoint, |
24 | 24 | username=lrs_properties.username, |
25 | 25 | password=lrs_properties.password, |
26 | 26 | ) |
27 | | -print "...done" |
| 27 | +print("...done") |
28 | 28 |
|
29 | 29 | # construct the actor of the statement |
30 | | -print "constructing the Actor..." |
| 30 | +print("constructing the Actor...") |
31 | 31 | actor = Agent( |
32 | 32 | name='UserMan', |
33 | 33 | mbox='mailto:tincanpython@tincanapi.com', |
34 | 34 | ) |
35 | | -print "...done" |
| 35 | +print("...done") |
36 | 36 |
|
37 | 37 | # construct the verb of the statement |
38 | | -print "constructing the Verb..." |
| 38 | +print("constructing the Verb...") |
39 | 39 | verb = Verb( |
40 | 40 | id='http://adlnet.gov/expapi/verbs/experienced', |
41 | 41 | display=LanguageMap({'en-US': 'experienced'}), |
42 | 42 | ) |
43 | | -print "...done" |
| 43 | +print("...done") |
44 | 44 |
|
45 | 45 | # construct the object of the statement |
46 | | -print "constructing the Object..." |
| 46 | +print("constructing the Object...") |
47 | 47 | object = Activity( |
48 | 48 | id='http://tincanapi.com/TinCanPython/Example/0', |
49 | 49 | definition=ActivityDefinition( |
50 | 50 | name=LanguageMap({'en-US': 'TinCanPython Library'}), |
51 | 51 | description=LanguageMap({'en-US': 'Use of, or interaction with, the TinCanPython Library'}), |
52 | 52 | ), |
53 | 53 | ) |
54 | | -print "...done" |
| 54 | +print("...done") |
55 | 55 |
|
56 | 56 | # construct a context for the statement |
57 | | -print "constructing the Context..." |
| 57 | +print("constructing the Context...") |
58 | 58 | context = Context( |
59 | 59 | registration=uuid.uuid4(), |
60 | 60 | instructor=Agent( |
|
63 | 63 | ), |
64 | 64 | # language='en-US', |
65 | 65 | ) |
66 | | -print "...done" |
| 66 | +print("...done") |
67 | 67 |
|
68 | 68 | # construct the actual statement |
69 | | -print "constructing the Statement..." |
| 69 | +print("constructing the Statement...") |
70 | 70 | statement = Statement( |
71 | 71 | actor=actor, |
72 | 72 | verb=verb, |
73 | 73 | object=object, |
74 | 74 | context=context, |
75 | 75 | ) |
76 | | -print "...done" |
| 76 | +print("...done") |
77 | 77 |
|
78 | 78 | # save our statement to the remote_lrs and store the response in 'response' |
79 | | -print "saving the Statement..." |
| 79 | +print("saving the Statement...") |
80 | 80 | response = lrs.save_statement(statement) |
81 | 81 |
|
82 | 82 | if not response: |
83 | 83 | raise ValueError("statement failed to save") |
84 | | -print "...done" |
| 84 | +print("...done") |
85 | 85 |
|
86 | 86 | # retrieve our statement from the remote_lrs using the id returned in the response |
87 | | -print "Now, retrieving statement..." |
| 87 | +print("Now, retrieving statement...") |
88 | 88 | response = lrs.retrieve_statement(response.content.id) |
89 | 89 |
|
90 | 90 | if not response.success: |
91 | 91 | raise ValueError("statement could not be retrieved") |
92 | | -print "...done" |
| 92 | +print("...done") |
93 | 93 |
|
94 | | -print "constructing new Statement from retrieved statement data..." |
| 94 | +print("constructing new Statement from retrieved statement data...") |
95 | 95 | ret_statement = response.content |
96 | | -print "...done" |
| 96 | +print("...done") |
97 | 97 |
|
98 | 98 | # now, using our old statement and our returned statement, we can send multiple statements |
99 | 99 | # note: these statements are logically identical, but are 2 separate objects |
100 | | -print "saving both Statements" |
| 100 | +print("saving both Statements") |
101 | 101 | response = lrs.save_statements([statement, ret_statement]) |
102 | 102 |
|
103 | 103 | if not response: |
104 | 104 | raise ValueError("statements failed to save") |
105 | | -print "...done" |
| 105 | +print("...done") |
106 | 106 |
|
107 | 107 | # we can query our statements using an object |
108 | 108 | # constructing the query object with common fields |
|
117 | 117 | "limit": 2, |
118 | 118 | } |
119 | 119 |
|
120 | | -print "querying statements..." |
| 120 | +print("querying statements...") |
121 | 121 | response = lrs.query_statements(query) |
122 | 122 |
|
123 | 123 | if not response: |
124 | 124 | raise ValueError("statements could not be queried") |
125 | | -print "...done" |
| 125 | +print("...done") |
126 | 126 |
|
127 | 127 | # now we will explore saving a document, e.g. a state document |
128 | | -print "constructing a state document..." |
| 128 | +print("constructing a state document...") |
129 | 129 | state_document = StateDocument( |
130 | 130 | activity=object, |
131 | 131 | agent=actor, |
132 | 132 | id='stateDoc', |
133 | 133 | content=bytearray('stateDocValue', encoding='utf-8'), |
134 | 134 | ) |
135 | | -print "...done" |
| 135 | +print("...done") |
136 | 136 |
|
137 | | -print "saving state document..." |
| 137 | +print("saving state document...") |
138 | 138 | response = lrs.save_state(state_document) |
139 | 139 |
|
140 | 140 | if not response.success: |
141 | 141 | raise ValueError("could not save state document") |
142 | | -print "...done" |
| 142 | +print("...done") |
0 commit comments