Пример #1
0
 def test_view_course_assignments_as_Administrator(self):
     self.ui.login('usrAdministrator', 'password')
     test_course = Course(name="CS103",
                          section="222",
                          days_of_week="M/W/F",
                          start_time="12:00",
                          end_time="13:00",
                          instructor=self.tst_instructor,
                          lab="333")
     test_course.save()
     expected_output = "<p>Course: " + test_course.name + ", Instructor: " + self.tst_instructor.user + "</p><br />"
     actual_output = self.ui.view_course_assignments()
     self.assertEqual(expected_output, actual_output)
Пример #2
0
 def test_view_ta_assignments_single_ta_multiple_course_as_ta(self):
     self.ui.login("usrTA", "password")
     test_ta2 = Account(user="******", password="******", role="TA")
     test_ta2.save()
     test_course = Course(name="CS103",
                          section="222",
                          days_of_week="M/W/F",
                          start_time="12:00",
                          end_time="13:00",
                          instructor=self.tst_instructor,
                          lab="333")
     test_course.save()
     test_course.tas.add(self.tst_ta)
     test_course2 = Course(name="CS104",
                           section="223",
                           days_of_week="M/W/F",
                           start_time="14:00",
                           end_time="15:00",
                           instructor=self.tst_instructor,
                           lab="363")
     test_course2.save()
     test_course2.tas.add(test_ta2)
     expected_output = "<p>Course: " + test_course.name + ", Section: " + test_course.section + \
                       ", TA(s): " + self.tst_ta.user + " </p><br />" + \
                       "<p>Course: " + test_course2.name + ", Section: " + test_course2.section + \
                       ", TA(s): " + test_ta2.user + " </p><br />"
     actual_output = self.ui.view_ta_assignments()
     self.assertEqual(expected_output, actual_output)
Пример #3
0
 def test_view_ta_assignments_single_ta_single_course_as_administrator(self):
     self.ui.login("usrAdministrator", "password")
     test_course = Course(name="CS103",
                          section="222",
                          days_of_week="M/W/F",
                          start_time="12:00",
                          end_time="13:00",
                          instructor=self.tst_instructor,
                          lab="333")
     test_course.save()
     test_course.tas.add(self.tst_ta)
     expected_output = "<p>Course: " + test_course.name + ", Section: " + test_course.section + ", TA(s): " + self.tst_ta.user + " </p><br />"
     actual_output = self.ui.view_ta_assignments()
     self.assertEqual(expected_output, actual_output)
Пример #4
0
    def create_course(self, name="", section="", days="", time="", labs=""):
        cur_user_role = self.get_current_user().role
        if cur_user_role != "Supervisor" and cur_user_role != "Administrator":
            return "You do not have permissions to create courses"
        if name == "" or section == "" or days == "" or time == "" or labs == "":
            return "Please input valid arguments for all fields to create a course"
        else:
            d = days.split("/")
            valid1 = True
            for day in d:
                if day not in ["M", "T", "W", "R", "F", "S", "U", "O"]:
                    valid1 = False

            times = time.split("-")
            stl = times[0].split(":")
            etl = times[1].split(":")

            valid2 = True
            ls = labs.split("/")
            for lab in ls:
                if len(lab) > 3 or not lab.isnumeric():
                    valid2 = False

            if Course.objects.filter(name=name).exists():
                return "Course " + name + " - " + section + " already exists in the data base"
            elif len(section) > 3 or not section.isnumeric():
                return "Section must be a three digit number"
            elif not valid1:
                return "Days of week are noted as M, T, W, R, F, S, U, O"
            elif len(times[0]) > 5 or int(stl[0]) > 23 or int(stl[1]) > 59:
                return "valid start time is 00:00 to 23:59"
            elif len(times[1]) > 5 or int(etl[0]) > 23 or int(etl[1]) > 59:
                return "valid end time is 00:00 to 23:59"
            elif stl[0] > etl[0] or (stl[0] == etl[0] and stl[1] > etl[1]):
                return "end time can not be earlier than start time"
            elif not valid2:
                return "Lab sections must be a three digit number"
            else:
                o = Course(name=name,
                           section=section,
                           days_of_week=days,
                           start_time=times[0],
                           end_time=times[1])
                o.save()
                for lab in ls:
                    Lab(course=o, section=lab).save()
            return "Course " + name + " has been added to the data base with lab sections " + labs
