예제 #1
0
class TestDeleteMessage(TestCase):
    def setUp(self):
        self.first_user = User(username="******")
        self.first_user.set_password('12345')
        self.first_user.save()
        self.second_user = User(username="******")
        self.second_user.set_password('12345')
        self.second_user.save()
        self.third_user = User(username="******")
        self.third_user.save()
        self.first_student = Student(user=self.first_user)
        self.first_student.save()
        self.second_student = Student(user=self.second_user)
        self.second_student.save()
        self.teacher = Professor(user=self.third_user)
        self.teacher.save()
        self.stage = Stage(id=1, name="Stage1", level=1)
        self.stage.save()
        self.lesson = Lesson(id=1, name="Lesson 1", stage_id=1)
        self.lesson.save()
        self.thread_lesson = Thread.objects.create(author=self.first_user,
                                                   lesson=self.lesson,
                                                   title="Thread 1",
                                                   id=1)
        self.thread_lesson.save()
        self.thread_id = self.thread_lesson.id
        self.message = Message.objects.create(
            author=self.first_user,
            content="Content of message",
            thread=self.thread_lesson,
            created_date=utc.localize(datetime.now()),
            modified_date=utc.localize(datetime.now()))
        self.message.save()
        self.c = Client()
        self.c.login(username='******', password='******')
        self.c2 = Client()
        self.c2.login(username='******', password='******')

    def test_delete_unknown_thread(self):
        response = self.c.post('/forum/thread/{}/delete/{}'.format(402552, 1))
        self.assertEquals(response.status_code, 404)

    def test_delete_unknown_message(self):
        response = self.c.post('/forum/thread/{}/delete/{}'.format(
            self.thread_lesson.id, 1138282))
        self.assertEquals(response.status_code, 404)

    def test_delete_message(self):
        response = self.c.post('/forum/thread/{}/delete/{}'.format(
            self.thread_lesson.id, self.message.id))

        self.assertEquals(response.status_code, 302)
        self.assertFalse(Message.objects.filter(pk=self.message.id).exists())

    def test_edit_message_unauthorized(self):
        response = self.c2.post('/forum/thread/{}/delete/{}'.format(
            self.thread_lesson.id, self.message.id))
        self.assertEquals(response.status_code, 403)
예제 #2
0
    def setUp(self):
        self.user = User(username="******")
        self.user.save()
        self.second_user = User(username="******")
        self.second_user.save()
        self.teacher_user = User(username="******")
        self.teacher_user.save()
        self.second_teacher_user = User(username="******")
        self.second_teacher_user.save()

        self.student = Student(user=self.user)
        self.student.save()
        self.second_student = Student(user=self.second_user)
        self.second_student.save()
        self.teacher = Professor(user=self.teacher_user)
        self.teacher.save()
        self.second_teacher = Professor(user=self.second_teacher_user)
        self.second_teacher.save()

        self.stage = Stage(id=1, name="Stage1", level=1)
        self.stage.save()
        self.second_stage = Stage(id=2, name="Stage2", level=1)
        self.second_stage.save()

        self.lesson = Lesson(id=1, name="English", stage_id=1)
        self.lesson.save()
        self.lesson.students.add(self.student)
        self.lesson.students.add(self.second_student)
        self.lesson.professors.add(self.teacher)
        self.lesson.save()

        self.second_lesson = Lesson(id=2, name="French", stage_id=2)
        self.second_lesson.save()
        self.second_lesson.students.add(self.second_student)
        self.second_lesson.professors.add(self.teacher)
        self.second_lesson.save()

        self.thread = Thread(title="Help",
                             author=self.user,
                             recipient=self.teacher_user)
        self.thread.save()

        self.second_thread = Thread(title="Send help",
                                    author=self.second_user,
                                    lesson=self.second_lesson)
        self.second_thread.save()

        self.third_thread = Thread(title="Information regarding w/e",
                                   author=self.teacher_user,
                                   professor=self.teacher)
        self.third_thread.save()

        self.fourth_thread = Thread(title="Information regarding spam",
                                    author=self.teacher_user,
                                    professor=self.teacher)
        self.fourth_thread.save()
예제 #3
0
    def setUp(self):
        self.user = User(username="******")
        self.user.set_password('12345')
        self.user.save()
        self.teacher_user = User(username="******")
        self.teacher_user.set_password('12345')
        self.teacher_user.save()

        self.student = Student(user=self.user)
        self.student.save()
        self.teacher = Professor(user=self.teacher_user)
        self.teacher.save()

        res1_content = {"title": "Res1"}
        self.res1 = Resource(added_by=self.teacher_user, content=res1_content)
        self.res1.save()

        self.section = Section(id=1, name="Section1")
        self.section.save()
        self.section.resource.add(self.res1)
        self.section.save()

        self.skill2 = Skill(id=2, name="Skill2", code="2")
        self.skill2.save()

        res2_content = {"title": "Res2"}
        self.res2 = Resource(added_by=self.teacher_user, content=res2_content)
        self.res2.save()

        self.skill3 = Skill(id=3, name="Skill3", code="3")
        self.skill3.save()
        self.skill3.resource.add(self.res2)
        self.skill3.save()

        self.skill4 = Skill(id=4, name="Skill4", code="4")
        self.skill4.section = self.section
        self.skill4.save()

        self.stage = Stage(id=1, name="Stage1", level=1)
        self.stage.save()
        self.stage.skills.add(self.skill3)
        self.stage.skills.add(self.skill4)
        self.stage.save()

        self.lesson = Lesson(id=1, name="English", stage_id=1)
        self.lesson.save()
        self.lesson.students.add(self.student)
        self.lesson.professors.add(self.teacher)
        self.lesson.save()

        self.s1 = Client()
        self.s1.login(username=self.user.username, password='******')

        self.t1 = Client()
        self.t1.login(username=self.teacher_user.username, password='******')
