Ejemplo n.º 1
0
    def setUp(self):
        self.facility = FacilityFactory.create()
        # provision device to pass the setup_wizard middleware check
        provision_device()
        self.superuser = create_superuser(self.facility)
        self.user1 = FacilityUserFactory.create(facility=self.facility)
        self.user2 = FacilityUserFactory.create(facility=self.facility)

        # add admin to 1st facility
        self.admin = FacilityUserFactory.create(facility=self.facility)
        self.facility.add_admin(self.admin)

        # create logs for each user
        self.interaction_logs = [ContentSessionLogFactory.create(user=self.user1, content_id=uuid.uuid4().hex, channel_id=uuid.uuid4().hex) for _ in range(3)]
        [ContentSessionLogFactory.create(user=self.user2, content_id=uuid.uuid4().hex, channel_id=uuid.uuid4().hex) for _ in range(2)]

        # create classroom, learner group, add user2
        self.classroom = ClassroomFactory.create(parent=self.facility)
        self.learner_group = LearnerGroupFactory.create(parent=self.classroom)
        self.learner_group.add_learner(self.user2)

        self.payload = {'user': self.user1.pk,
                        'content_id': uuid.uuid4().hex,
                        'channel_id': uuid.uuid4().hex,
                        'kind': 'video',
                        'start_timestamp': str(datetime.datetime.now())}
Ejemplo n.º 2
0
 def setUp(self):
     provision_device()
     self.facility = Facility.objects.create(name='facility')
     self.admin = FacilityUser.objects.create(username='******', facility=self.facility)
     self.admin.set_password(DUMMY_PASSWORD)
     self.admin.save()
     self.facility.add_admin(self.admin)
Ejemplo n.º 3
0
    def setUp(self):
        provision_device()

        self.client = Client()
        self.hash = hashlib.md5("DUMMYDATA".encode()).hexdigest()
        self.extension = file_formats.PDF
        self.filename = "{}.{}".format(self.hash, self.extension)
        self.title = "abc123!@#$%^&*();'[],./?><"
        self.contentnode = ContentNode(title=self.title)
        self.available = True
        self.preset = format_presets.DOCUMENT
        self.local_file = LocalFile(id=self.hash,
                                    extension=self.extension,
                                    available=self.available)
        self.file = File(local_file=self.local_file,
                         available=self.available,
                         contentnode=self.contentnode,
                         preset=self.preset)

        self.path = get_content_storage_file_path(self.filename)
        path_dir = os.path.dirname(self.path)
        if not os.path.exists(path_dir):
            os.makedirs(path_dir)
        tempfile = open(self.path, "w")
        tempfile.write("test")
        tempfile.close()
Ejemplo n.º 4
0
    def setUp(self):
        self.facility = FacilityFactory.create()
        # provision device to pass the setup_wizard middleware check
        provision_device()
        self.user1 = FacilityUserFactory.create(facility=self.facility)
        self.user2 = FacilityUserFactory.create(facility=self.facility)
        self.exam = Exam.objects.create(title="", channel_id="", question_count=1, collection=self.facility, creator=self.user2, active=True)
        self.examlog = ExamLog.objects.create(exam=self.exam, user=self.user1)
        [ExamAttemptLog.objects.create(
            item="d4623921a2ef5ddaa39048c0f7a6fe06",
            examlog=self.examlog,
            user=self.user1,
            content_id=uuid.uuid4().hex,
            channel_id=uuid.uuid4().hex,
            start_timestamp=str(datetime.datetime.now().replace(minute=x, hour=x, second=x)),
            end_timestamp=str(datetime.datetime.now().replace(minute=x, hour=x, second=x)),
            correct=0
        ) for x in range(3)]

        self.examattemptdata = {
            "item": "test",
            "start_timestamp": timezone.now(),
            "end_timestamp": timezone.now(),
            "correct": 0,
            "user": self.user1.pk,
            "examlog": self.examlog.pk,
            "content_id": "77b57a14a1f0466bb27ea7de8ff468be",
            "channel_id": "77b57a14a1f0466bb27ea7de8ff468be",
        }
