コード例 #1
0
ファイル: test_api.py プロジェクト: bernandez/kolibri
    def setUpTestData(cls):
        cls.facility = FacilityFactory.create()
        # provision device to pass the setup_wizard middleware check
        provision_device()
        cls.superuser = create_superuser(cls.facility)
        cls.user1 = FacilityUserFactory.create(facility=cls.facility)
        cls.user2 = FacilityUserFactory.create(facility=cls.facility)

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

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

        # create classroom, learner group, add user2
        cls.classroom = ClassroomFactory.create(parent=cls.facility)
        cls.learner_group = LearnerGroupFactory.create(parent=cls.classroom)
        cls.learner_group.add_learner(cls.user2)
コード例 #2
0
 def test_superuser_responses(self):
     facility = FacilityFactory.create()
     user = create_superuser(facility)
     self.check_responses(credentials={
         "username": user.username,
         "password": DUMMY_PASSWORD
     })
コード例 #3
0
 def setUp(self):
     provision_device()
     facility = FacilityFactory.create()
     user = create_superuser(facility)
     self.credentials = {
         "username": user.username,
         "password": DUMMY_PASSWORD
     }
コード例 #4
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(reverse("kolibri:core:root_redirect"))
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.get("location"),
                      reverse("kolibri:learn:learn"))
コード例 #5
0
ファイル: test_key_urls.py プロジェクト: n0remac/kolibri
 def setUpTestData(cls):
     provision_device()
     facility = cls.facility = FacilityFactory.create()
     cls.learner = FacilityUserFactory.create(facility=facility)
     cls.facility_coach = FacilityUserFactory.create(facility=facility)
     facility.add_role(cls.facility_coach, "coach")
     cls.class_coach = FacilityUserFactory.create(facility=facility)
     facility.add_role(cls.class_coach, "classroom assignable coach")
     cls.superuser = create_superuser(cls.facility)
コード例 #6
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,
     )
コード例 #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,
     )
コード例 #8
0
ファイル: test_api.py プロジェクト: socketbox/kolibri
 def setUp(self):
     provision_device()
     self.facility = FacilityFactory.create()
     self.superuser = create_superuser(self.facility)
     self.learner = FacilityUserFactory(facility=self.facility)
     self.existing_happy_netloc = models.NetworkLocation.objects.create(
         base_url="https://kolibrihappyurl.qqq/")
     self.existing_nonkolibri_netloc = models.NetworkLocation.objects.create(
         base_url="https://nonkolibrihappyurl.qqq/")
     self.existing_sad_netloc = models.NetworkLocation.objects.create(
         base_url="https://sadurl.qqq/")
コード例 #9
0
 def setUp(self):
     super(DeviceNameTestCase, self).setUp()
     self.facility = FacilityFactory.create()
     provision_device(language_id="es", default_facility=self.facility)
     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,
     )
コード例 #10
0
ファイル: test_api.py プロジェクト: indirectlylit/kolibri
    def setUpTestData(cls):
        cls.settings = {
            "language_id": "en",
            "allow_guest_access": False,
            "allow_peer_unlisted_channel_import": True,
            "allow_learner_unassigned_resource_access": False,
        }

        cls.facility = FacilityFactory.create()
        provision_device(language_id="es", default_facility=cls.facility)
        cls.superuser = create_superuser(cls.facility)
        cls.user = FacilityUserFactory.create(facility=cls.facility)
コード例 #11
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()),
        }