예제 #4
0
    def test_public_lesson_thread(self):
        user = User(username="******")
        user.save()

        stage = Stage(level=1)
        stage.save()

        lesson = Lesson(name="Calculus", stage=stage)
        lesson.save()

        thread = Thread(title="Help", author=user, lesson=lesson)
        thread.clean()
        thread.save()

        self.assertTrue(thread.is_public_lesson())
        self.assertFalse(thread.is_private())
        self.assertFalse(thread.is_public_professor())
예제 #5
0
 def setUp(self):
     self.first_user = User(username="******")
     self.first_user.set_password('12345')
     self.first_user.save()
     self.second_user = User(username="******")
     self.second_user.set_password('12345')
     self.second_user.save()
     self.third_user = User(username="******")
     self.third_user.save()
     self.first_student = Student(user=self.first_user)
     self.first_student.save()
     self.second_student = Student(user=self.second_user)
     self.second_student.save()
     self.teacher = Professor(user=self.third_user)
     self.teacher.save()
     self.stage = Stage(id=1, name="Stage1", level=1)
     self.stage.save()
     self.lesson = Lesson(id=1, name="Lesson 1", stage_id=1)
     self.lesson.save()
     self.thread_lesson = Thread.objects.create(author=self.first_user,
                                                lesson=self.lesson,
                                                title="Thread 1",
                                                id=1)
     self.thread_lesson.save()
     self.thread_id = self.thread_lesson.id
     self.message = Message.objects.create(
         author=self.first_user,
         content="Content of message",
         thread=self.thread_lesson,
         created_date=utc.localize(datetime.now()),
         modified_date=utc.localize(datetime.now()))
     self.message.save()
     self.c = Client()
     self.c.login(username='******', password='******')
     self.c2 = Client()
     self.c2.login(username='******', password='******')
     self.file = SimpleUploadedFile('file.txt', b'OOOOOOOOOOOOOOOOOOOO')
     self.attachment = MessageAttachment.objects.create(
         name=self.file.name, file=self.file, message=self.message)
     self.attachment.save()
예제 #6
0
 def setUp(self):
     self.user1 = User(username='******')
     self.user1.set_password('12345')
     self.user1.save()
     self.teacher = Professor(user=self.user1)
     self.teacher.save()
     self.user2 = User(username="******")
     self.user2.save()
     self.student = Student(user=self.user2)
     self.student.save()
     self.stage = Stage(id=1, name="Stage1", level=1)
     self.stage.save()
     self.lesson = Lesson(id=1, name="Lesson 1", stage_id=1)
     self.lesson.save()
     self.skill1 = Skill(code=422230,
                         name="Compter deux par deux",
                         description="")
     self.skill1.save()
     self.skill2 = Skill(code=422231,
                         name="Lacer ses chaussures",
                         description="")
     self.skill2.save()
     self.c = Client()
     self.c.login(username='******', password='******')
