示例#1
0
class CriterionLearningRecordTests(ComPAIRLearningRecordTestCase):
    def setUp(self):
        super(ComPAIRLearningRecordTestCase, self).setUp()
        self.data = BasicTestData()
        self.user = self.data.authorized_student
        self.setup_session_data(self.user)
        self.criterion = self.data.create_criterion(self.user)

        self.expected_caliper_criterion = {
            'dateCreated':
            self.criterion.created.replace(tzinfo=pytz.utc).isoformat(),
            'dateModified':
            self.criterion.modified.replace(tzinfo=pytz.utc).isoformat(),
            'id':
            "https://localhost:8888/app/criterion/" + self.criterion.uuid,
            'name':
            self.criterion.name,
            'description':
            self.criterion.description,
            'type':
            'Entity'
        }

        self.expected_xapi_criterion = {
            'id':
            "https://localhost:8888/app/criterion/" + self.criterion.uuid,
            'definition': {
                'type': 'http://adlnet.gov/expapi/activities/question',
                'name': {
                    'en-US': self.criterion.name
                },
                'description': {
                    'en-US': self.criterion.description
                }
            },
            'objectType': 'Activity'
        }

    def test_on_criterion_create(self):
        on_criterion_create.send(current_app._get_current_object(),
                                 event_name=on_criterion_create.name,
                                 user=self.user,
                                 criterion=self.criterion)

        events = self.get_and_clear_caliper_event_log()
        expected_caliper_event = {
            'action':
            'Created',
            'actor':
            self.get_compair_caliper_actor(self.user),
            'object':
            self.expected_caliper_criterion,
            'session':
            self.get_caliper_session(self.get_compair_caliper_actor(
                self.user)),
            'type':
            'Event'
        }

        self.assertEqual(len(events), 1)
        self.assertEqual(events[0], expected_caliper_event)

        statements = self.get_and_clear_xapi_statement_log()
        expected_xapi_statement = {
            "actor": self.get_compair_xapi_actor(self.user),
            "verb": {
                'id': 'http://activitystrea.ms/schema/1.0/author',
                'display': {
                    'en-US': 'authored'
                }
            },
            "object": self.expected_xapi_criterion,
            "context": {
                'extensions': {
                    'http://id.tincanapi.com/extension/browser-info': {},
                    'http://id.tincanapi.com/extension/session-info':
                    self.get_xapi_session_info()
                }
            }
        }

        self.assertEqual(len(statements), 1)
        self.assertEqual(statements[0], expected_xapi_statement)

    def test_on_criterion_update(self):
        on_criterion_update.send(current_app._get_current_object(),
                                 event_name=on_criterion_update.name,
                                 user=self.user,
                                 criterion=self.criterion)

        events = self.get_and_clear_caliper_event_log()
        expected_caliper_event = {
            'action':
            'Modified',
            'actor':
            self.get_compair_caliper_actor(self.user),
            'object':
            self.expected_caliper_criterion,
            'session':
            self.get_caliper_session(self.get_compair_caliper_actor(
                self.user)),
            'type':
            'Event'
        }

        self.assertEqual(len(events), 1)
        self.assertEqual(events[0], expected_caliper_event)

        statements = self.get_and_clear_xapi_statement_log()
        expected_xapi_statement = {
            "actor": self.get_compair_xapi_actor(self.user),
            "verb": {
                'id': 'http://activitystrea.ms/schema/1.0/update',
                'display': {
                    'en-US': 'updated'
                }
            },
            "object": self.expected_xapi_criterion,
            "context": {
                'extensions': {
                    'http://id.tincanapi.com/extension/browser-info': {},
                    'http://id.tincanapi.com/extension/session-info':
                    self.get_xapi_session_info()
                }
            }
        }

        self.assertEqual(len(statements), 1)
        self.assertEqual(statements[0], expected_xapi_statement)