Пример #5
0
def usercourse():

    u = User.query.filter_by(user_name="alireza").first()
    cour1 = Course(course_title="ساختمان داده",
                   course_description="ساختمان داده ارائه شده در این ترم",
                   course_date="پاییز-96")

    u.course_auth.append(cour1)
    db.session.add(cour1)
    db.session.commit()
Пример #6
0
    def setUp(self):
        self.ui = Commands()
        self.tst_supervisor = Account(user='******',
                                      password='******',
                                      role='Supervisor')
        self.tst_administrator = Account(user='******',
                                         password='******',
                                         role='Administrator')
        self.tst_instructor = Account(user='******',
                                      password='******',
                                      role='Instructor')
        self.tst_ta = Account(user='******', password='******', role='TA')
        self.tst_supervisor.save()
        self.tst_administrator.save()
        self.tst_instructor.save()
        self.tst_ta.save()

        self.tst_course = Course(name="EE-554",
                                 section="004",
                                 days_of_week="M/W/F",
                                 start_time="11:00",
                                 end_time="11:50")
        self.tst_course.save()
Пример #7
0
 def test_view_course_assignments_multiple_courses_multiple_instructors_as_administrator(self):
     self.ui.login('usrAdministrator', 'password')
     test_instructor2 = Account(user='******', password='******', role='Instructor')
     test_instructor2.save()
     test_course1 = Course(name="CS103",
                           section="222",
                           days_of_week="M/W/F",
                           start_time="12:00",
                           end_time="13:00",
                           instructor=self.tst_instructor,
                           lab="333")
     test_course1.save()
     test_course2 = Course(name="CS104",
                           section="223",
                           days_of_week="M/W/F",
                           start_time="14:00",
                           end_time="15:00",
                           instructor=test_instructor2,
                           lab="363")
     test_course2.save()
     expected_output = "<p>Course: " + test_course1.name + ", Instructor: " + self.tst_instructor.user + "</p><br />" + \
                       "<p>Course: " + test_course2.name + ", Instructor: " + test_instructor2.user + "</p><br />"
     actual_output = self.ui.view_course_assignments()
     self.assertEqual(expected_output, actual_output)
Пример #8
0
def buildCourse():

    u1 = User(user_name="اضعر فرهادی")
    cour1 = Course(course_title="برنامه سازی پیشرفته",
                   course_description="جاوا",
                   author=u1,
                   course_date="پاییز-96")
    db.session.add(cour1)
    file1 = SharedFile(shared_file_title="book", shared_file_path="book.pdf")
    db.session.add(file1)
    syllab = Syllabes(syllabes_title="10 نمره پروژه", course_syllabes=cour1)
    db.session.add(syllab)
    assign = Assignments(
        assignments_title="سوال هفته",
        assignments_description=
        "برنامه ایی بنویسید که لیست صورت حساب ها را نشان بدهد.",
        course_assignments=cour1)
    db.session.add(assign)
    reourse = Resources(resources_title="کتاب",
                        sharedfile=file1,
                        course_resources=cour1)
    db.session.add(reourse)
    db.session.commit()