예제 #7
0
    def setUp(self):
        self.browser = webdriver.Firefox()

        # Creation of the professor and setting up the database
        user_prof = User.objects.create_user(username='******',
                                             password='******',
                                             email='*****@*****.**')
        user_prof.save()
        self.user_prof = user_prof
        prof = Professor.objects.create(user=user_prof, is_pending=False)
        prof.save()
        self.prof = prof

        # Creation of a Student 1
        user1 = User.objects.create(first_name="Fake",
                                    last_name="Student 1",
                                    username="******",
                                    email="*****@*****.**")
        user1.save()
        student1 = Student.objects.create(user=user1, is_pending=True)
        self.code1 = student1.generate_new_code()
        student1.save()
        self.student1 = student1

        # Creation of a Student 2
        user2 = User.objects.create(first_name="Fake",
                                    last_name="Student 2",
                                    username="******",
                                    email="*****@*****.**")
        user2.save()
        student2 = Student.objects.create(user=user2, is_pending=True)
        self.code2 = student2.generate_new_code()
        student2.save()
        self.student2 = student2

        # Creation of a Student 3
        user3 = User.objects.create(first_name="Fake",
                                    last_name="Student 3",
                                    username="******",
                                    email="*****@*****.**")
        user3.save()
        student3 = Student.objects.create(user=user3, is_pending=True)
        self.code3 = student3.generate_new_code()
        student3.save()
        self.student3 = student3

        # Creation of a stage
        stage = Stage(name="Study year 1", level=1)
        stage.save()

        # Creation of a class
        lesson = Lesson(name="Class 1", stage=stage)
        lesson.save()
        self.lesson = lesson
        lesson.professors.add(prof)  # Adds a professor to the class
        lesson.students.add(student1)  # Adds students to the class
        lesson.students.add(student2)
        lesson.students.add(student3)
        lesson.save()

        # Creation of a section
        section = Section.objects.create(name="Section test")
        section.save()

        # Creation of skills for the stage, linked to the stage
        skill1 = Skill.objects.create(code="skill1",
                                      name="Skill 1 name",
                                      description="This is skill 1.",
                                      section=section)
        skill2 = Skill.objects.create(code="skill2",
                                      name="Skill 2 name",
                                      description="This is skill 2.",
                                      section=section)
        skill3 = Skill.objects.create(code="skill3",
                                      name="Skill 3 name",
                                      description="This is skill 3.",
                                      section=section)
        skill4 = Skill.objects.create(code="skill4",
                                      name="Skill 4 name",
                                      description="This is skill 4.",
                                      section=section)
        skill1.save()
        skill2.save()
        skill3.save()
        skill4.save()
        stage.skills.add(skill1)
        stage.skills.add(skill2)
        stage.skills.add(skill3)
        stage.skills.add(skill4)

        # Add relation between skills 3 and 4
        # from_skill = models.ForeignKey(Skill, null=False, blank=False, related_name='from_skill', default=0)
        # to_skill = models.ForeignKey(Skill, null=False, blank=False, related_name='to_skill', default=0)
        # relation_type = models.CharField(max_length=255, null=False, blank=False, choices=(
        #
        #     ("depend_on", "depend de"),
        #     ("similar_to", "similaire a"),
        #     ("identic_to", "identique a"),
        # ))
        relation = Relations.objects.create(from_skill=skill3,
                                            to_skill=skill4,
                                            relation_type="depend_on")
        relation.save()

        # Link students to the skills
        student_skill11 = StudentSkill.objects.create(student=student1,
                                                      skill=skill1)
        student_skill12 = StudentSkill.objects.create(student=student1,
                                                      skill=skill2)
        student_skill13 = StudentSkill.objects.create(student=student1,
                                                      skill=skill3)
        student_skill14 = StudentSkill.objects.create(student=student1,
                                                      skill=skill4)
        student_skill11.default(user_prof, "Test purpose", lesson)
        student_skill12.default(user_prof, "Test purpose", lesson)
        student_skill13.default(user_prof, "Test purpose", lesson)
        student_skill14.default(user_prof, "Test purpose", lesson)
        self.student_skill11 = student_skill11
        self.student_skill12 = student_skill12
        self.student_skill13 = student_skill13
        self.student_skill14 = student_skill14

        student_skill21 = StudentSkill.objects.create(student=student2,
                                                      skill=skill1)
        student_skill22 = StudentSkill.objects.create(student=student2,
                                                      skill=skill2)
        student_skill23 = StudentSkill.objects.create(student=student2,
                                                      skill=skill3)
        student_skill24 = StudentSkill.objects.create(student=student2,
                                                      skill=skill4)
        student_skill21.default(user_prof, "Test purpose", lesson)
        student_skill22.default(user_prof, "Test purpose", lesson)
        student_skill23.default(user_prof, "Test purpose", lesson)
        student_skill24.default(user_prof, "Test purpose", lesson)
        self.student_skill21 = student_skill21
        self.student_skill22 = student_skill22
        self.student_skill23 = student_skill23
        self.student_skill24 = student_skill24

        student_skill31 = StudentSkill.objects.create(student=student3,
                                                      skill=skill1)
        student_skill32 = StudentSkill.objects.create(student=student3,
                                                      skill=skill2)
        student_skill33 = StudentSkill.objects.create(student=student3,
                                                      skill=skill3)
        student_skill34 = StudentSkill.objects.create(student=student3,
                                                      skill=skill4)
        student_skill31.default(user_prof, "Test purpose", lesson)
        student_skill32.default(user_prof, "Test purpose", lesson)
        student_skill33.default(user_prof, "Test purpose", lesson)
        student_skill34.default(user_prof, "Test purpose", lesson)
        self.student_skill31 = student_skill31
        self.student_skill32 = student_skill32
        self.student_skill33 = student_skill33
        self.student_skill34 = student_skill34

        super(SetUp, self).setUp()
예제 #8
0
    def setUp(self):
        self.selenium = webdriver.Firefox()
        self.selenium.implicitly_wait(2)

        # Creation of the professor and setting up the database
        user = User.objects.create_user(username='******',
                                        password='******',
                                        email='*****@*****.**')
        user.save()
        prof = Professor.objects.create(user=user, is_pending=False)
        prof.save()
        self.prof = prof
        # Creating a class
        stage = Stage(name="test stage", level=1)
        stage.save()
        lesson = Lesson(name="Test", stage=stage)
        lesson.save()
        lesson.professors.add(prof)
        lesson.save()

        section = Section.objects.create(name="section")
        section.save()
        lesson.current_uaa = section.name
        lesson.save()

        skill_list = []
        self.student_list = []
        base_test_list = []
        self.codeR_list = []

        for i in range(0, 6):
            codeR = CodeR.objects.create(section=section,
                                         sub_code="UA" + str(i),
                                         name="name" + str(i))
            codeR.save()
            self.codeR_list.append(codeR)

        for i in range(0, 5):  # [0; 4[
            user = User.objects.create_user(username="******" + str(i))
            user.first_name = "student" + str(i)
            user.last_name = str(i) + "tneduts"
            user.email = "xxx_student" + str(i) + "*****@*****.**"
            user.save()
            student = Student.objects.create(user=user)
            student.save()
            self.student_list.append(student)

        for i in range(0, 100):
            gen_name = "skill" + str(i)
            skill = Skill.objects.create(code=gen_name, name=gen_name)
            skill.save()
            stage.skills.add(skill)
            skill_list.append(skill)

        for i in range(0, 100):
            base_test = Test.objects.create(name="btest" + str(i),
                                            lesson=lesson,
                                            type="skills")
            base_test.save()
            base_test_list.append(base_test)

        random.seed()

        for skill in skill_list:
            for codeR in self.codeR_list:
                if random.randint(0, 1) == 1:
                    codeR.skill.add(skill)

        for base_test in base_test_list:
            for skill in skill_list:
                if random.randint(0, 1) == 1:
                    base_test.skills.add(skill)

        for skill in skill_list:
            for student in self.student_list:
                if random.randint(0, 1) == 1:
                    skill_student = StudentSkill.objects.create(
                        student=student, skill=skill, acquired=timezone.now())
                    skill_student.save()

        for student in self.student_list:
            for base_test in base_test_list:
                if random.randint(0, 1) == 0:
                    test_student = TestStudent.objects.create(
                        student=student,
                        finished=True,
                        test=base_test,
                        started_at=timezone.now(),
                        finished_at=timezone.now())
                    test_student.save()

        for student in self.student_list:
            lesson.students.add(student)

        super(GeneralUITest, self).setUp()