Ejemplo n.º 5
0
 def setUp(self):
     provision_device()
     self.facility = FacilityFactory.create()
     self.superuser = create_superuser(self.facility)
     self.user = FacilityUserFactory.create(facility=self.facility)
     self.client.login(username=self.superuser.username,
                       password=DUMMY_PASSWORD,
                       facility=self.facility)
Ejemplo n.º 6
0
 def test_redirect_root_to_learn_if_logged_in(self):
     facility = FacilityFactory.create()
     do = create_superuser(facility)
     provision_device()
     self.client.login(username=do.username, password=DUMMY_PASSWORD)
     response = self.client.get("/")
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.get("location"), reverse('kolibri:learnplugin:learn'))
Ejemplo n.º 7
0
 def setUp(self):
     provision_device()
     DatabaseIDModel.objects.create()
     self.facility = FacilityFactory.create()
     self.superuser = create_superuser(self.facility)
     self.client.login(username=self.superuser.username,
                       password=DUMMY_PASSWORD,
                       facility=self.facility)
Ejemplo n.º 8
0
    def setUp(self):
        provision_device()
        self.facility = Facility.objects.create(name='My Facility')
        self.classroom = Classroom.objects.create(name='My Classroom',
                                                  parent=self.facility)

        self.coach_user = FacilityUser.objects.create(username='******',
                                                      facility=self.facility)
        self.coach_user.set_password('password')
        self.coach_user.save()

        self.learner_user = FacilityUser.objects.create(username='******',
                                                        facility=self.facility)
        self.learner_user.set_password('password')
        self.learner_user.save()

        self.facility.add_coach(self.coach_user)
        self.classroom.add_coach(self.coach_user)
        self.classroom.add_member(self.learner_user)

        # Need ContentNodes
        self.channel_id = '15f32edcec565396a1840c5413c92450'
        self.lesson_id = '15f32edcec565396a1840c5413c92452'

        self.content_ids = [
            '15f32edcec565396a1840c5413c92451',
            '15f32edcec565396a1840c5413c92452',
            '15f32edcec565396a1840c5413c92453',
        ]
        self.contentnode_ids = [
            '25f32edcec565396a1840c5413c92451',
            '25f32edcec565396a1840c5413c92452',
            '25f32edcec565396a1840c5413c92453',
        ]
        self.node_1 = ContentNode.objects.create(
            title='Node 1',
            available=True,
            id=self.contentnode_ids[0],
            content_id=self.content_ids[0],
            channel_id=self.channel_id)
        self.lesson = Lesson.objects.create(id=self.lesson_id,
                                            title='My Lesson',
                                            created_by=self.coach_user,
                                            collection=self.classroom,
                                            resources=json.dumps([{
                                                'contentnode_id':
                                                self.node_1.id,
                                                'content_id':
                                                self.node_1.content_id,
                                                'channel_id':
                                                self.channel_id
                                            }]))
        self.assignment_1 = LessonAssignment.objects.create(
            lesson=self.lesson,
            assigned_by=self.coach_user,
            collection=self.classroom,
        )
        self.lessonreport_basename = 'kolibri:coach:lessonreport'
Ejemplo n.º 9
0
 def setUp(self):
     provision_device()
     self.facility = Facility.objects.create(name='My Facility')
     self.learner_user = FacilityUser.objects.create(username='******', facility=self.facility)
     self.learner_user.set_password('password')
     self.learner_user.save()
     self.basename = 'kolibri:learnplugin:learnerlesson'
     self.classroom = Classroom.objects.create(name="Own Classroom", parent=self.facility)
     self.classroom.add_member(self.learner_user)
Ejemplo n.º 10
0
 def test_redirect_root_to_learn_if_logged_in(self):
     facility = FacilityFactory.create()
     do = create_superuser(facility)
     provision_device()
     self.client.login(username=do.username, password=DUMMY_PASSWORD)
     response = self.client.get("/")
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.get("location"),
                      reverse('kolibri:learnplugin:learn'))
