Example #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())}
Example #2
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)
Example #3
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)
Example #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("/")
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.get("location"), reverse('kolibri:learnplugin:learn'))
Example #5
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'))
Example #6
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)
Example #7
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)
Example #8
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)
Example #9
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)