예제 #9
0
    def setUp(self):
        self.user = User(username="******")
        self.user.set_password('12345')
        self.user.save()
        self.second_user = User(username="******")
        self.second_user.set_password('12345')
        self.second_user.save()
        self.teacher_user = User(username="******")
        self.teacher_user.save()
        self.second_teacher_user = User(username="******")
        self.second_teacher_user.save()

        self.student = Student(user=self.user)
        self.student.save()
        self.second_student = Student(user=self.second_user)
        self.second_student.save()
        self.teacher = Professor(user=self.teacher_user)
        self.teacher.save()
        self.second_teacher = Professor(user=self.second_teacher_user)
        self.second_teacher.save()

        self.skill1 = Skill(id=1, name="Skill1", code="1")
        self.skill1.save()

        self.skill2 = Skill(id=2, name="Skill2", code="2")
        self.skill2.save()

        self.section = Section(id=1, name="Section1")
        self.section.save()

        self.skill3 = Skill(id=3, name="Skill3", code="3")
        self.skill3.section = self.section
        self.skill3.save()

        self.skill4 = Skill(id=4, name="Skill4", code="4")
        self.skill4.section = self.section
        self.skill4.save()

        self.stage = Stage(id=1, name="Stage1", level=1)
        self.stage.save()
        self.stage.skills.add(self.skill1)
        self.stage.skills.add(self.skill2)
        self.stage.save()

        self.second_stage = Stage(id=2, name="Stage2", level=1)
        self.second_stage.save()
        self.second_stage.skills.add(self.skill3)
        self.second_stage.skills.add(self.skill4)
        self.second_stage.save()

        self.lesson = Lesson(id=1, name="English", stage_id=1)
        self.lesson.save()
        self.lesson.students.add(self.student)
        self.lesson.students.add(self.second_student)
        self.lesson.professors.add(self.teacher)
        self.lesson.save()

        self.second_lesson = Lesson(id=2, name="French", stage_id=2)
        self.second_lesson.save()
        self.second_lesson.students.add(self.second_student)
        self.second_lesson.professors.add(self.teacher)
        self.second_lesson.save()

        self.thread = Thread(title="Help",
                             author=self.user,
                             recipient=self.teacher_user)
        self.thread.save()

        self.second_thread = Thread(title="Send help",
                                    author=self.second_user,
                                    lesson=self.second_lesson)
        self.second_thread.save()

        self.third_thread = Thread(title="Information regarding w/e",
                                   author=self.teacher_user,
                                   professor=self.teacher)
        self.third_thread.save()

        self.fourth_thread = Thread(title="Information regarding spam",
                                    author=self.teacher_user,
                                    professor=self.teacher)
        self.fourth_thread.save()

        self.c1 = Client()
        self.c1.login(username=self.user.username, password='******')

        self.c2 = Client()
        self.c2.login(username=self.second_user.username, password='******')