Ejemplo n.º 11
0
 def test_cannot_post_if_provisioned(self):
     provision_device()
     data = {
         "superuser": self.superuser_data,
         "facility": self.facility_data,
         "preset": self.preset_data,
         "language_id": self.language_id,
     }
     response = self.client.post(reverse('deviceprovision'), data, format="json")
     self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Ejemplo n.º 12
0
 def setUp(self):
     self.facility = FacilityFactory.create()
     # provision device to pass the setup_wizard middleware check
     provision_device()
     self.admin = FacilityUserFactory.create(facility=self.facility)
     self.user = FacilityUserFactory.create(facility=self.facility)
     self.interaction_logs = [ContentSessionLogFactory.create(
         user=self.user,
         content_id=uuid.uuid4().hex,
         channel_id="6199dde695db4ee4ab392222d5af1e5c"
     ) for _ in range(3)]
     self.facility.add_admin(self.admin)
Ejemplo n.º 13
0
 def test_cannot_post_if_provisioned(self):
     provision_device()
     data = {
         "superuser": self.superuser_data,
         "facility": self.facility_data,
         "preset": self.preset_data,
         "language_id": self.language_id,
     }
     response = self.client.post(reverse('deviceprovision'),
                                 data,
                                 format="json")
     self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Ejemplo n.º 14
0
 def setUp(self):
     provision_device()
     self.facility = Facility.objects.create(name="MyFac")
     self.admin = FacilityUser.objects.create(username="******",
                                              facility=self.facility)
     self.admin.set_password(DUMMY_PASSWORD)
     self.admin.save()
     self.facility.add_admin(self.admin)
     self.lesson = models.Lesson.objects.create(title="title",
                                                is_active=True,
                                                collection=self.facility,
                                                created_by=self.admin)
Ejemplo n.º 15
0
 def setUp(self):
     provision_device()
     self.facility = Facility.objects.create(name="MyFac")
     self.admin = FacilityUser.objects.create(username="******",
                                              facility=self.facility)
     self.admin.set_password(DUMMY_PASSWORD)
     self.admin.save()
     self.facility.add_admin(self.admin)
     self.exam = models.Exam.objects.create(title="title",
                                            channel_id="test",
                                            question_count=1,
                                            active=True,
                                            collection=self.facility,
                                            creator=self.admin)
Ejemplo n.º 16
0
 def setUp(self):
     provision_device()
     self.facility = Facility.objects.create(name="MyFac")
     user = FacilityUser.objects.create(username="******",
                                        facility=self.facility)
     self.exam = models.Exam.objects.create(title="title",
                                            channel_id="test",
                                            question_count=1,
                                            active=True,
                                            collection=self.facility,
                                            creator=user)
     self.assignment = models.ExamAssignment.objects.create(
         exam=self.exam,
         collection=self.facility,
         assigned_by=user,
     )
Ejemplo n.º 17
0
 def setUp(self):
     provision_device()
     self.facility = Facility.objects.create(name="MyFac")
     user = FacilityUser.objects.create(username="******", facility=self.facility)
     self.exam = models.Exam.objects.create(
         title="title",
         channel_id="test",
         question_count=1,
         active=True,
         collection=self.facility,
         creator=user
     )
     self.assignment = models.ExamAssignment.objects.create(
         exam=self.exam,
         collection=self.facility,
         assigned_by=user,
     )
Ejemplo n.º 18
0
    def setUp(self):
        self.facility = FacilityFactory.create()
        # provision device to pass the setup_wizard middleware check
        provision_device()
        self.user1 = FacilityUserFactory.create(facility=self.facility)
        self.user2 = FacilityUserFactory.create(facility=self.facility)
        self.exam = Exam.objects.create(title="", channel_id="", question_count=0, collection=self.facility, creator=self.user2, active=True)
        self.examlog = ExamLog.objects.create(exam=self.exam, user=self.user1)

        self.examattemptdata = {
            "item": "test",
            "start_timestamp": timezone.now(),
            "end_timestamp": timezone.now(),
            "correct": 0,
            "user": self.user1.pk,
            "examlog": self.examlog.pk,
            "content_id": "77b57a14a1f0466bb27ea7de8ff468be",
            "channel_id": "77b57a14a1f0466bb27ea7de8ff468be",
        }