コード例 #12
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)
コード例 #13
0
    def handle(self, *args, **options):
        # Load in the user data from the csv file to give a predictable source of user data
        data_path = os.path.join(os.path.dirname(__file__), "user_data.csv")
        with io.open(data_path, mode="r", encoding="utf-8") as f:
            user_data = [data for data in csv.DictReader(f)]

        n_users = options["users"]
        n_classes = options["classes"]
        no_onboarding = options["no_onboarding"]
        num_content_items = options["num_content_items"]
        num_lessons = options["num_lessons"]
        num_exams = options["num_exams"]

        # 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:
            logger.info(
                "Provisioning device. Onboarding will be skipped after starting server."
            )
            provision_device()

        for facility in facilities:
            if no_onboarding:
                logger.info(
                    '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!
                    if num_content_items:
                        n_content_items = num_content_items
                    else:
                        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,
                        )

                # create lessons
                utils.create_lessons_for_classroom(
                    classroom=classroom,
                    facility=facility,
                    channels=ChannelMetadata.objects.all(),
                    lessons=num_lessons,
                    now=now,
                )

                # create exams
                utils.create_exams_for_classrooms(
                    classroom=classroom,
                    facility=facility,
                    channels=ChannelMetadata.objects.all(),
                    exams=num_exams,
                    now=now,
                )
コード例 #14
0
ファイル: generateuserdata.py プロジェクト: br-kwon/kolibri
    def handle(self, *args, **options):
        # Load in the user data from the csv file to give a predictable source of user data
        data_path = os.path.join(os.path.dirname(__file__), "user_data.csv")
        with io.open(data_path, mode="r", encoding="utf-8") as f:
            user_data = [data for data in csv.DictReader(f)]

        n_seed = options["seed"]
        n_facilities = options["facilities"]
        n_users = options["users"]
        n_classes = options["classes"]
        no_onboarding = options["no_onboarding"]
        num_content_items = options["num_content_items"]
        num_lessons = options["num_lessons"]
        num_exams = options["num_exams"]
        max_channels = options["max_channels"]
        device_name = options["device_name"]
        # TODO(cpauya):
        # num_groups = options["num_groups"]
        # channel_token = options["channel_token"]

        # TODO(cpauya): Default to the computer/VM name so we get a unique name for each VM automatically.
        # if not device_name:
        #     # Default to computer name.
        #     # REF: https://stackoverflow.com/questions/4271740/how-can-i-use-python-to-get-the-system-hostname#4271755
        #     import socket
        #     device_name = socket.gethostname()
        #     utils.logger_info("Defaulting 'device_name' to '{0}'.".format(device_name))

        # Set the random seed so that all operations will be randomized predictably
        random.seed(n_seed)

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

        facilities = utils.get_or_create_facilities(
            n_facilities=n_facilities, device_name=device_name
        )

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

        for facility in facilities:
            if no_onboarding:
                utils.logger_info(
                    '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, device_name=device_name
            )

            # TODO(cpauya):
            # if channel_token:
            #     # TODO(cpauya): which table do we get the channel_token field?
            #     channels = ChannelMetadata.objects.filter(channel_token=channel_token)
            # else:
            #     channels = ChannelMetadata.objects.all()[:max_channels]

            channels = ChannelMetadata.objects.all()
            if max_channels and max_channels > 0:
                channels = channels[:max_channels]

            if not channels:
                utils.logger_info(
                    "No channels found, cannot add channel activities for learners."
                )

            # 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,
                    device_name=device_name,
                )

                # 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!
                    if num_content_items:
                        n_content_items = num_content_items
                    else:
                        n_content_items = int(base_data["Age"])

                    # Loop over all local channels to generate data for each channel
                    utils.logger_info("    Learner {learner}...".format(learner=user))
                    for channel in channels:
                        # TODO(cpauya): check for issue as per Richard's report
                        # REF: https://github.com/learningequality/kolibri/pull/6983#issuecomment-638980072
                        utils.logger_info(
                            "      ==> Adding {channel} channel activity for learner {learner}...".format(
                                channel=channel, learner=user
                            )
                        )
                        utils.add_channel_activity_for_user(
                            n_content_items=n_content_items,
                            channel=channel,
                            user=user,
                            now=now,
                        )

                # create lessons
                utils.create_lessons_for_classroom(
                    classroom=classroom,
                    facility=facility,
                    channels=ChannelMetadata.objects.all(),
                    lessons=num_lessons,
                    now=now,
                )

                # create exams
                utils.create_exams_for_classrooms(
                    classroom=classroom,
                    facility=facility,
                    channels=ChannelMetadata.objects.all(),
                    exams=num_exams,
                    now=now,
                    device_name=device_name,
                )