예제 #10
0
class TestMisc(TestCase):
    def setUp(self):
        self.user = User(username="******")
        self.user.set_password('12345')
        self.user.save()
        self.second_user = User(username="******")
        self.second_user.set_password('12345')
        self.second_user.save()
        self.teacher_user = User(username="******")
        self.teacher_user.save()
        self.second_teacher_user = User(username="******")
        self.second_teacher_user.save()

        self.student = Student(user=self.user)
        self.student.save()
        self.second_student = Student(user=self.second_user)
        self.second_student.save()
        self.teacher = Professor(user=self.teacher_user)
        self.teacher.save()
        self.second_teacher = Professor(user=self.second_teacher_user)
        self.second_teacher.save()

        self.skill1 = Skill(id=1, name="Skill1", code="1")
        self.skill1.save()

        self.skill2 = Skill(id=2, name="Skill2", code="2")
        self.skill2.save()

        self.section = Section(id=1, name="Section1")
        self.section.save()

        self.skill3 = Skill(id=3, name="Skill3", code="3")
        self.skill3.section = self.section
        self.skill3.save()

        self.skill4 = Skill(id=4, name="Skill4", code="4")
        self.skill4.section = self.section
        self.skill4.save()

        self.stage = Stage(id=1, name="Stage1", level=1)
        self.stage.save()
        self.stage.skills.add(self.skill1)
        self.stage.skills.add(self.skill2)
        self.stage.save()

        self.second_stage = Stage(id=2, name="Stage2", level=1)
        self.second_stage.save()
        self.second_stage.skills.add(self.skill3)
        self.second_stage.skills.add(self.skill4)
        self.second_stage.save()

        self.lesson = Lesson(id=1, name="English", stage_id=1)
        self.lesson.save()
        self.lesson.students.add(self.student)
        self.lesson.students.add(self.second_student)
        self.lesson.professors.add(self.teacher)
        self.lesson.save()

        self.second_lesson = Lesson(id=2, name="French", stage_id=2)
        self.second_lesson.save()
        self.second_lesson.students.add(self.second_student)
        self.second_lesson.professors.add(self.teacher)
        self.second_lesson.save()

        self.thread = Thread(title="Help",
                             author=self.user,
                             recipient=self.teacher_user)
        self.thread.save()

        self.second_thread = Thread(title="Send help",
                                    author=self.second_user,
                                    lesson=self.second_lesson)
        self.second_thread.save()

        self.third_thread = Thread(title="Information regarding w/e",
                                   author=self.teacher_user,
                                   professor=self.teacher)
        self.third_thread.save()

        self.fourth_thread = Thread(title="Information regarding spam",
                                    author=self.teacher_user,
                                    professor=self.teacher)
        self.fourth_thread.save()

        self.c1 = Client()
        self.c1.login(username=self.user.username, password='******')

        self.c2 = Client()
        self.c2.login(username=self.second_user.username, password='******')

    def test_get_skills_user(self):
        skills, sections = get_skills(FakeRequest(self.user))
        self.assertEquals(len(skills), 2)

        self.assertListEqual(skills, [self.skill1, self.skill2])
        self.assertEquals(len(sections), 0)

    def test_get_skills_second_user(self):
        skills, sections = get_skills(FakeRequest(self.second_user))
        self.assertEquals(len(skills), 4)
        self.assertListEqual(
            skills, [self.skill1, self.skill2, self.skill3, self.skill4])

        self.assertEqual(len(sections), 1)
        self.assertEqual(sections[0], self.skill3.section)

    def test_get_professors_user(self):
        response = self.c1.get('/forum/write/professors/')
        json_data = json.loads(response.content)
        data = json_data["data"]

        professor = data[0]
        self.assertEquals(len(data), 1)
        self.assertEquals(
            professor, {
                "id": self.teacher.id,
                "username": self.teacher.user.username,
                "first_name": self.teacher.user.first_name,
                "last_name": self.teacher.user.last_name
            })

    def test_get_professors_second_user(self):
        response = self.c2.get('/forum/write/professors/')
        json_data = json.loads(response.content)
        data = json_data["data"]
        professor = data[0]
        self.assertEquals(len(data), 1)
        self.assertEquals(
            professor, {
                "id": self.teacher.id,
                "username": self.teacher.user.username,
                "first_name": self.teacher.user.first_name,
                "last_name": self.teacher.user.last_name
            })

    def test_get_lessons_user(self):
        response = self.c1.get('/forum/write/lessons/')
        json_data = json.loads(response.content)
        data = json_data["data"]
        self.assertEquals(len(data), 1)

        lesson = data[0]
        self.assertEqual(lesson["id"], self.lesson.id)
        self.assertEqual(lesson["name"], self.lesson.name)

    def test_get_lessons_second_user(self):
        response = self.c2.get('/forum/write/lessons/')
        json_data = json.loads(response.content)
        data = json_data["data"]

        self.assertEquals(len(data), 2)

        lesson = data[0]
        self.assertEqual(lesson["id"], self.lesson.id)
        self.assertEqual(lesson["name"], self.lesson.name)

        lesson2 = data[1]
        self.assertEqual(lesson2["id"], self.second_lesson.id)
        self.assertEqual(lesson2["name"], self.second_lesson.name)

    def test_get_users(self):
        response = self.c1.get('/forum/write/users/')
        json_data = json.loads(response.content)
        data = json_data["data"]
        users = User.objects.all()
        for i, user in enumerate(data):
            self.assertEquals(
                user, {
                    'id': users[i].id,
                    'username': users[i].username,
                    'first_name': users[i].first_name,
                    'last_name': users[i].last_name
                })
