Ejemplo n.º 1
0
 def test_redirect_root_to_user_if_not_logged_in(self):
     provision_device()
     response = self.client.get(reverse("kolibri:core:root_redirect"))
     self.assertEqual(response.status_code, 302)
     self.assertEqual(
         response.get("location"), reverse("kolibri:kolibri.plugins.user:user")
     )
Ejemplo n.º 2
0
 def test_fails_if_device_provisioned(self):
     provision_device()
     response = self._make_request({
         "user_id": self.admin.id,
         "password": "******"
     })
     self.assertEqual(response.status_code, 403)
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 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)
Ejemplo n.º 5
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.index_name, self.index_str)
            zf.writestr(self.other_name, self.other_str)
            zf.writestr(self.script_name, self.script_str)
            zf.writestr(self.async_script_name, self.async_script_str)
            zf.writestr(self.empty_html_name, self.empty_html_str)
            zf.writestr(self.test_name_1, self.test_str_1)
            zf.writestr(self.test_name_2, self.test_str_2)
            zf.writestr(self.test_name_3, self.test_str_3)

        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.º 6
0
 def setUp(self):
     provision_device()
     facility = FacilityFactory.create()
     user = create_superuser(facility)
     self.credentials = {
         "username": user.username,
         "password": DUMMY_PASSWORD
     }
Ejemplo n.º 7
0
 def test_redirect_root_to_learn_if_logged_in(self):
     do = FacilityUserFactory.create()
     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:kolibri.plugins.learn:learn"))
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
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:learn:learn"))
Ejemplo n.º 10
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.º 11
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.º 12
0
 def test_redirect_root_to_device_if_superuser_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:kolibri.plugins.device:device_management"),
     )
Ejemplo n.º 13
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:learn:learnerlesson"
     self.classroom = Classroom.objects.create(name="Own Classroom",
                                               parent=self.facility)
     self.classroom.add_member(self.learner_user)
Ejemplo n.º 14
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,
     )
Ejemplo n.º 15
0
 def setUpTestData(cls):
     provision_device()
     cls.facility = FacilityFactory.create()
     cls.user = FacilityUserFactory(facility=cls.facility)
     cls.user2 = FacilityUserFactory(facility=cls.facility)
     cls.contentnode = ContentNode.objects.create(
         id=uuid.uuid4().hex,
         title="root",
         channel_id=uuid.uuid4().hex,
         content_id=uuid.uuid4().hex,
     )
Ejemplo n.º 16
0
 def setUp(self):
     provision_device()
     Language.objects.create(id="en", lang_code="en")
     Language.objects.create(id="es", lang_code="es")
     self.channel_id1 = uuid.uuid4().hex
     self.channel_id2 = uuid.uuid4().hex
     create_mini_channel(channel_name="math", channel_id=self.channel_id1)
     channel2 = create_mini_channel(channel_name="science",
                                    channel_id=self.channel_id2,
                                    root_lang="es")
     calculate_channel_fields(channel2.id)
Ejemplo n.º 17
0
 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/")
Ejemplo n.º 18
0
    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)
Ejemplo n.º 19
0
 def test_cannot_post_if_provisioned(self):
     provision_device()
     data = {
         "superuser": self.superuser_data,
         "facility": self.facility_data,
         "preset": self.preset_data,
         "settings": self.settings,
         "language_id": self.language_id,
     }
     response = self.client.post(
         reverse("kolibri:core:deviceprovision"), data, format="json"
     )
     self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Ejemplo n.º 20
0
 def setUpTestData(cls):
     provision_device()
     cls.facility = Facility.objects.create(name="MyFac")
     cls.admin = FacilityUser.objects.create(username="******", facility=cls.facility)
     cls.admin.set_password(DUMMY_PASSWORD)
     cls.admin.save()
     cls.facility.add_admin(cls.admin)
     cls.lesson = models.Lesson.objects.create(
         title="title",
         is_active=True,
         collection=cls.facility,
         created_by=cls.admin,
     )
Ejemplo n.º 21
0
 def setUpTestData(cls):
     provision_device()
     cls.facility = Facility.objects.create(name="MyFac")
     cls.admin = FacilityUser.objects.create(username="******", facility=cls.facility)
     cls.admin.set_password(DUMMY_PASSWORD)
     cls.admin.save()
     cls.facility.add_admin(cls.admin)
     cls.exam = models.Exam.objects.create(
         title="title",
         question_count=1,
         active=True,
         collection=cls.facility,
         creator=cls.admin,
     )
Ejemplo n.º 22
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.º 23
0
 def setUp(self):
     provision_device()
     self.facility = FacilityFactory.create()
     self.user = FacilityUserFactory(facility=self.facility)
     self.client.login(username=self.user.username,
                       password=DUMMY_PASSWORD,
                       facility=self.facility)
     data = {
         "id": "ping",
         "version_range": "<2.0.0",
         "timestamp": timezone.now(),
         "source": PINGBACK,
     }
     self.notification = PingbackNotification.objects.create(**data)