示例#2
0
class CriterionXAPITests(ComPAIRXAPITestCase):
    def setUp(self):
        super(ComPAIRXAPITestCase, self).setUp()
        self.data = BasicTestData()
        self.user = self.data.authorized_student
        self.criterion = self.data.create_criterion(self.user)

    def test_on_criterion_create(self):
        on_criterion_create.send(
            current_app._get_current_object(),
            event_name=on_criterion_create.name,
            user=self.user,
            criterion=self.criterion,
        )

        statements = self.get_and_clear_statement_log()
        self.assertEqual(len(statements), 1)

        self.assertEqual(statements[0]["actor"], self.get_compair_actor(self.user))
        self.assertEqual(
            statements[0]["verb"], {"id": "http://activitystrea.ms/schema/1.0/author", "display": {"en-US": "authored"}}
        )
        self.assertEqual(
            statements[0]["object"],
            {
                "id": "https://localhost:8888/app/xapi/criterion/" + self.criterion.uuid,
                "definition": {
                    "type": "http://adlnet.gov/expapi/activities/question",
                    "name": {"en-US": self.criterion.name},
                    "description": {"en-US": self.criterion.description},
                },
                "objectType": "Activity",
            },
        )
        self.assertNotIn("result", statements[0])
        self.assertNotIn("context", statements[0])

    def test_on_criterion_update(self):
        on_criterion_update.send(
            current_app._get_current_object(),
            event_name=on_criterion_update.name,
            user=self.user,
            criterion=self.criterion,
        )

        statements = self.get_and_clear_statement_log()
        self.assertEqual(len(statements), 1)

        self.assertEqual(statements[0]["actor"], self.get_compair_actor(self.user))
        self.assertEqual(
            statements[0]["verb"], {"id": "http://activitystrea.ms/schema/1.0/update", "display": {"en-US": "updated"}}
        )
        self.assertEqual(
            statements[0]["object"],
            {
                "id": "https://localhost:8888/app/xapi/criterion/" + self.criterion.uuid,
                "definition": {
                    "type": "http://adlnet.gov/expapi/activities/question",
                    "name": {"en-US": self.criterion.name},
                    "description": {"en-US": self.criterion.description},
                },
                "objectType": "Activity",
            },
        )
        self.assertNotIn("result", statements[0])
        self.assertNotIn("context", statements[0])
示例#3
0
class CriterionXAPITests(ComPAIRXAPITestCase):
    def setUp(self):
        super(ComPAIRXAPITestCase, self).setUp()
        self.data = BasicTestData()
        self.user = self.data.authorized_student
        self.criterion = self.data.create_criterion(self.user)

    def test_on_criterion_create(self):
        on_criterion_create.send(current_app._get_current_object(),
                                 event_name=on_criterion_create.name,
                                 user=self.user,
                                 criterion=self.criterion)

        statements = self.get_and_clear_statement_log()
        self.assertEqual(len(statements), 1)

        self.assertEqual(statements[0]['actor'],
                         self.get_compair_actor(self.user))
        self.assertEqual(
            statements[0]['verb'], {
                'id': 'http://activitystrea.ms/schema/1.0/author',
                'display': {
                    'en-US': 'authored'
                }
            })
        self.assertEqual(
            statements[0]['object'], {
                'id':
                'https://localhost:8888/app/xapi/criterion/' +
                self.criterion.uuid,
                'definition': {
                    'type': 'http://adlnet.gov/expapi/activities/question',
                    'name': {
                        'en-US': self.criterion.name
                    },
                    'description': {
                        'en-US': self.criterion.description
                    }
                },
                'objectType':
                'Activity'
            })
        self.assertNotIn('result', statements[0])
        self.assertNotIn('context', statements[0])

    def test_on_criterion_update(self):
        on_criterion_update.send(current_app._get_current_object(),
                                 event_name=on_criterion_update.name,
                                 user=self.user,
                                 criterion=self.criterion)

        statements = self.get_and_clear_statement_log()
        self.assertEqual(len(statements), 1)

        self.assertEqual(statements[0]['actor'],
                         self.get_compair_actor(self.user))
        self.assertEqual(
            statements[0]['verb'], {
                'id': 'http://activitystrea.ms/schema/1.0/update',
                'display': {
                    'en-US': 'updated'
                }
            })
        self.assertEqual(
            statements[0]['object'], {
                'id':
                'https://localhost:8888/app/xapi/criterion/' +
                self.criterion.uuid,
                'definition': {
                    'type': 'http://adlnet.gov/expapi/activities/question',
                    'name': {
                        'en-US': self.criterion.name
                    },
                    'description': {
                        'en-US': self.criterion.description
                    }
                },
                'objectType':
                'Activity'
            })
        self.assertNotIn('result', statements[0])
        self.assertNotIn('context', statements[0])