/
exp_fetchers_test.py
984 lines (884 loc) · 37 KB
/
exp_fetchers_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
# coding: utf-8
#
# Copyright 2014 The Oppia Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Unit tests for core.domain.exp_fetchers."""
from __future__ import absolute_import # pylint: disable=import-only-modules
from __future__ import unicode_literals # pylint: disable=import-only-modules
import copy
from core.domain import exp_domain
from core.domain import exp_fetchers
from core.domain import exp_jobs_one_off
from core.domain import exp_services
from core.domain import rights_manager
from core.platform import models
from core.tests import test_utils
import feconf
import python_utils
(exp_models,) = models.Registry.import_models([models.NAMES.exploration])
class ExplorationRetrievalTests(test_utils.GenericTestBase):
"""Test the exploration retrieval methods."""
EXP_1_ID = 'exploration_1_id'
EXP_2_ID = 'exploration_2_id'
EXP_3_ID = 'exploration_3_id'
def setUp(self):
super(ExplorationRetrievalTests, self).setUp()
self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME)
self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL)
self.exploration_1 = self.save_new_default_exploration(
self.EXP_1_ID, self.owner_id, title='Aa')
self.exploration_2 = self.save_new_default_exploration(
self.EXP_2_ID, self.owner_id, title='Bb')
self.exploration_3 = self.save_new_default_exploration(
self.EXP_3_ID, self.owner_id, title='Cc')
def test_get_exploration_summaries_matching_ids(self):
summaries = exp_fetchers.get_exploration_summaries_matching_ids([
self.EXP_1_ID, self.EXP_2_ID, self.EXP_3_ID, 'nonexistent'])
self.assertEqual(summaries[0].title, self.exploration_1.title)
self.assertEqual(summaries[1].title, self.exploration_2.title)
self.assertEqual(summaries[2].title, self.exploration_3.title)
self.assertIsNone(summaries[3])
def test_get_exploration_summaries_subscribed_to(self):
summaries = exp_fetchers.get_exploration_summaries_subscribed_to(
self.owner_id)
self.assertEqual(summaries[0].title, self.exploration_1.title)
self.assertEqual(summaries[1].title, self.exploration_2.title)
self.assertEqual(summaries[2].title, self.exploration_3.title)
def test_retrieval_of_explorations(self):
"""Test the get_exploration_by_id() method."""
with self.assertRaisesRegexp(Exception, 'Entity .* not found'):
exp_fetchers.get_exploration_by_id('fake_eid')
retrieved_exploration = (
exp_fetchers.get_exploration_by_id(self.EXP_1_ID))
self.assertEqual(self.exploration_1.id, retrieved_exploration.id)
self.assertEqual(self.exploration_1.title, retrieved_exploration.title)
with self.assertRaisesRegexp(
Exception,
'Entity for class ExplorationModel with id fake_exploration'
' not found'):
exp_fetchers.get_exploration_by_id('fake_exploration')
def test_retrieval_of_multiple_exploration_versions_for_fake_exp_id(self):
with self.assertRaisesRegexp(
ValueError, 'The given entity_id fake_exp_id is invalid'):
exp_fetchers.get_multiple_explorations_by_version(
'fake_exp_id', [1, 2, 3])
def test_retrieval_of_multiple_exploration_versions(self):
# Update exploration to version 2.
change_list = [exp_domain.ExplorationChange({
'cmd': exp_domain.CMD_ADD_STATE,
'state_name': 'New state',
})]
exp_services.update_exploration(
feconf.SYSTEM_COMMITTER_ID, self.EXP_1_ID, change_list, '')
# Update exploration to version 3.
change_list = [exp_domain.ExplorationChange({
'cmd': exp_domain.CMD_ADD_STATE,
'state_name': 'New state 2',
})]
exp_services.update_exploration(
feconf.SYSTEM_COMMITTER_ID, self.EXP_1_ID, change_list, '')
exploration_latest = exp_fetchers.get_exploration_by_id(self.EXP_1_ID)
latest_version = exploration_latest.version
explorations = exp_fetchers.get_multiple_explorations_by_version(
self.EXP_1_ID, list(python_utils.RANGE(1, latest_version + 1)))
self.assertEqual(len(explorations), 3)
self.assertEqual(explorations[0].version, 1)
self.assertEqual(explorations[1].version, 2)
self.assertEqual(explorations[2].version, 3)
def test_version_number_errors_for_get_multiple_exploration_versions(self):
# Update exploration to version 2.
change_list = [exp_domain.ExplorationChange({
'cmd': exp_domain.CMD_ADD_STATE,
'state_name': 'New state',
})]
exp_services.update_exploration(
feconf.SYSTEM_COMMITTER_ID, self.EXP_1_ID, change_list, '')
# Update exploration to version 3.
change_list = [exp_domain.ExplorationChange({
'cmd': exp_domain.CMD_ADD_STATE,
'state_name': 'New state 2',
})]
exp_services.update_exploration(
feconf.SYSTEM_COMMITTER_ID, self.EXP_1_ID, change_list, '')
with self.assertRaisesRegexp(
ValueError,
'Requested version number 4 cannot be higher than the current '
'version number 3.'):
exp_fetchers.get_multiple_explorations_by_version(
self.EXP_1_ID, [1, 2, 3, 4])
with self.assertRaisesRegexp(
ValueError,
'At least one version number is invalid'):
exp_fetchers.get_multiple_explorations_by_version(
self.EXP_1_ID, [1, 2, 2.5, 3])
def test_retrieval_of_multiple_explorations(self):
exps = {}
chars = 'abcde'
exp_ids = ['%s%s' % (self.EXP_1_ID, c) for c in chars]
for _id in exp_ids:
exp = self.save_new_valid_exploration(_id, self.owner_id)
exps[_id] = exp
result = exp_fetchers.get_multiple_explorations_by_id(
exp_ids)
for _id in exp_ids:
self.assertEqual(result.get(_id).title, exps.get(_id).title)
# Test retrieval of non-existent ids.
result = exp_fetchers.get_multiple_explorations_by_id(
exp_ids + ['doesnt_exist'], strict=False
)
for _id in exp_ids:
self.assertEqual(result.get(_id).title, exps.get(_id).title)
self.assertNotIn('doesnt_exist', result)
with self.assertRaisesRegexp(
Exception,
'Couldn\'t find explorations with the following ids:\n'
'doesnt_exist'):
exp_fetchers.get_multiple_explorations_by_id(
exp_ids + ['doesnt_exist'])
class ExplorationConversionPipelineTests(test_utils.GenericTestBase):
"""Tests the exploration model -> exploration conversion pipeline."""
OLD_EXP_ID = 'exp_id0'
NEW_EXP_ID = 'exp_id1'
UPGRADED_EXP_YAML = (
"""author_notes: ''
auto_tts_enabled: true
blurb: ''
category: category
correctness_feedback_enabled: false
init_state_name: %s
language_code: en
objective: Old objective
param_changes: []
param_specs: {}
schema_version: %d
states:
END:
classifier_model_id: null
content:
content_id: content
html: <p>Congratulations, you have finished!</p>
interaction:
answer_groups: []
confirmed_unclassified_answers: []
customization_args:
recommendedExplorationIds:
value: []
default_outcome: null
hints: []
id: EndExploration
solution: null
next_content_id_index: 0
param_changes: []
recorded_voiceovers:
voiceovers_mapping:
content: {}
solicit_answer_details: false
written_translations:
translations_mapping:
content: {}
%s:
classifier_model_id: null
content:
content_id: content
html: ''
interaction:
answer_groups: []
confirmed_unclassified_answers: []
customization_args:
buttonText:
value:
content_id: ca_buttonText_0
unicode_str: Continue
default_outcome:
dest: END
feedback:
content_id: default_outcome
html: ''
labelled_as_correct: false
missing_prerequisite_skill_id: null
param_changes: []
refresher_exploration_id: null
hints: []
id: Continue
solution: null
next_content_id_index: 1
param_changes: []
recorded_voiceovers:
voiceovers_mapping:
ca_buttonText_0: {}
content: {}
default_outcome: {}
solicit_answer_details: false
written_translations:
translations_mapping:
ca_buttonText_0: {}
content: {}
default_outcome: {}
states_schema_version: %d
tags: []
title: Old Title
""") % (
python_utils.convert_to_bytes(feconf.DEFAULT_INIT_STATE_NAME),
exp_domain.Exploration.CURRENT_EXP_SCHEMA_VERSION,
python_utils.convert_to_bytes(feconf.DEFAULT_INIT_STATE_NAME),
feconf.CURRENT_STATE_SCHEMA_VERSION)
ALBERT_EMAIL = 'albert@example.com'
ALBERT_NAME = 'albert'
def setUp(self):
super(ExplorationConversionPipelineTests, self).setUp()
# Setup user who will own the test explorations.
self.signup(self.ALBERT_EMAIL, self.ALBERT_NAME)
self.albert_id = self.get_user_id_from_email(self.ALBERT_EMAIL)
# Create exploration that uses a states schema version of 0 and ensure
# it is properly converted.
self.save_new_exp_with_states_schema_v0(
self.OLD_EXP_ID, self.albert_id, 'Old Title')
# Create standard exploration that should not be converted.
new_exp = self.save_new_valid_exploration(
self.NEW_EXP_ID, self.albert_id)
self._up_to_date_yaml = new_exp.to_yaml()
def save_new_exp_with_states_schema_v34(self, exp_id, user_id, states_dict):
"""Saves a new default exploration with a default version 34 states
dictionary.
This function should only be used for creating explorations in tests
involving migration of datastore explorations that use an old states
schema version.
Note that it makes an explicit commit to the datastore instead of using
the usual functions for updating and creating explorations. This is
because the latter approach would result in an exploration with the
*current* states schema version.
Args:
exp_id: str. The exploration ID.
user_id: str. The user_id of the creator.
states_dict: dict. The dict representation of all the states.
"""
exp_model = exp_models.ExplorationModel(
id=exp_id,
category='category',
title='title',
objective='Old objective',
language_code='en',
tags=[],
blurb='',
author_notes='',
states_schema_version=34,
init_state_name=feconf.DEFAULT_INIT_STATE_NAME,
states=states_dict,
param_specs={},
param_changes=[]
)
rights_manager.create_new_exploration_rights(exp_id, user_id)
commit_message = 'New exploration created with title \'title\'.'
exp_model.commit(
user_id, commit_message, [{
'cmd': 'create_new',
'title': 'title',
'category': 'category',
}])
exp_rights = exp_models.ExplorationRightsModel.get_by_id(exp_id)
exp_summary_model = exp_models.ExpSummaryModel(
id=exp_id,
title='title',
category='category',
objective='Old objective',
language_code='en',
tags=[],
ratings=feconf.get_empty_ratings(),
scaled_average_rating=feconf.EMPTY_SCALED_AVERAGE_RATING,
status=exp_rights.status,
community_owned=exp_rights.community_owned,
owner_ids=exp_rights.owner_ids,
contributor_ids=[],
contributors_summary={},
)
exp_summary_model.put()
def test_converts_exp_model_with_default_states_schema_version(self):
exploration = exp_fetchers.get_exploration_by_id(self.OLD_EXP_ID)
self.assertEqual(
exploration.states_schema_version,
feconf.CURRENT_STATE_SCHEMA_VERSION)
self.assertEqual(exploration.to_yaml(), self.UPGRADED_EXP_YAML)
def test_does_not_convert_up_to_date_exploration(self):
exploration = exp_fetchers.get_exploration_by_id(self.NEW_EXP_ID)
self.assertEqual(
exploration.states_schema_version,
feconf.CURRENT_STATE_SCHEMA_VERSION)
self.assertEqual(exploration.to_yaml(), self._up_to_date_yaml)
def test_migration_then_reversion_maintains_valid_exploration(self):
"""This integration test simulates the behavior of the domain layer
prior to the introduction of a states schema. In particular, it deals
with an exploration that was created before any states schema
migrations occur. The exploration is constructed using multiple change
lists, then a migration job is run. The test thereafter tests if
reverting to a version prior to the migration still maintains a valid
exploration. It tests both the exploration domain object and the
exploration model stored in the datastore for validity.
Note: It is important to distinguish between when the test is testing
the exploration domain versus its model. It is operating at the domain
layer when using exp_fetchers.get_exploration_by_id. Otherwise, it
loads the model explicitly using exp_models.ExplorationModel.get and
then converts it to an exploration domain object for validation using
exp_fetchers.get_exploration_from_model. This is NOT the same process
as exp_fetchers.get_exploration_by_id as it skips many steps which
include the conversion pipeline (which is crucial to this test).
"""
exp_id = 'exp_id2'
# Create a exploration with states schema version 0.
self.save_new_exp_with_states_schema_v0(
exp_id, self.albert_id, 'Old Title')
# Load the exploration without using the conversion pipeline. All of
# these changes are to happen on an exploration with states schema
# version 0.
exploration_model = exp_models.ExplorationModel.get(
exp_id, strict=True, version=None)
# In version 1, the title was 'Old title'.
# In version 2, the title becomes 'New title'.
exploration_model.title = 'New title'
exploration_model.commit(
self.albert_id, 'Changed title.', [])
# Version 2 of exploration.
exploration_model = exp_models.ExplorationModel.get(
exp_id, strict=True, version=None)
# Store state id mapping model for new exploration.
exploration = exp_fetchers.get_exploration_from_model(exploration_model)
# In version 3, a new state is added.
new_state = copy.deepcopy(
self.VERSION_0_STATES_DICT[feconf.DEFAULT_INIT_STATE_NAME])
new_state['interaction']['id'] = 'TextInput'
exploration_model.states['New state'] = new_state
# Properly link in the new state to avoid an invalid exploration.
init_state = exploration_model.states[feconf.DEFAULT_INIT_STATE_NAME]
init_handler = init_state['interaction']['handlers'][0]
init_handler['rule_specs'][0]['dest'] = 'New state'
exploration_model.commit(
'committer_id_v3', 'Added new state', [])
# Version 3 of exploration.
exploration_model = exp_models.ExplorationModel.get(
exp_id, strict=True, version=None)
# Store state id mapping model for new exploration.
exploration = exp_fetchers.get_exploration_from_model(exploration_model)
# Version 4 is an upgrade based on the migration job.
# Start migration job on sample exploration.
job_id = exp_jobs_one_off.ExplorationMigrationJobManager.create_new()
exp_jobs_one_off.ExplorationMigrationJobManager.enqueue(job_id)
self.process_and_flush_pending_tasks()
# Verify the latest version of the exploration has the most up-to-date
# states schema version.
exploration_model = exp_models.ExplorationModel.get(
exp_id, strict=True, version=None)
exploration = exp_fetchers.get_exploration_from_model(
exploration_model, run_conversion=False)
self.assertEqual(
exploration.states_schema_version,
feconf.CURRENT_STATE_SCHEMA_VERSION)
# The exploration should be valid after conversion.
exploration.validate(strict=True)
# Version 5 is a reversion to version 1.
exp_services.revert_exploration('committer_id_v4', exp_id, 4, 1)
# The exploration model itself should now be the old version
# (pre-migration).
exploration_model = exp_models.ExplorationModel.get(
exp_id, strict=True, version=None)
self.assertEqual(exploration_model.states_schema_version, 0)
# The exploration domain object should be updated since it ran through
# the conversion pipeline.
exploration = exp_fetchers.get_exploration_by_id(exp_id)
# The reversion after migration should still be an up-to-date
# exploration. exp_fetchers.get_exploration_by_id will automatically
# keep it up-to-date.
self.assertEqual(exploration.to_yaml(), self.UPGRADED_EXP_YAML)
# The exploration should be valid after reversion.
exploration.validate(strict=True)
snapshots_metadata = exp_services.get_exploration_snapshots_metadata(
exp_id)
# These are used to verify the correct history has been recorded after
# both migration and reversion.
commit_dict_5 = {
'committer_id': 'committer_id_v4',
'commit_message': 'Reverted exploration to version 1',
'version_number': 5,
}
commit_dict_4 = {
'committer_id': feconf.MIGRATION_BOT_USERNAME,
'commit_message':
'Update exploration states from schema version 0 to %d.' %
feconf.CURRENT_STATE_SCHEMA_VERSION,
'commit_cmds': [{
'cmd': exp_domain.CMD_MIGRATE_STATES_SCHEMA_TO_LATEST_VERSION,
'from_version': '0',
'to_version': python_utils.UNICODE(
feconf.CURRENT_STATE_SCHEMA_VERSION)
}],
'version_number': 4,
}
# Ensure there have been 5 commits.
self.assertEqual(len(snapshots_metadata), 5)
# Ensure the correct commit logs were entered during both migration and
# reversion. Also, ensure the correct commit command was written during
# migration.
self.assertDictContainsSubset(commit_dict_4, snapshots_metadata[3])
self.assertDictContainsSubset(commit_dict_5, snapshots_metadata[4])
self.assertLess(
snapshots_metadata[3]['created_on_ms'],
snapshots_metadata[4]['created_on_ms'])
# Ensure that if a converted, then reverted, then converted exploration
# is saved, it will be the up-to-date version within the datastore.
exp_services.update_exploration(
self.albert_id, exp_id, [], 'Resave after reversion')
exploration_model = exp_models.ExplorationModel.get(
exp_id, strict=True, version=None)
exploration = exp_fetchers.get_exploration_from_model(
exploration_model,
run_conversion=False)
# This exploration should be both up-to-date and valid.
self.assertEqual(exploration.to_yaml(), self.UPGRADED_EXP_YAML)
exploration.validate(strict=True)
def test_loading_old_exploration_does_not_break_domain_object_ctor(self):
"""This test attempts to load an exploration that is stored in the data
store as pre-states schema version 0. The
exp_fetchers.get_exploration_by_id function should properly load and
convert the exploration without any issues. Structural changes to the
states schema will not break the exploration domain class constructor.
"""
exp_id = 'exp_id3'
# Create a exploration with states schema version 0 and an old states
# blob.
self.save_new_exp_with_states_schema_v0(
exp_id, self.albert_id, 'Old Title')
# Ensure the exploration was converted.
exploration = exp_fetchers.get_exploration_by_id(exp_id)
self.assertEqual(
exploration.states_schema_version,
feconf.CURRENT_STATE_SCHEMA_VERSION)
# The converted exploration should be up-to-date and properly
# converted.
self.assertEqual(exploration.to_yaml(), self.UPGRADED_EXP_YAML)
def test_exploration_upgrade_v34_to_latest(self):
"""The following tests are specifically for state version upgrade from
34 to 35. That migration function contains some conditional logic that
is not fully tested by the test above.
"""
answer_groups_1 = [{
'outcome': {
'dest': 'Introduction',
'feedback': {
'content_id': 'feedback_1',
'html': '<p>Feedback</p>'
},
'labelled_as_correct': True,
'param_changes': [],
'refresher_exploration_id': None,
'missing_prerequisite_skill_id': None
},
'rule_specs': [{
'inputs': {
'x': 'x+y'
},
'rule_type': 'IsMathematicallyEquivalentTo'
}, {
'inputs': {
'x': 'x=y'
},
'rule_type': 'IsMathematicallyEquivalentTo'
}],
'training_data': [],
'tagged_skill_misconception_id': None
}]
states_dict = {
'Introduction': {
'content': {
'content_id': 'content_1',
'html': 'Question 1'
},
'recorded_voiceovers': {
'voiceovers_mapping': {
'content_1': {},
'feedback_1': {},
'feedback_2': {},
'hint_1': {},
'content_2': {}
}
},
'written_translations': {
'translations_mapping': {
'content_1': {},
'feedback_1': {},
'feedback_2': {},
'hint_1': {},
'content_2': {}
}
},
'interaction': {
'answer_groups': answer_groups_1,
'confirmed_unclassified_answers': [],
'customization_args': {},
'default_outcome': {
'dest': 'Introduction',
'feedback': {
'content_id': 'feedback_2',
'html': 'Correct Answer'
},
'param_changes': [],
'refresher_exploration_id': None,
'labelled_as_correct': True,
'missing_prerequisite_skill_id': None
},
'hints': [{
'hint_content': {
'content_id': 'hint_1',
'html': 'Hint 1'
}
}],
'solution': {
'correct_answer': {
'ascii': 'x=y',
'latex': 'x=y'
},
'answer_is_exclusive': False,
'explanation': {
'html': 'Solution explanation',
'content_id': 'content_2'
}
},
'id': 'MathExpressionInput'
},
'next_content_id_index': 4,
'param_changes': [],
'solicit_answer_details': False,
'classifier_model_id': None
}
}
self.save_new_exp_with_states_schema_v34(
'exp_id_1', 'owner_id', states_dict)
# Ensure the exploration was converted.
exploration = exp_fetchers.get_exploration_by_id('exp_id_1')
self.assertEqual(
exploration.states_schema_version,
feconf.CURRENT_STATE_SCHEMA_VERSION)
answer_groups = exploration.states[
'Introduction'].interaction.answer_groups
self.assertEqual(
exploration.states['Introduction'].interaction.id,
'MathEquationInput')
self.assertEqual(
answer_groups[0].rule_types_to_inputs, {
'MatchesExactlyWith': [{'x': 'x=y', 'y': 'both'}]
})
answer_groups_2 = [{
'outcome': {
'dest': 'Introduction',
'feedback': {
'content_id': 'feedback_2',
'html': '<p>Feedback</p>'
},
'labelled_as_correct': True,
'param_changes': [],
'refresher_exploration_id': None,
'missing_prerequisite_skill_id': None
},
'rule_specs': [{
'inputs': {
'x': 'x+y'
},
'rule_type': 'IsMathematicallyEquivalentTo'
}, {
'inputs': {
'x': '1.2 + 3'
},
'rule_type': 'IsMathematicallyEquivalentTo'
}],
'training_data': [],
'tagged_skill_misconception_id': None
}]
states_dict = {
'Introduction': {
'content': {
'content_id': 'content_2',
'html': 'Question 1'
},
'recorded_voiceovers': {
'voiceovers_mapping': {
'content_2': {},
'feedback_2': {},
'feedback_3': {},
'hint_2': {},
'content_3': {}
}
},
'written_translations': {
'translations_mapping': {
'content_2': {},
'feedback_2': {},
'feedback_3': {},
'hint_2': {},
'content_3': {}
}
},
'interaction': {
'answer_groups': answer_groups_2,
'confirmed_unclassified_answers': [],
'customization_args': {},
'default_outcome': {
'dest': 'Introduction',
'feedback': {
'content_id': 'feedback_3',
'html': 'Correct Answer'
},
'param_changes': [],
'refresher_exploration_id': None,
'labelled_as_correct': True,
'missing_prerequisite_skill_id': None
},
'hints': [{
'hint_content': {
'content_id': 'hint_2',
'html': 'Hint 2'
}
}],
'solution': {
'correct_answer': {
'ascii': 'x+y',
'latex': 'x+y'
},
'answer_is_exclusive': False,
'explanation': {
'html': 'Solution explanation',
'content_id': 'content_3'
}
},
'id': 'MathExpressionInput'
},
'next_content_id_index': 4,
'param_changes': [],
'solicit_answer_details': False,
'classifier_model_id': None
}
}
self.save_new_exp_with_states_schema_v34(
'exp_id_2', 'owner_id', states_dict)
# Ensure the exploration was converted.
exploration = exp_fetchers.get_exploration_by_id('exp_id_2')
self.assertEqual(
exploration.states_schema_version,
feconf.CURRENT_STATE_SCHEMA_VERSION)
answer_groups = exploration.states[
'Introduction'].interaction.answer_groups
self.assertEqual(
exploration.states['Introduction'].interaction.id,
'AlgebraicExpressionInput')
self.assertEqual(
answer_groups[0].rule_types_to_inputs, {
'MatchesExactlyWith': [{'x': 'x+y'}]
})
answer_groups_3 = [{
'outcome': {
'dest': 'Introduction',
'feedback': {
'content_id': 'feedback_3',
'html': '<p>Feedback</p>'
},
'labelled_as_correct': True,
'param_changes': [],
'refresher_exploration_id': None,
'missing_prerequisite_skill_id': None
},
'rule_specs': [{
'inputs': {
'x': '1.2 + 3'
},
'rule_type': 'IsMathematicallyEquivalentTo'
}],
'training_data': [],
'tagged_skill_misconception_id': None
}]
states_dict = {
'Introduction': {
'content': {
'content_id': 'content_2',
'html': 'Question 1'
},
'recorded_voiceovers': {
'voiceovers_mapping': {
'content_2': {},
'feedback_2': {},
'feedback_3': {},
'hint_2': {},
'content_3': {}
}
},
'written_translations': {
'translations_mapping': {
'content_2': {},
'feedback_2': {},
'feedback_3': {},
'hint_2': {},
'content_3': {}
}
},
'interaction': {
'answer_groups': answer_groups_3,
'confirmed_unclassified_answers': [],
'customization_args': {},
'default_outcome': {
'dest': 'Introduction',
'feedback': {
'content_id': 'feedback_3',
'html': 'Correct Answer'
},
'param_changes': [],
'refresher_exploration_id': None,
'labelled_as_correct': True,
'missing_prerequisite_skill_id': None
},
'hints': [{
'hint_content': {
'content_id': 'hint_2',
'html': 'Hint 2'
}
}],
'solution': {},
'id': 'MathExpressionInput'
},
'next_content_id_index': 4,
'param_changes': [],
'solicit_answer_details': False,
'classifier_model_id': None
}
}
self.save_new_exp_with_states_schema_v34(
'exp_id_3', 'owner_id', states_dict)
# Ensure the exploration was converted.
exploration = exp_fetchers.get_exploration_by_id('exp_id_3')
self.assertEqual(
exploration.states_schema_version,
feconf.CURRENT_STATE_SCHEMA_VERSION)
answer_groups = exploration.states[
'Introduction'].interaction.answer_groups
self.assertEqual(
exploration.states['Introduction'].interaction.id,
'NumericExpressionInput')
self.assertEqual(
answer_groups[0].rule_types_to_inputs, {
'MatchesExactlyWith': [{'x': '1.2 + 3'}]
})
answer_groups_4 = [{
'outcome': {
'dest': 'Introduction',
'feedback': {
'content_id': 'feedback_1',
'html': '<p>Feedback</p>'
},
'labelled_as_correct': True,
'param_changes': [],
'refresher_exploration_id': None,
'missing_prerequisite_skill_id': None
},
'rule_specs': [{
'inputs': {
'x': 'x+y'
},
'rule_type': 'IsMathematicallyEquivalentTo'
}],
'training_data': [],
'tagged_skill_misconception_id': None
}, {
'outcome': {
'dest': 'Introduction',
'feedback': {
'content_id': 'feedback_2',
'html': '<p>Feedback</p>'
},
'labelled_as_correct': True,
'param_changes': [],
'refresher_exploration_id': None,
'missing_prerequisite_skill_id': None
},
'rule_specs': [{
'inputs': {
'x': '1.2 + 3'
},
'rule_type': 'IsMathematicallyEquivalentTo'
}],
'training_data': [],
'tagged_skill_misconception_id': None
}]
states_dict = {
'Introduction': {
'content': {
'content_id': 'content_1',
'html': 'Question 1'
},
'recorded_voiceovers': {
'voiceovers_mapping': {
'content_1': {},
'feedback_1': {},
'feedback_2': {},
'feedback_3': {}
}
},
'written_translations': {
'translations_mapping': {
'content_1': {},
'feedback_1': {},
'feedback_2': {},
'feedback_3': {}
}
},
'interaction': {
'answer_groups': answer_groups_4,
'confirmed_unclassified_answers': [],
'customization_args': {},
'default_outcome': {
'dest': 'Introduction',
'feedback': {
'content_id': 'feedback_3',
'html': 'Correct Answer'
},
'param_changes': [],
'refresher_exploration_id': None,
'labelled_as_correct': True,
'missing_prerequisite_skill_id': None
},
'hints': [],
'solution': None,
'id': 'MathExpressionInput'
},
'next_content_id_index': 4,
'param_changes': [],
'solicit_answer_details': False,
'classifier_model_id': None
}
}
self.save_new_exp_with_states_schema_v34(
'exp_id_4', 'owner_id', states_dict)
# Ensure the exploration was converted.
exploration = exp_fetchers.get_exploration_by_id('exp_id_4')
self.assertEqual(
exploration.states_schema_version,
feconf.CURRENT_STATE_SCHEMA_VERSION)
answer_groups = exploration.states[
'Introduction'].interaction.answer_groups
self.assertEqual(
exploration.states['Introduction'].interaction.id,
'AlgebraicExpressionInput')
self.assertEqual(
answer_groups[0].rule_types_to_inputs, {
'MatchesExactlyWith': [{'x': 'x+y'}]
})
self.assertEqual(sorted(exploration.states[
'Introduction'].recorded_voiceovers.voiceovers_mapping.keys()), [
'content_1', 'feedback_1', 'feedback_3'])
self.assertEqual(sorted(exploration.states[
'Introduction'].written_translations.translations_mapping.keys()), [
'content_1', 'feedback_1', 'feedback_3'])