예제 #11
0
class TestPostThread(TestCase):
    def setUp(self):
        self.user1 = User(username='******')
        self.user1.set_password('12345')
        self.user1.save()
        self.teacher = Professor(user=self.user1)
        self.teacher.save()
        self.user2 = User(username="******")
        self.user2.save()
        self.student = Student(user=self.user2)
        self.student.save()
        self.stage = Stage(id=1, name="Stage1", level=1)
        self.stage.save()
        self.lesson = Lesson(id=1, name="Lesson 1", stage_id=1)
        self.lesson.save()
        self.skill1 = Skill(code=422230,
                            name="Compter deux par deux",
                            description="")
        self.skill1.save()
        self.skill2 = Skill(code=422231,
                            name="Lacer ses chaussures",
                            description="")
        self.skill2.save()
        self.c = Client()
        self.c.login(username='******', password='******')

    def test_post_valid_new_public_thread(self):
        new_thread = {
            "title": "titre_1",
            "visibdata": str(self.teacher.id),
            "skills": [422230, 422231],
            "content": "message_1",
            "visibility": "public"
        }
        response = self.c.post('/forum/write/', data=new_thread)
        new_thread = Thread.objects.order_by('-pk')[0]
        last_msg = Message.objects.order_by('-pk')[0]
        self.assertEquals(response.status_code, 302)
        self.assertEquals(new_thread.title, "titre_1")
        self.assertEquals(last_msg.content, "message_1")

    def test_post_valid_new_private_thread(self):
        new_thread = {
            "title": "titre_2",
            "visibdata": str(self.user2.id),
            "skills": [422230, 422231],
            "content": "message_2",
            "visibility": "private"
        }
        response = self.c.post('/forum/write/', data=new_thread)
        new_thread = Thread.objects.order_by('-pk')[0]
        last_msg = Message.objects.order_by('-pk')[0]
        self.assertEquals(response.status_code, 302)
        self.assertEquals(new_thread.title, "titre_2")
        self.assertEquals(last_msg.content, "message_2")

    def test_post_valid_new_class_thread(self):
        new_thread = {
            "title": "titre_3",
            "visibdata": str(self.lesson.id),
            "skills": [422230, 422231],
            "content": "message_3",
            "visibility": "class"
        }
        response = self.c.post('/forum/write/', data=new_thread)
        new_thread = Thread.objects.order_by('-pk')[0]
        last_msg = Message.objects.order_by('-pk')[0]
        self.assertEquals(response.status_code, 302)
        self.assertEquals(new_thread.title, "titre_3")
        self.assertEquals(last_msg.content, "message_3")

    def test_post_invalid_new_thread_blank_req_fields(self):
        thread_cnt_before = Thread.objects.all().count()
        msg_cnt_before = Message.objects.all().count()
        new_thread = {
            "title": "",
            "visibdata": "",
            "skills": "",
            "content": "",
            "visibility": ""
        }
        response = self.c.post('/forum/write/', data=new_thread)
        self.assertEquals(response.status_code, 200)
        self.assertEquals(thread_cnt_before, Thread.objects.all().count())
        self.assertEquals(msg_cnt_before, Message.objects.all().count())

    def test_post_invalid_new_thread_unknown_skills(self):
        thread_cnt_before = Thread.objects.all().count()
        msg_cnt_before = Message.objects.all().count()
        new_thread = {
            "title": "titre_5",
            "visibdata": str(self.lesson.id),
            "skills": ["l", "m"],
            "content": "message_5",
            "visibility": "class"
        }
        response = self.c.post('/forum/write/', data=new_thread)
        self.assertEquals(response.status_code, 200)
        self.assertEquals(thread_cnt_before, Thread.objects.all().count())
        self.assertEquals(msg_cnt_before, Message.objects.all().count())

    def test_post_invalid_new_private_thread_unknown_recipient(self):
        thread_cnt_before = Thread.objects.all().count()
        msg_cnt_before = Message.objects.all().count()
        new_thread = {
            "title": "titre_6",
            "visibdata": "unknown",
            "skills": "422230 422231",
            "content": "message_6",
            "visibility": "private"
        }
        response = self.c.post('/forum/write/', data=new_thread)
        self.assertEquals(response.status_code, 200)
        self.assertEquals(thread_cnt_before, Thread.objects.all().count())
        self.assertEquals(msg_cnt_before, Message.objects.all().count())

    def test_post_invalid_new_class_thread_unknown_class(self):
        thread_cnt_before = Thread.objects.all().count()
        msg_cnt_before = Message.objects.all().count()
        new_thread = {
            "title": "titre_7",
            "visibdata": "unknown",
            "skills": [422230, 422231],
            "content": "message_7",
            "visibility": "class"
        }
        response = self.c.post('/forum/write/', data=new_thread)
        self.assertEquals(response.status_code, 200)
        self.assertEquals(thread_cnt_before, Thread.objects.all().count())
        self.assertEquals(msg_cnt_before, Message.objects.all().count())

    def test_post_invalid_new_public_thread_unknown_professor(self):
        thread_cnt_before = Thread.objects.all().count()
        msg_cnt_before = Message.objects.all().count()
        new_thread = {
            "title": "titre_8",
            "visibdata": "unknown",
            "skills": [422230, 422231],
            "content": "message_7",
            "visibility": "public"
        }
        response = self.c.post('/forum/write/', data=new_thread)
        self.assertEquals(response.status_code, 200)
        self.assertEquals(thread_cnt_before, Thread.objects.all().count())
        self.assertEquals(msg_cnt_before, Message.objects.all().count())
예제 #12
0
class TestAttachment(TestCase):
    def setUp(self):
        self.first_user = User(username="******")
        self.first_user.set_password('12345')
        self.first_user.save()
        self.second_user = User(username="******")
        self.second_user.set_password('12345')
        self.second_user.save()
        self.third_user = User(username="******")
        self.third_user.save()
        self.first_student = Student(user=self.first_user)
        self.first_student.save()
        self.second_student = Student(user=self.second_user)
        self.second_student.save()
        self.teacher = Professor(user=self.third_user)
        self.teacher.save()
        self.stage = Stage(id=1, name="Stage1", level=1)
        self.stage.save()
        self.lesson = Lesson(id=1, name="Lesson 1", stage_id=1)
        self.lesson.save()
        self.thread_lesson = Thread.objects.create(author=self.first_user,
                                                   lesson=self.lesson,
                                                   title="Thread 1",
                                                   id=1)
        self.thread_lesson.save()
        self.thread_id = self.thread_lesson.id
        self.message = Message.objects.create(
            author=self.first_user,
            content="Content of message",
            thread=self.thread_lesson,
            created_date=utc.localize(datetime.now()),
            modified_date=utc.localize(datetime.now()))
        self.message.save()
        self.c = Client()
        self.c.login(username='******', password='******')
        self.c2 = Client()
        self.c2.login(username='******', password='******')
        self.file = SimpleUploadedFile('file.txt', b'OOOOOOOOOOOOOOOOOOOO')
        self.attachment = MessageAttachment.objects.create(
            name=self.file.name, file=self.file, message=self.message)
        self.attachment.save()

    def test_reply_thread_with_attachment(self):
        content = 'content of the new message'
        file = SimpleUploadedFile('file.png',
                                  b'AAAAAAAA',
                                  content_type='image/png')
        response = self.c.post('/forum/thread/{}'.format(self.thread_id),
                               data={
                                   'content': content,
                                   'file': file
                               })

        messages = Message.objects.all().filter(thread=self.thread_lesson)

        self.assertEquals(messages.last().content, content)
        self.assertTrue(messages.last().attachments()[0])
        self.assertEquals(response.status_code, 302)

    def test_reply_parent_message_with_attachment(self):
        content = 'content of the new message'
        response = self.c.post('/forum/thread/{}'.format(self.thread_id),
                               data={'content': content})

        messages = Message.objects.all().filter(thread=self.thread_lesson)

        self.assertEquals(messages.last().content, content)
        self.assertEquals(response.status_code, 302)  # 302 because redirects

        file = SimpleUploadedFile('file1',
                                  b'AAAAAAAA',
                                  content_type='image/png')
        content = 'content'
        response = self.c.post('/forum/thread/{}?reply_to={}'.format(
            self.thread_id,
            messages.last().id),
                               data={
                                   'content': content,
                                   'file': file
                               })
        self.assertEquals(response.status_code, 302)

    def test_edit_message_and_attachment(self):
        new_content = "New Content"
        new_file = SimpleUploadedFile('file.png',
                                      b'AAAAAAAA',
                                      content_type='image/png')
        response = self.c.post('/forum/thread/{}/edit/{}'.format(
            self.thread_lesson.id, self.message.id),
                               data={
                                   "content": new_content,
                                   "file": new_file
                               })

        self.assertEquals(response.status_code, 302)
        self.assertEquals(
            Message.objects.get(pk=self.message.id).content, new_content)
        self.assertFalse(
            Message.objects.get(pk=self.message.id).attachments()[0].file ==
            self.attachment.file)

    def test_delete_message_and_attachments(self):
        response = self.c.post('/forum/thread/{}/delete/{}'.format(
            self.thread_lesson.id, self.message.id))

        self.assertEquals(response.status_code, 302)
        self.assertFalse(Message.objects.filter(pk=self.message.id).exists())
        self.assertFalse(
            MessageAttachment.objects.filter(pk=self.attachment.id).exists())