Ejemplo n.º 24
0
 def setUpTestData(cls):
     cls.facility = FacilityFactory.create()
     # provision device to pass the setup_wizard middleware check
     provision_device()
     cls.admin = FacilityUserFactory.create(facility=cls.facility)
     cls.user1 = FacilityUserFactory.create(facility=cls.facility)
     cls.summary_logs = [
         ContentSummaryLogFactory.create(
             user=cls.user1,
             content_id=uuid.uuid4().hex,
             channel_id="6199dde695db4ee4ab392222d5af1e5c",
         ) for _ in range(3)
     ]
     cls.facility.add_admin(cls.admin)
Ejemplo n.º 25
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.º 26
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.group = LearnerGroup.objects.create(name="My Group",
                                                 parent=self.classroom)

        self.facility_and_classroom_coach = helpers.create_coach(
            username="******",
            password=DUMMY_PASSWORD,
            facility=self.facility,
            classroom=self.classroom,
            is_facility_coach=True,
        )
        self.learner = helpers.create_learner(username="******",
                                              password=DUMMY_PASSWORD,
                                              facility=self.facility)
        self.classroom_group_learner = helpers.create_learner(
            username="******",
            password=DUMMY_PASSWORD,
            facility=self.facility,
            classroom=self.classroom,
            learner_group=self.group,
        )

        self.classroom_group_learner_2 = helpers.create_learner(
            username="******",
            password=DUMMY_PASSWORD,
            facility=self.facility,
            classroom=self.classroom,
            learner_group=self.group,
        )

        self.quiz = Exam.objects.create(
            title="My Lesson",
            creator=self.facility_and_classroom_coach,
            collection=self.classroom,
            question_count=5,
            active=False,
        )
        self.assignment_1 = ExamAssignment.objects.create(
            exam=self.quiz,
            assigned_by=self.facility_and_classroom_coach,
            collection=self.classroom,
        )
        self.quiz_difficulties_basename = (
            "kolibri:kolibri.plugins.coach:quizdifficulties")
        self.content_id = "25f32edcec565396a1840c5413c92451"
Ejemplo n.º 27
0
 def setUp(self):
     provision_device()
     self.facility = Facility.objects.create(name="MyFac")
     self.admin = FacilityUser.objects.create(username="******",
                                              facility=self.facility)
     self.facility.add_admin(self.admin)
     self.exam = models.Exam.objects.create(
         title="title",
         question_count=1,
         active=True,
         collection=self.facility,
         creator=self.admin,
     )
     self.assignment = models.ExamAssignment.objects.create(
         exam=self.exam, collection=self.facility, assigned_by=self.admin)
Ejemplo n.º 28
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",
         question_count=1,
         active=True,
         collection=self.facility,
         creator=self.admin,
     )
Ejemplo n.º 29
0
    def setUpTestData(cls):
        provision_device()
        cls.facility = Facility.objects.create(name="My Facility")
        cls.classroom = Classroom.objects.create(
            name="My Classroom", parent=cls.facility
        )

        cls.admin_user = FacilityUser.objects.create(
            username="******", facility=cls.facility
        )
        cls.admin_user.set_password("password")
        cls.admin_user.save()

        cls.facility.add_coach(cls.admin_user)

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

        # Available ContentNode
        cls.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
        cls.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.º 30
0
    def setUp(self):
        provision_device()
        self.facility = Facility.objects.create(name="MyFac")
        self.classroom = Classroom.objects.create(name="classrom",
                                                  parent=self.facility)
        self.another_classroom = Classroom.objects.create(
            name="another classrom", parent=self.facility)

        self.facility_admin = helpers.create_facility_admin(
            username="******",
            password=DUMMY_PASSWORD,
            facility=self.facility)
        self.facility_coach = helpers.create_coach(
            username="******",
            password=DUMMY_PASSWORD,
            facility=self.facility,
            is_facility_coach=True,
        )
        self.classroom_coach = helpers.create_coach(
            username="******",
            password=DUMMY_PASSWORD,
            facility=self.facility,
            classroom=self.classroom,
        )
        self.another_classroom_coach = helpers.create_coach(
            username="******",
            password=DUMMY_PASSWORD,
            facility=self.facility,
            classroom=self.another_classroom,
        )
        self.learner = helpers.create_learner(username="******",
                                              password=DUMMY_PASSWORD,
                                              facility=self.facility)

        self.lesson = models.Lesson.objects.create(
            title="title",
            is_active=True,
            collection=self.classroom,
            created_by=self.facility_admin,
        )

        self.basename = "kolibri:kolibri.plugins.coach:classsummary"
        self.detail_name = self.basename + "-detail"