Ejemplo n.º 19
0
    def setUp(self):
        self.facility = FacilityFactory.create()
        # provision device to pass the setup_wizard middleware check
        provision_device()
        self.superuser = create_superuser(self.facility)
        self.user1 = FacilityUserFactory.create(facility=self.facility)
        self.user2 = FacilityUserFactory.create(facility=self.facility)

        # add admin to 1st facility
        self.admin = FacilityUserFactory.create(facility=self.facility)
        self.facility.add_admin(self.admin)

        # create logs for each user
        self.session_logs = [UserSessionLogFactory.create(user=self.user1) for _ in range(3)]
        [UserSessionLogFactory.create(user=self.user2) for _ in range(2)]

        # create classroom, learner group, add user2
        self.classroom = ClassroomFactory.create(parent=self.facility)
        self.learner_group = LearnerGroupFactory.create(parent=self.classroom)
        self.learner_group.add_learner(self.user2)
Ejemplo n.º 20
0
    def setUp(self):

        self.client = Client()

        provision_device()

        self.hash = hashlib.md5("DUMMYDATA".encode()).hexdigest()
        self.extension = "zip"
        self.filename = "{}.{}".format(self.hash, self.extension)

        self.zip_path = get_content_storage_file_path(self.filename)
        zip_path_dir = os.path.dirname(self.zip_path)
        if not os.path.exists(zip_path_dir):
            os.makedirs(zip_path_dir)

        with zipfile.ZipFile(self.zip_path, "w") as zf:
            zf.writestr(self.test_name_1, self.test_str_1)
            zf.writestr(self.test_name_2, self.test_str_2)

        self.zip_file_obj = LocalFile(id=self.hash, extension=self.extension, available=True)
        self.zip_file_base_url = self.zip_file_obj.get_storage_url()
Ejemplo n.º 21
0
    def setUp(self):
        provision_device()
        self.facility = Facility.objects.create(name='My Facility')
        self.classroom = Classroom.objects.create(name='My Classroom', parent=self.facility)

        self.admin_user = FacilityUser.objects.create(username='******', facility=self.facility)
        self.admin_user.set_password('password')
        self.admin_user.save()

        self.facility.add_coach(self.admin_user)

        channel_id = '15f32edcec565396a1840c5413c92450'
        content_ids = [
            '15f32edcec565396a1840c5413c92451',
            '15f32edcec565396a1840c5413c92452',
            '15f32edcec565396a1840c5413c92453',
        ]
        contentnode_ids = [
            '25f32edcec565396a1840c5413c92451',
            '25f32edcec565396a1840c5413c92452',
            '25f32edcec565396a1840c5413c92453',
        ]

        # Available ContentNode
        self.available_node = ContentNode.objects.create(
            title='Available Content',
            available=True,
            id=contentnode_ids[0],
            content_id=content_ids[0],
            channel_id=channel_id
        )

        # Unavailable ContentNode
        self.unavailable_node = ContentNode.objects.create(
            title='Unavailable Content',
            available=False,
            id=contentnode_ids[1],
            content_id=content_ids[1],
            channel_id=channel_id
        )
Ejemplo n.º 22
0
    def setUp(self):
        provision_device()

        self.client = Client()
        self.hash = hashlib.md5("DUMMYDATA".encode()).hexdigest()
        self.extension = file_formats.PDF
        self.filename = "{}.{}".format(self.hash, self.extension)
        self.title = "abc123!@#$%^&*();'[],./?><"
        self.contentnode = ContentNode(title=self.title)
        self.available = True
        self.preset = format_presets.DOCUMENT
        self.local_file = LocalFile(id=self.hash, extension=self.extension, available=self.available)
        self.file = File(local_file=self.local_file, available=self.available,
                         contentnode=self.contentnode, preset=self.preset)

        self.path = get_content_storage_file_path(self.filename)
        path_dir = os.path.dirname(self.path)
        if not os.path.exists(path_dir):
            os.makedirs(path_dir)
        tempfile = open(self.path, "w")
        tempfile.write("test")
        tempfile.close()