Пример #9
0
class TestCommands(TestCase):
    def setUp(self):
        self.ui = Commands()
        self.tst_supervisor = Account(user='******',
                                      password='******',
                                      role='Supervisor')
        self.tst_administrator = Account(user='******',
                                         password='******',
                                         role='Administrator')
        self.tst_instructor = Account(user='******',
                                      password='******',
                                      role='Instructor')
        self.tst_ta = Account(user='******', password='******', role='TA')
        self.tst_supervisor.save()
        self.tst_administrator.save()
        self.tst_instructor.save()
        self.tst_ta.save()

        self.tst_course = Course(name="EE-554",
                                 section="004",
                                 days_of_week="M/W/F",
                                 start_time="11:00",
                                 end_time="11:50")
        self.tst_course.save()

    def test_call_command_valid(self):
        self.ui.current_user = Account()
        self.ui.set_command_list()
        output1 = self.ui.call_command('help')
        output2 = self.ui.call_command('login usrSupervisor password')
        output3 = self.ui.call_command('logout')
        self.assertNotEqual(output1, 'You should type something...')
        self.assertNotEqual(output2, 'You should type something...')
        self.assertNotEqual(output3, 'You should type something...')
        self.assertNotEqual(output1, 'Too many arguments entered. Try again!')
        self.assertNotEqual(output2, 'Too many arguments entered. Try again!')
        self.assertNotEqual(output3, 'Too many arguments entered. Try again!')
        self.assertNotEqual(output1, 'ERROR: this is not an available command')
        self.assertNotEqual(output2, 'ERROR: this is not an available command')
        self.assertNotEqual(output3, 'ERROR: this is not an available command')

    def testCallCommandInvalid(self):
        expected_output = 'ERROR: this is not an available command'
        actual_output = self.ui.call_command('invalidCommand')
        self.assertEqual(expected_output, actual_output)

    def test_call_command_too_many_args(self):
        expected_output = 'Too many arguments entered. Try again!'
        actual_output = self.ui.call_command('login user password oops')
        self.assertEqual(expected_output, actual_output)

    def test_call_command_no_args(self):
        expected_output = ''
        actual_output = self.ui.call_command()
        self.assertEqual(expected_output, actual_output)

    def test_help_with_no_current_user(self):
        self.ui.current_user = Account()
        output = self.ui.help()
        self.assertTrue(output.find('login'))
        self.assertTrue(output.find('help'))

    def test_help_as_supervisor(self):
        self.ui.current_user = self.tst_supervisor
        output = self.ui.help()
        self.assertTrue(output.find('logout'))
        self.assertTrue(output.find('create_account'))
        self.assertTrue(output.find('delete_account'))
        self.assertTrue(output.find('edit_account'))
        self.assertTrue(output.find('create_account'))
        self.assertTrue(output.find('assign_instructor'))
        self.assertTrue(output.find('assign_ta_to_course'))
        self.assertTrue(output.find('assign_ta_to_lab'))
        self.assertTrue(output.find('view_course_assignments'))
        self.assertTrue(output.find('view_ta_assignments'))
        self.assertTrue(output.find('edit_contact_info'))
        self.assertTrue(output.find('read_contact_info'))
        self.assertTrue(output.find('help'))

    def test_help_as_administrator(self):
        self.ui.current_user = self.tst_administrator
        output = self.ui.help()
        self.assertTrue(output.find('logout'))
        self.assertTrue(output.find('create_account'))
        self.assertTrue(output.find('delete_account'))
        self.assertTrue(output.find('edit_account'))
        self.assertTrue(output.find('create_account'))
        self.assertTrue(output.find('view_course_assignments'))
        self.assertTrue(output.find('view_ta_assignments'))
        self.assertTrue(output.find('edit_contact_info'))
        self.assertTrue(output.find('read_contact_info'))
        self.assertTrue(output.find('help'))

    def test_help_as_instructor(self):
        self.ui.current_user = self.tst_instructor
        output = self.ui.help()
        self.assertTrue(output.find('logout'))
        self.assertTrue(output.find('assign_ta_to_lab'))
        self.assertTrue(output.find('view_course_assignments'))
        self.assertTrue(output.find('view_ta_assignments'))
        self.assertTrue(output.find('edit_contact_info'))
        self.assertTrue(output.find('read_contact_info'))
        self.assertTrue(output.find('help'))

    def test_help_as_ta(self):
        self.ui.current_user = self.tst_ta
        output = self.ui.help()
        self.assertTrue(output.find('logout'))
        self.assertTrue(output.find('view_ta_assignments'))
        self.assertTrue(output.find('edit_contact_info'))
        self.assertTrue(output.find('read_contact_info'))
        self.assertTrue(output.find('help'))

    def test_login_bad_username(self):
        self.ui.current_user = Account()
        username = '******'
        expected_output = 'login failed! bad username/ password'
        actual_output = self.ui.login(username, 'password')
        self.assertEqual(expected_output, actual_output)
        self.assertNotEqual(self.ui.current_user.user, username)
        self.assertTrue(self.ui.current_user.id is None)

    def test_login_bad_password(self):
        self.ui.current_user = Account()
        username = '******'
        expected_output = 'login failed! bad username/ password'
        actual_output = self.ui.login(username, 'badPassword')
        self.assertEqual(expected_output, actual_output)
        self.assertNotEqual(self.ui.current_user.user, username)
        self.assertTrue(self.ui.current_user.id is None)

    def test_login_supervisor(self):
        self.ui.current_user = Account()
        username = '******'
        expected_output = 'login successful...'
        actual_output = self.ui.login(username, 'password')
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(self.ui.get_current_user(), self.tst_supervisor)

        commands = self.ui.command_list
        expected_num_commands = 13
        self.assertEqual(expected_num_commands, len(commands))
        self.assertTrue(commands.__contains__('logout'))
        self.assertTrue(commands.__contains__('create_account'))
        self.assertTrue(commands.__contains__('delete_account'))
        self.assertTrue(commands.__contains__('edit_account'))
        self.assertTrue(commands.__contains__('create_account'))
        self.assertTrue(commands.__contains__('assign_instructor'))
        self.assertTrue(commands.__contains__('assign_ta_to_course'))
        self.assertTrue(commands.__contains__('assign_ta_to_lab'))
        self.assertTrue(commands.__contains__('view_course_assignments'))
        self.assertTrue(commands.__contains__('view_ta_assignments'))
        self.assertTrue(commands.__contains__('edit_contact_info'))
        self.assertTrue(commands.__contains__('read_contact_info'))
        self.assertTrue(commands.__contains__('help'))

    def test_login_administrator(self):
        self.ui.current_user = Account()
        username = '******'
        expected_output = 'login successful...'
        actual_output = self.ui.login(username, 'password')
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(self.ui.get_current_user(), self.tst_administrator)

        commands = self.ui.command_list
        expected_num_commands = 10
        self.assertEqual(expected_num_commands, len(commands))
        self.assertTrue(commands.__contains__('logout'))
        self.assertTrue(commands.__contains__('create_account'))
        self.assertTrue(commands.__contains__('delete_account'))
        self.assertTrue(commands.__contains__('edit_account'))
        self.assertTrue(commands.__contains__('create_account'))
        self.assertTrue(commands.__contains__('view_course_assignments'))
        self.assertTrue(commands.__contains__('view_ta_assignments'))
        self.assertTrue(commands.__contains__('edit_contact_info'))
        self.assertTrue(commands.__contains__('read_contact_info'))
        self.assertTrue(commands.__contains__('help'))

    def test_login_instructor(self):
        self.ui.current_user = Account()
        username = '******'
        expected_output = 'login successful...'
        actual_output = self.ui.login(username, 'password')
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(self.ui.get_current_user(), self.tst_instructor)

        commands = self.ui.command_list
        expected_num_commands = 7
        self.assertEqual(expected_num_commands, len(commands))
        self.assertTrue(commands.__contains__('logout'))
        self.assertTrue(commands.__contains__('assign_ta_to_lab'))
        self.assertTrue(commands.__contains__('view_course_assignments'))
        self.assertTrue(commands.__contains__('view_ta_assignments'))
        self.assertTrue(commands.__contains__('edit_contact_info'))
        self.assertTrue(commands.__contains__('read_contact_info'))
        self.assertTrue(commands.__contains__('help'))

    def test_login_ta(self):
        self.ui.current_user = Account()
        username = '******'
        expected_output = 'login successful...'
        actual_output = self.ui.login(username, 'password')
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(self.ui.get_current_user(), self.tst_ta)

        commands = self.ui.command_list
        expected_num_commands = 5
        self.assertEqual(expected_num_commands, len(commands))
        self.assertTrue(commands.__contains__('logout'))
        self.assertTrue(commands.__contains__('view_ta_assignments'))
        self.assertTrue(commands.__contains__('edit_contact_info'))
        self.assertTrue(commands.__contains__('read_contact_info'))
        self.assertTrue(commands.__contains__('help'))

    def test_logout(self):
        self.ui.login('usrSupervisor', 'password')
        expected_output = 'logout successful...'
        actual_output = self.ui.logout()
        self.assertEqual(expected_output, actual_output)
        self.assertIsNone(self.ui.get_current_user().id)

        commands = self.ui.command_list
        expected_num_commands = 2
        self.assertEqual(expected_num_commands, len(commands))
        self.assertTrue(commands.__contains__('login'))
        self.assertTrue(commands.__contains__('help'))

    def test_create_account_as_supervisor(self):
        self.ui.login('usrSupervisor', 'password')
        username = '******'
        password = '******'
        role = 'Supervisor'
        expected_output = 'Successfully created account'
        actual_output = self.ui.create_account(username, password, role)
        self.assertEqual(expected_output, actual_output)
        created_account = self.ui.get_account(username)
        self.assertIsNotNone(created_account.id)
        self.assertEqual(created_account.user, username)
        self.assertEqual(created_account.password, password)
        self.assertEqual(created_account.role, role)

    def test_create_account_as_administrator(self):
        self.ui.login('usrAdministrator', 'password')
        username = '******'
        password = '******'
        role = 'TA'
        expected_output = 'Successfully created account'
        actual_output = self.ui.create_account(username, password, role)
        self.assertEqual(expected_output, actual_output)
        created_account = self.ui.get_account(username)
        self.assertIsNotNone(created_account.id)
        self.assertEqual(created_account.user, username)
        self.assertEqual(created_account.password, password)
        self.assertEqual(created_account.role, role)

    def test_create_supervisor_account_as_administrator(self):
        self.ui.login('usrAdministrator', 'password')
        username = '******'
        password = '******'
        role = 'Supervisor'
        expected_output = 'Failed to create account. Insufficient permissions'
        actual_output = self.ui.create_account(username, password, role)
        self.assertEqual(expected_output, actual_output)
        created_account = self.ui.get_account(username)
        self.assertIsNone(created_account.id)

    def test_create_account_as_instructor(self):
        self.ui.login('usrInstructor', 'password')
        username = '******'
        password = '******'
        role = 'TA'
        expected_output = 'Failed to create account. Insufficient permissions'
        actual_output = self.ui.create_account(username, password, role)
        self.assertEqual(expected_output, actual_output)
        created_account = self.ui.get_account(username)
        self.assertIsNone(created_account.id)

    def test_create_account_as_ta(self):
        self.ui.login('usrTA', 'password')
        username = '******'
        password = '******'
        role = 'TA'
        initial_count = Account.objects.count()
        expected_output = 'Failed to create account. Insufficient permissions'
        actual_output = self.ui.create_account(username, password, role)
        final_count = Account.objects.count()
        created_account = self.ui.get_account(username)
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(initial_count, final_count)
        self.assertIsNone(created_account.id)

    def test_create_account_existing_user(self):
        self.ui.login('usrSupervisor', 'password')
        username = '******'
        password = '******'
        role = 'TA'
        expected_output = 'Failed to create account. User already exists'
        initial_count = Account.objects.count()
        actual_output = self.ui.create_account(username, password, role)
        final_count = Account.objects.count()
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(initial_count, final_count)

    def test_delete_account_as_supervisor(self):
        self.ui.login('usrSupervisor', 'password')
        self.ui.create_account('tstDeleteAcc', 'password', 'TA')
        expected_output = 'Successfully deleted account'
        initial_count = Account.objects.count()
        expected_count = initial_count - 1
        actual_output = self.ui.delete_account('tstDeleteAcc')
        final_count = Account.objects.count()
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(expected_count, final_count)

    def test_delete_account_as_administrator(self):
        self.ui.login('usrAdministrator', 'password')
        self.ui.create_account('tstDeleteAcc', 'password', 'TA')
        initial_count = Account.objects.count()
        expected_count = initial_count - 1
        expected_output = 'Successfully deleted account'
        actual_output = self.ui.delete_account('tstDeleteAcc')
        final_count = Account.objects.count()
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(expected_count, final_count)

    def test_delete_account_not_exist(self):
        self.ui.login('usrSupervisor', 'password')
        expected_output = 'Failed to delete account. User not found'
        initial_count = Account.objects.count()
        actual_output = self.ui.delete_account('notExist')
        final_count = Account.objects.count()
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(initial_count, final_count)

    def test_delete_supervisor_as_administrator(self):
        self.ui.login('usrAdministrator', 'password')
        expected_output = 'Failed to delete account. Insufficient permissions'
        initial_count = Account.objects.count()
        actual_output = self.ui.delete_account('usrSupervisor')
        final_count = Account.objects.count()
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(initial_count, final_count)

    def test_delete_account_as_Instructor(self):
        self.ui.login('usrInstructor', 'password')
        expected_output = 'Failed to delete account. Insufficient permissions'
        initial_count = Account.objects.count()
        actual_output = self.ui.delete_account('usrTA')
        final_count = Account.objects.count()
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(initial_count, final_count)

    def test_delete_account_as_TA(self):
        self.ui.login('usrTA', 'password')
        expected_output = 'Failed to delete account. Insufficient permissions'
        initial_count = Account.objects.count()
        actual_output = self.ui.delete_account('usrTA')
        final_count = Account.objects.count()
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(initial_count, final_count)

    def test_delete_account_assigned_to_course(self):
        self.ui.login('usrSupervisor', 'password')
        self.tst_course.instructor = self.tst_instructor
        self.tst_course.save()
        self.assertEqual(self.tst_course.instructor, self.tst_instructor)
        num_courses_initial = Course.objects.count()
        num_accounts_initial = Account.objects.count()
        expected_output = 'Failed to delete account. User is assigned to a course'
        actual_output = self.ui.delete_account(self.tst_instructor.user)
        self.assertEqual(self.tst_course.instructor, self.tst_instructor)
        num_courses_final = Course.objects.count()
        num_accounts_final = Account.objects.count()
        self.assertEqual(expected_output, actual_output)
        self.assertEqual(num_accounts_initial, num_accounts_final)
        self.assertEqual(num_courses_initial, num_courses_final)