コード例 #15
0
    def setUp(self):
        provision_device()
        self.facility = FacilityFactory.create()
        self.superuser = create_superuser(self.facility)
        self.user1 = FacilityUserFactory.create(facility=self.facility)
        self.user2 = FacilityUserFactory.create(facility=self.facility)
        # create classroom, learner group, add user1
        self.classroom = ClassroomFactory.create(parent=self.facility)
        self.classroom.add_member(self.user1)

        self.payload = {
            "user": self.user1.pk,
            "content_id": uuid.uuid4().hex,
            "channel_id": uuid.uuid4().hex,
            "kind": "exercise",
            "start_timestamp": str(datetime.datetime.now()),
        }
        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,
            kind=content_kinds.EXERCISE,
        )
        self.node_2 = ContentNode.objects.create(
            title="Node 2",
            available=True,
            id=self.contentnode_ids[1],
            content_id=self.content_ids[1],
            channel_id=self.channel_id,
            kind=content_kinds.EXERCISE,
        )
        self.lesson = Lesson.objects.create(
            id=self.lesson_id,
            title="My Lesson",
            is_active=True,
            created_by=self.superuser,
            collection=self.classroom,
            resources=json.dumps(
                [
                    {
                        "contentnode_id": self.node_1.id,
                        "content_id": self.node_1.content_id,
                        "channel_id": self.channel_id,
                    },
                    {
                        "contentnode_id": self.node_2.id,
                        "content_id": self.node_2.content_id,
                        "channel_id": self.channel_id,
                    },
                ]
            ),
        )

        self.assignment_1 = LessonAssignment.objects.create(
            lesson=self.lesson, assigned_by=self.superuser, collection=self.classroom
        )

        self.exam = Exam.objects.create(
            title="title",
            question_count=1,
            active=True,
            collection=self.classroom,
            creator=self.superuser,
        )
        self.assignment = ExamAssignment.objects.create(
            exam=self.exam, collection=self.classroom, assigned_by=self.superuser
        )
        self.summarylog1 = ContentSummaryLogFactory.create(
            user=self.user1,
            content_id=self.node_1.content_id,
            channel_id=self.channel_id,
        )

        self.summarylog2 = ContentSummaryLogFactory.create(
            user=self.user1,
            content_id=self.node_2.content_id,
            channel_id=self.channel_id,
            kind=content_kinds.EXERCISE,
        )
コード例 #16
0
ファイル: test_api.py プロジェクト: indirectlylit/kolibri
 def setUpTestData(cls):
     cls.device_name = {"name": "test device"}
     cls.facility = FacilityFactory.create()
     provision_device(language_id="es", default_facility=cls.facility)
     cls.superuser = create_superuser(cls.facility)
     cls.user = FacilityUserFactory.create(facility=cls.facility)
コード例 #17
0
ファイル: test_api.py プロジェクト: indirectlylit/kolibri
 def setUpTestData(cls):
     provision_device()
     DatabaseIDModel.objects.create()
     cls.facility = FacilityFactory.create()
     cls.superuser = create_superuser(cls.facility)
コード例 #18
0
ファイル: test_api.py プロジェクト: indirectlylit/kolibri
 def setUpTestData(cls):
     provision_device()
     cls.facility = FacilityFactory.create()
     cls.superuser = create_superuser(cls.facility)
     cls.user = FacilityUserFactory.create(facility=cls.facility)