예제 #13
0
class TestPostReply(TestCase):
    def setUp(self):
        self.first_user = User(username="******")
        self.first_user.set_password('12345')
        self.first_user.save()
        self.second_user = User(username="******")
        self.second_user.set_password('12345')
        self.second_user.save()
        self.third_user = User(username="******")
        self.third_user.save()
        self.first_student = Student(user=self.first_user)
        self.first_student.save()
        self.second_student = Student(user=self.second_user)
        self.second_student.save()
        self.teacher = Professor(user=self.third_user)
        self.teacher.save()
        self.stage = Stage(id=1, name="Stage1", level=1)
        self.stage.save()
        self.lesson = Lesson(id=1, name="Lesson 1", stage_id=1)
        self.lesson.save()
        self.thread_lesson = Thread.objects.create(author=self.first_user,
                                                   lesson=self.lesson,
                                                   title="Thread 1",
                                                   id=1)
        self.thread_lesson.save()
        self.thread_id = self.thread_lesson.id
        self.message = Message.objects.create(
            author=self.first_user,
            content="Content of message",
            thread=self.thread_lesson,
            created_date=utc.localize(datetime.now()),
            modified_date=utc.localize(datetime.now()))
        self.message.save()
        self.c = Client()
        self.c.login(username='******', password='******')
        self.c2 = Client()
        self.c2.login(username='******', password='******')

    def test_get_thread_page(self):
        response = self.c.get('/forum/thread/{}'.format(self.thread_id))
        self.assertEquals(response.status_code, 200)

    def test_reply_thread(self):
        content = 'content of the new message'
        response = self.c.post('/forum/thread/{}'.format(self.thread_id),
                               data={'content': content})

        messages = Message.objects.all().filter(thread=self.thread_lesson)

        self.assertEquals(messages.last().content, content)
        self.assertEquals(response.status_code, 302)  # 302 because redirects

    def test_reply_thread(self):
        response = self.c.post('/forum/thread/{}'.format(self.thread_id))

        self.assertEquals(response.status_code, 400)  # 302 because redirects

    def test_reply_parent_message(self):
        content = 'content of the new message'
        response = self.c.post('/forum/thread/{}'.format(self.thread_id),
                               data={'content': content})

        messages = Message.objects.all().filter(thread=self.thread_lesson)

        self.assertEquals(messages.last().content, content)
        self.assertEquals(response.status_code, 302)  # 302 because redirects

        content = 'content'
        response = self.c.post('/forum/thread/{}?reply_to={}'.format(
            self.thread_id,
            messages.last().id),
                               data={'content': content})
        self.assertEquals(response.status_code, 302)

    def test_reply_unknown_parent_message(self):
        content = 'content'
        response = self.c.post('/forum/thread/{}?reply_to=155'.format(
            self.thread_id),
                               data={'content': content})
        self.assertEquals(response.status_code, 404)