Ejemplo n.º 23
0
 def setUp(self):
     provision_device()
Ejemplo n.º 24
0
 def test_create_super_user(self):
     Facility.objects.create(name="Test")
     provision_device()
     create_superuser(username='******', password='******')
     self.assertTrue(FacilityUser.objects.get(username='******').is_superuser)
Ejemplo n.º 25
0
 def setUp(self):
     provision_device()
Ejemplo n.º 26
0
 def test_redirect_root_to_user_if_not_logged_in(self):
     provision_device()
     response = self.client.get("/")
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.get("location"), reverse('kolibri:user:user'))
Ejemplo n.º 27
0
 def test_redirect_root_to_user_if_not_logged_in(self):
     provision_device()
     response = self.client.get("/")
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.get("location"),
                      reverse('kolibri:user:user'))
Ejemplo n.º 28
0
 def setUp(self):
     provision_device()
     self.facility = FacilityFactory.create()
     self.superuser = create_superuser(self.facility)
     self.user = FacilityUserFactory.create(facility=self.facility)
     self.client.login(username=self.superuser.username, password=DUMMY_PASSWORD, facility=self.facility)
Ejemplo n.º 29
0
    def handle(self, *args, **options):
        # Load in the user data from the csv file to give a predictable source of user data
        with open(os.path.join(os.path.dirname(__file__),
                               'user_data.csv')) as f:
            user_data = [data for data in csv.DictReader(f)]

        n_users = options['users']
        n_classes = options['classes']
        no_onboarding = options['no_onboarding']

        # Set the random seed so that all operations will be randomized predictably
        random.seed(options['seed'])

        # Generate data up to the current time
        now = timezone.now()

        facilities = utils.get_or_create_facilities(
            n_facilities=options['facilities'])

        # Device needs to be provisioned before adding superusers
        if no_onboarding:
            print(
                'Provisioning device. Onboarding will be skipped after starting server.'
            )
            provision_device()

        for facility in facilities:
            if no_onboarding:
                print(
                    'Creating superuser "superuser" with password "password" at facility {facility}.'
                    .format(facility=facility.name))
                create_superuser(facility=facility)

            classrooms = utils.get_or_create_classrooms(
                n_classes=n_classes,
                facility=facility,
            )

            # Get all the user data at once so that it is distinct across classrooms
            facility_user_data = random.sample(user_data, n_classes * n_users)

            for i, classroom in enumerate(classrooms):
                classroom_user_data = facility_user_data[i * n_users:(i + 1) *
                                                         n_users]
                users = utils.get_or_create_classroom_users(
                    n_users=n_users,
                    classroom=classroom,
                    user_data=classroom_user_data,
                    facility=facility)

                # Iterate through the slice of the facility_user_data specific to this classroom
                for user, base_data in zip(users, classroom_user_data):
                    # The user data we are fetching from has 'Age' as a characteristic, use this as the "age" of the user
                    # in terms of their content interaction history - older, more content items interacted with!
                    n_content_items = int(base_data['Age'])

                    # Loop over all local channels to generate data for each channel
                    for channel in ChannelMetadata.objects.all():
                        utils.add_channel_activity_for_user(
                            n_content_items=n_content_items,
                            channel=channel,
                            user=user,
                            now=now)
Ejemplo n.º 30
0
 def setUp(self):
     provision_device()
     DatabaseIDModel.objects.create()
     self.facility = FacilityFactory.create()
     self.superuser = create_superuser(self.facility)
     self.client.login(username=self.superuser.username, password=DUMMY_PASSWORD, facility=self.facility)