コード例 #19
0
ファイル: test_utils.py プロジェクト: indirectlylit/kolibri
    def setUp(self):
        # create dummy channel
        channel_id = uuid.uuid4().hex
        root = ContentNode.objects.create(
            id=uuid.uuid4().hex,
            title="root",
            channel_id=channel_id,
            content_id=uuid.uuid4().hex,
        )
        min_timestamp = datetime.datetime(2018, 10, 11)
        self.channel = ChannelMetadata.objects.create(
            id=channel_id,
            name="channel",
            last_updated=min_timestamp,
            root=root)
        lf = LocalFile.objects.create(
            id=uuid.uuid4().hex,
            available=True,
            file_size=1048576  # 1 MB
        )
        File.objects.create(id=uuid.uuid4().hex,
                            contentnode=root,
                            local_file=lf)

        # Load in the user data from the csv file to give a predictable source of user data
        data_path = os.path.join(USER_CSV_PATH)
        with io.open(data_path, mode="r", encoding="utf-8") as f:
            users = [data for data in csv.DictReader(f)]

        n_facilities = 1
        n_classes = 1  # 1 class x 1 facility = 1 class
        n_users = 20  # 20 users x 1 facility = 20 users
        max_timestamp = datetime.datetime(2019, 10, 11)

        self.facilities = user_data.get_or_create_facilities(
            n_facilities=n_facilities)
        for facility in self.facilities:
            dataset = facility.dataset
            # create superuser and login session
            superuser = create_superuser(facility=facility)
            facility.add_role(superuser, role_kinds.ADMIN)
            UserSessionLog.objects.create(
                user=superuser,
                start_timestamp=min_timestamp,
                last_interaction_timestamp=max_timestamp,
            )
            # create lesson and exam for facility
            Lesson.objects.create(created_by=superuser,
                                  title="lesson",
                                  collection=facility)
            exam = Exam.objects.create(creator=superuser,
                                       title="exam",
                                       question_count=1,
                                       collection=facility)

            classrooms = user_data.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(users, n_classes * n_users)

            # create random content id for the session logs
            self.content_id = uuid.uuid4().hex
            for i, classroom in enumerate(classrooms):
                classroom_user_data = facility_user_data[i * n_users:(i + 1) *
                                                         n_users]
                users = user_data.get_or_create_classroom_users(
                    n_users=n_users,
                    classroom=classroom,
                    user_data=classroom_user_data,
                    facility=facility,
                )
                # create 1 of each type of log per user
                for user in users:
                    for _ in range(1):
                        sessionlog = ContentSessionLog.objects.create(
                            user=user,
                            start_timestamp=min_timestamp,
                            end_timestamp=max_timestamp,
                            content_id=self.content_id,
                            channel_id=self.channel.id,
                            time_spent=60,  # 1 minute
                            kind=content_kinds.EXERCISE,
                        )
                        AttemptLog.objects.create(
                            item="item",
                            start_timestamp=min_timestamp,
                            end_timestamp=max_timestamp,
                            completion_timestamp=max_timestamp,
                            correct=1,
                            sessionlog=sessionlog,
                        )
                        # create 1 anon log per user session log
                        ContentSessionLog.objects.create(
                            dataset=dataset,
                            user=None,
                            start_timestamp=min_timestamp,
                            end_timestamp=max_timestamp,
                            content_id=self.content_id,
                            channel_id=self.channel.id,
                            time_spent=60,  # 1 minute,
                            kind=content_kinds.VIDEO,
                        )
                    for _ in range(1):
                        UserSessionLog.objects.create(
                            user=user,
                            start_timestamp=min_timestamp,
                            last_interaction_timestamp=max_timestamp,
                            device_info="Android,9/Chrome Mobile,86",
                        )
                    for _ in range(1):
                        ContentSummaryLog.objects.create(
                            user=user,
                            start_timestamp=min_timestamp,
                            end_timestamp=max_timestamp,
                            completion_timestamp=max_timestamp,
                            content_id=uuid.uuid4().hex,
                            channel_id=self.channel.id,
                        )
                    for _ in range(1):
                        examlog = ExamLog.objects.create(exam=exam, user=user)
                        ExamAttemptLog.objects.create(
                            examlog=examlog,
                            start_timestamp=min_timestamp,
                            end_timestamp=max_timestamp,
                            completion_timestamp=max_timestamp,
                            correct=1,
                            content_id=uuid.uuid4().hex,
                        )