예제 #14
0
class TestGetDashboard(TestCase):
    def setUp(self):
        self.user = User(username="******")
        self.user.save()
        self.second_user = User(username="******")
        self.second_user.save()
        self.teacher_user = User(username="******")
        self.teacher_user.save()
        self.second_teacher_user = User(username="******")
        self.second_teacher_user.save()

        self.student = Student(user=self.user)
        self.student.save()
        self.second_student = Student(user=self.second_user)
        self.second_student.save()
        self.teacher = Professor(user=self.teacher_user)
        self.teacher.save()
        self.second_teacher = Professor(user=self.second_teacher_user)
        self.second_teacher.save()

        self.stage = Stage(id=1, name="Stage1", level=1)
        self.stage.save()
        self.second_stage = Stage(id=2, name="Stage2", level=1)
        self.second_stage.save()

        self.lesson = Lesson(id=1, name="English", stage_id=1)
        self.lesson.save()
        self.lesson.students.add(self.student)
        self.lesson.students.add(self.second_student)
        self.lesson.professors.add(self.teacher)
        self.lesson.save()

        self.second_lesson = Lesson(id=2, name="French", stage_id=2)
        self.second_lesson.save()
        self.second_lesson.students.add(self.second_student)
        self.second_lesson.professors.add(self.teacher)
        self.second_lesson.save()

        self.thread = Thread(title="Help",
                             author=self.user,
                             recipient=self.teacher_user)
        self.thread.save()

        self.second_thread = Thread(title="Send help",
                                    author=self.second_user,
                                    lesson=self.second_lesson)
        self.second_thread.save()

        self.third_thread = Thread(title="Information regarding w/e",
                                   author=self.teacher_user,
                                   professor=self.teacher)
        self.third_thread.save()

        self.fourth_thread = Thread(title="Information regarding spam",
                                    author=self.teacher_user,
                                    professor=self.teacher)
        self.fourth_thread.save()

    # TODO
    def test_forum_dashboard(self):
        factory = RequestFactory()
        request = factory.get("/forum/")
        request.user = self.user
        response = forum_dashboard(request)
        self.assertEquals(response.status_code, 200)

    def test_private_dashboard_empty(self):
        user = User(username="******")
        user.save()
        result = private_threads(user)
        expected = set()
        self.assertEquals(expected, result)

    def test_private_dashboard(self):
        result = private_threads(self.user)
        expected = set()
        expected.add(self.thread)
        self.assertEquals(expected, result)

    def test_public_class_dashboard_empty(self):
        user = User(username="******")
        user.save()
        student = Student(user=user)
        student.save()
        result = public_class_threads(student)
        expected = set()
        self.assertEquals(expected, result)

    def test_public_class_dashboard(self):
        result = public_class_threads(self.second_student)
        expected = set()
        expected.add(self.second_thread)
        self.assertEquals(expected, result)

    def test_public_teacher_dashboard_empty(self):
        user = User(username="******")
        user.save()
        student = Student(user=user)
        student.save()
        result = public_teacher_threads_student(student)
        expected = set()
        self.assertEquals(expected, result)

    def test_public_class_dashboard_teacher(self):
        result = public_teacher_threads_student(self.teacher)
        expected = set()
        expected.add(self.third_thread)
        expected.add(self.fourth_thread)
        self.assertEquals(expected, result)

    def test_get_thread_set_teacher(self):
        result = get_thread_set(self.teacher_user)
        expected = set()
        expected.add(self.thread)
        expected.add(self.second_thread)
        expected.add(self.third_thread)
        expected.add(self.fourth_thread)
        self.assertEquals(expected, result)
예제 #15
0
class TestResources(TestCase):
    def setUp(self):
        self.user = User(username="******")
        self.user.set_password('12345')
        self.user.save()
        self.teacher_user = User(username="******")
        self.teacher_user.set_password('12345')
        self.teacher_user.save()

        self.student = Student(user=self.user)
        self.student.save()
        self.teacher = Professor(user=self.teacher_user)
        self.teacher.save()

        res1_content = {"title": "Res1"}
        self.res1 = Resource(added_by=self.teacher_user, content=res1_content)
        self.res1.save()

        self.section = Section(id=1, name="Section1")
        self.section.save()
        self.section.resource.add(self.res1)
        self.section.save()

        self.skill2 = Skill(id=2, name="Skill2", code="2")
        self.skill2.save()

        res2_content = {"title": "Res2"}
        self.res2 = Resource(added_by=self.teacher_user, content=res2_content)
        self.res2.save()

        self.skill3 = Skill(id=3, name="Skill3", code="3")
        self.skill3.save()
        self.skill3.resource.add(self.res2)
        self.skill3.save()

        self.skill4 = Skill(id=4, name="Skill4", code="4")
        self.skill4.section = self.section
        self.skill4.save()

        self.stage = Stage(id=1, name="Stage1", level=1)
        self.stage.save()
        self.stage.skills.add(self.skill3)
        self.stage.skills.add(self.skill4)
        self.stage.save()

        self.lesson = Lesson(id=1, name="English", stage_id=1)
        self.lesson.save()
        self.lesson.students.add(self.student)
        self.lesson.professors.add(self.teacher)
        self.lesson.save()

        self.s1 = Client()
        self.s1.login(username=self.user.username, password='******')

        self.t1 = Client()
        self.t1.login(username=self.teacher_user.username, password='******')

    def test_get_all_resources(self):
        response = self.s1.get('/forum/write/resources/')
        json_data = json.loads(response.content)
        data = json_data["data"]

        self.assertEquals(len(data), 2)

        correct_ids = [self.res1.id, self.res2.id]
        self.assertTrue(data[0]["id"] in correct_ids)
        self.assertTrue(data[1]["id"] in correct_ids)

    def test_get_section_resources(self):
        response = self.s1.get(
            '/forum/write/resources/?section={0}&skills[]={1}'.format(
                self.section.id, 0))
        json_data = json.loads(response.content)
        data = json_data["data"]

        self.assertEquals(len(data), 1)

        self.assertEquals(data[0]["title"], self.res1.content['title'])

    def test_get_skills_resources(self):
        response = self.s1.get(
            '/forum/write/resources/?skills[]={0}&section={1}'.format(
                self.skill3.id, 0))
        json_data = json.loads(response.content)
        data = json_data["data"]

        self.assertEquals(len(data), 1)

        self.assertEquals(data[0]["title"], self.res2.content['title'])