class DjangoModelInterfaceTests(TestCase):
    def setUp(self):
        self.di = DjangoModelInterface()

    @staticmethod
    def hashed_password(password):
        h = hashlib.new("md5")
        h.update(f"{password}".encode("ascii"))
        return h.hexdigest()

# region Testing User variations

    def test_get_user_exists(self):
        self.di.create_account("root", "root", "administrator")
        self.assertIsNotNone(self.di.get_user("root"))

    def test_get_user_doesnt_exist(self):
        self.assertIsNone(self.di.get_user("nonexistent"))

    def test_valid_role_admin(self):
        self.assertTrue(self.di.is_valid_role("administrator"))

    def test_valid_role_supervisor(self):
        self.assertTrue(self.di.is_valid_role("supervisor"))

    def test_valid_role_instructor(self):
        self.assertTrue(self.di.is_valid_role("instructor"))

    def test_valid_role_TA(self):
        self.assertTrue(self.di.is_valid_role("TA"))

    def test_invalid_role(self):
        self.assertFalse(self.di.is_valid_role("invalid"))
# endregion

# region Testing account variations

    def test_create_account(self):
        name = "account"
        password = "******"
        role = "role"

        self.di.create_account(name, password, role)

        account = Account.objects.get(name=name)
        self.assertEqual(account.name, name)
        self.assertEqual(account.password, self.hashed_password(password))
        self.assertEqual(account.role, role)

    def test_create_account_no_user(self):
        name = "name"
        password = "******"
        role = "role"

        # wrong name
        response = self.di.create_account("", password, role)
        self.assertIsNone(response)

        # wrong role
        response = self.di.create_account(name, password, "")
        self.assertIsNone(response)

    def test_delete_account(self):
        name = "account2delete"
        self.di.create_account("account", "pass", "role")
        self.di.create_account(name, "pass", "role")
        self.di.delete_account("account")

        self.di.delete_account(name)

        self.assertEqual(len(Account.objects.filter(name=name)), 0)

    def test_update_account(self):
        name = "account"
        new_pass = "******"
        new_role = "newrole"
        self.di.create_account(name, "pass", "role")
        self.di.update_account(name, new_pass, new_role)

        account = Account.objects.get(name=name)
        self.assertNotEqual(account.password, self.hashed_password("pass"))
        self.assertEqual(account.password, self.hashed_password(new_pass))
        self.assertEqual(account.role, new_role)

    def test_get_accounts(self):
        password1 = "pass"
        password2 = "pass2"

        self.di.create_account("account", password1, "role")
        self.di.create_account("account2", password2, "role2")

        accounts = self.di.get_accounts()

        self.assertEqual(accounts, [{
            "name": "account",
            "password": self.hashed_password(password1),
            "role": "role"
        }, {
            "name": "account2",
            "password": self.hashed_password(password2),
            "role": "role2"
        }])
# endregion

# region Testing Login variations

    def test_get_set_logged_in(self):
        self.di.create_account("account", "pass", "TA")
        self.di.set_logged_in("account")

        response = self.di.get_logged_in()

        self.assertEqual(response, "account")

    def test_get_not_logged_in(self):
        self.di.create_account("account", "pass", "TA")

        response = self.di.get_logged_in()

        self.assertEqual(response, "")

    def test_set_logged_in_set_logged_out(self):
        self.di.create_account("account", "pass", "TA")
        self.di.set_logged_in("account")

        response = self.di.get_logged_in()
        self.assertEqual(response, "account")

        self.di.set_logged_out()

        response = self.di.get_logged_in()
        self.assertEqual(response, "")

    def test_set_logged_in_twice(self):
        self.di.create_account("account", "pass", "TA")
        self.di.set_logged_in("account")

        self.di.create_account("account_fail", "pass", "TA")
        self.di.set_logged_in("account_fail")

        # Tried to sign another account in before logout

        response = self.di.get_logged_in()
        self.assertEqual(response, "account")
# endregion

# region Testing Course variations

    def test_create_course_get_courses(self):
        number = "361"
        name = "CompSci361"
        self.di.create_course(number, name)

        self.assertIsNotNone(
            Course.objects.filter(number=number, name=name).first())

    def test_create_set_course_instructor(self):
        number = "361"
        instructor_name = "jayson"

        self.di.create_course(number, "CompSci")
        self.di.create_account(instructor_name, "pass", "instructor")
        self.di.set_course_instructor(number, instructor_name)

        course = Course.objects.get(number=number)
        self.assertEqual(course.instructor.first().name, instructor_name)

    def test_create_set_course_no_instructor(self):
        number = "361"
        name = "CompSci361"
        self.di.create_course(number, name)

        course = Course.objects.get(number=number)

        self.assertIsNone(course.instructor.first())

    def test_create_set_course_instructor_twice(self):
        number = "361"
        instructor_name = "jayson"

        self.di.create_course(number, "CompSci")
        self.di.create_account(instructor_name, "pass", "instructor")
        self.di.set_course_instructor(number, instructor_name)

        # Try to set again
        self.di.create_account("Not jayson", "pass", "instructor")
        self.di.set_course_instructor(number, "Not jayson")

        course = Course.objects.get(number=number)
        self.assertEqual(course.instructor.first().name, instructor_name)

    def test_get_course_exists(self):
        self.di.create_course("123", "test_course")
        self.assertIsNotNone(self.di.course_exists("123"))

    def test_get_course_doesnt_exist(self):
        self.assertIsNotNone(self.di.course_exists("000"))

    def test_get_course_assigned(self):
        self.di.create_account("teacher", "root", "instructor")
        self.di.create_course("123", "test_course")
        self.di.set_course_instructor("123", "teacher")
        self.assertTrue(self.di.is_course_assigned("123"))

    def test_get_course_not_assigned(self):
        self.di.create_course("000", "test_course")
        self.assertFalse(self.di.is_course_assigned("000"))
# endregion

# region Testing Lab variations

    def test_create_lab_get_labs(self):
        course_number = "361"
        lab_number = "801"
        self.di.create_course(course_number, "courseName")
        self.di.create_lab(course_number, lab_number)

        lab = Course.objects.get(number=course_number, labs__number=lab_number)

        self.assertIsNotNone(lab)

    def test_assign_lab(self):
        course_number = "361"
        lab_number = "801"
        ta_name = "apoorv"
        self.di.create_course(course_number, "courseName")
        self.di.create_lab(course_number, lab_number)
        self.di.create_account(ta_name, "pass", "TA")

        self.di.set_lab_assignment(course_number, lab_number, ta_name)
        lab = Course.objects.get(number=course_number).labs.get(
            number=lab_number)

        self.assertEqual(lab.ta.first().name, ta_name)

    def test_get_lab_exists(self):
        self.di.create_course("123", "test_course")
        self.di.create_lab("123", "001")
        self.assertTrue(self.di.lab_exists("123", "001"))

    def test_get_lab_doesnt_exist(self):
        self.di.create_course("123", "test_course")
        self.assertFalse(self.di.lab_exists("123", "1231231"))

    def test_get_lab_assigned(self):
        self.di.create_account("ta", "pass", "TA")
        self.di.create_course("123", "test_course")
        self.di.create_lab("123", "001")
        self.di.set_lab_assignment("123", "001", "ta")
        self.assertTrue(self.di.is_lab_assigned("123", "001"))

    def test_get_lab_not_assigned(self):
        self.di.create_course("234", "test_course2")
        self.di.create_lab("234", "000")
        self.assertFalse(self.di.is_lab_assigned("234", "000"))
# endregion

# region Information variations

    def test_basic_get_private_info(self):
        user = TaCLI.User.User("admin", "master")
        self.di.create_account("admin", "pass", "master")

        self.assertEqual(
            self.di.get_private_info(user), {
                'username': '******',
                'name': '',
                'lname': '',
                'email': '',
                'address': '',
                'phone': '',
                'hours': '',
                'role': 'master'
            })

    def test_edit_phone_get_private_info(self):
        user = TaCLI.User.User("admin", "master")
        self.di.create_account("admin", "pass", "master")
        self.di.edit_phone("admin", "1414")

        self.assertEqual(
            self.di.get_private_info(user), {
                'username': '******',
                'name': '',
                'lname': '',
                'email': '',
                'address': '',
                'phone': '1414',
                'hours': '',
                'role': 'master'
            })

    def test_edit_name_get_private_info(self):
        user = TaCLI.User.User("admin", "master")
        self.di.create_account("admin", "pass", "master")
        self.di.edit_name("admin", "first", "second")

        self.assertEqual(
            self.di.get_private_info(user), {
                'username': '******',
                'name': 'first',
                'lname': 'second',
                'email': '',
                'address': '',
                'phone': '',
                'hours': '',
                'role': 'master'
            })

    def test_edit_address_get_private_info(self):
        user = TaCLI.User.User("admin", "master")
        self.di.create_account("admin", "pass", "master")
        self.di.edit_address("admin", "somewhere")

        self.assertEqual(
            self.di.get_private_info(user), {
                'username': '******',
                'name': '',
                'lname': '',
                'email': '',
                'address': 'somewhere',
                'phone': '',
                'hours': '',
                'role': 'master'
            })

    def test_edit_email_get_private_info(self):
        user = TaCLI.User.User("admin", "master")
        self.di.create_account("admin", "pass", "master")
        self.di.edit_email("admin", "@uwm.edu")

        self.assertEqual(
            self.di.get_private_info(user), {
                'username': '******',
                'name': '',
                'lname': '',
                'email': '@uwm.edu',
                'address': '',
                'phone': '',
                'hours': '',
                'role': 'master'
            })

    def test_edit_office_hours_get_private_info(self):
        user = TaCLI.User.User("admin", "master")
        self.di.create_account("admin", "pass", "master")
        self.di.edit_office_hours("admin", "Monday: 1:00PM-2:00PM")

        self.assertEqual(
            self.di.get_private_info(user), {
                'username': '******',
                'name': '',
                'lname': '',
                'email': '',
                'address': '',
                'phone': '',
                'hours': 'MONDAY: 1:00PM-2:00PM, ',
                'role': 'master'
            })

    def test_basic_get_public_info(self):
        user = TaCLI.User.User("admin", "master")
        self.di.create_account("admin", "pass", "master")

        self.assertEqual(
            self.di.get_public_info(user), {
                'username': '******',
                'name': '',
                'lname': '',
                'email': '',
                'hours': '',
                'role': 'master'
            })

    def test_edit_name_get_public_info(self):
        user = TaCLI.User.User("admin", "master")
        self.di.create_account("admin", "pass", "master")
        self.di.edit_name("admin", "first", "second")

        self.assertEqual(
            self.di.get_public_info(user), {
                'username': '******',
                'name': 'first',
                'lname': 'second',
                'email': '',
                'hours': '',
                'role': 'master'
            })

    def test_edit_email_get_public_info(self):
        user = TaCLI.User.User("admin", "master")
        self.di.create_account("admin", "pass", "master")
        self.di.edit_email("admin", "@uwm.edu")

        self.assertEqual(
            self.di.get_public_info(user), {
                'username': '******',
                'name': '',
                'lname': '',
                'email': '@uwm.edu',
                'hours': '',
                'role': 'master'
            })

    def test_edit_office_hours_get_public_info(self):
        user = TaCLI.User.User("admin", "master")
        self.di.create_account("admin", "pass", "master")
        self.di.edit_office_hours("admin", "Monday: 1:00PM-2:00PM")

        self.assertEqual(
            self.di.get_public_info(user), {
                'username': '******',
                'name': '',
                'lname': '',
                'email': '',
                'hours': 'MONDAY: 1:00PM-2:00PM ',
                'role': 'master'
            })
예제 #2
0
class LoginTests(TestCase):
    def setUp(self):
        self.di = DjangoModelInterface()

        self.di.create_account("Supervisor", "SupervisorPassword",
                               "supervisor")
        self.di.create_account("Administrator", "AdministratorPassword",
                               "administrator")
        self.di.create_account("Instructor", "InstructorPassword",
                               "instructor")
        self.di.create_account("TA", "TAPassword", "TA")

        self.di.create_course("361", "CompSci361")
        self.di.create_lab("361", "801")

        self.environment = Environment.Environment(self.di, DEBUG=True)
        self.ui = UI.UI(self.environment)

    """
        When the login command is entered, it takes two arguments:
        - Username
        - Password
        If the username and password match a database entry, login is a success:
        - "Logged in."
        If they do not match or are omitted, failure:
        - "Error logging in."
    """

    def test_command_login_correct_super(self):
        self.assertEqual(
            self.ui.command("login", {
                "username": "******",
                "password": "******"
            }), "Logged in.")

    def test_command_login_correct_admin(self):
        self.assertEqual(
            self.ui.command("login", {
                "username": "******",
                "password": "******"
            }), "Logged in.")

    def test_command_login_correct_instructor(self):
        self.assertEqual(
            self.ui.command("login", {
                "username": "******",
                "password": "******"
            }), "Logged in.")

    def test_command_login_no_pass(self):
        self.assertEqual(self.ui.command("login", {"username": "******"}),
                         "Error logging in.")

    def test_command_login_no_args(self):
        self.assertEqual(self.ui.command("login", {}), "Error logging in.")

    def test_command_login_no_args_username(self):
        self.assertEqual(
            self.ui.command("login", {
                "username": "",
                "password": "******"
            }), "Error logging in.")

    def test_command_login_no_args_password(self):
        self.assertEqual(
            self.ui.command("login", {
                "username": "******",
                "password": ""
            }), "Error logging in.")

    def test_command_login_already_logged_in(self):
        self.ui.command("login", {
            "username": "******",
            "password": "******"
        })
        self.assertEqual(
            self.ui.command("login", {
                "username": "******",
                "password": "******"
            }), "Error logging in.")

    """ 
        When logout command is entered, it takes no arguments.
        It logs a user out only if there is one logged in.
        - Success: "Logged out."
        - Failure: "Error logging out."
    """

    def test_command_logout_correct(self):
        self.ui.command("login", {
            "username": "******",
            "password": "******"
        })
        self.assertEqual(self.ui.command("logout", ""), "Logged out.")

    def test_command_logout_not_logged_in(self):
        self.assertEqual(self.ui.command("logout", ""), "Error logging out.")
예제 #3
0
class AssignTests(TestCase):
    def setUp(self):
        self.di = DjangoModelInterface()

        self.di.create_account("Supervisor", "SupervisorPassword", "supervisor")
        self.di.create_account("Administrator", "AdministratorPassword", "administrator")
        self.di.create_account("Instructor", "InstructorPassword", "instructor")
        self.di.create_account("TA", "TAPassword", "TA")

        self.di.create_course("361", "CompSci361")
        self.di.create_lab("361", "801")

        self.environment = Environment.Environment(self.di, DEBUG=True)
        self.ui = UI.UI(self.environment)

    """
        When assign_lab command is entered, it takes two arguments:
        - TA Name
        - Class Number
        The response is a string, either:
        - Success: "Assigned to lab."
        - Failure: "Error assigning to lab."
    """
    def test_assign_lab_by_supervisor_success(self):
        # Command: "assign_lab apoorv 361", expect success
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEqual(self.ui.command("assign_lab", ["assign_lab", "361", "801", "TA"]), "Assigned to lab.")

    def test_assign_lab_by_administrator_fail(self):
        # Command: "assign_lab TA 361", expect success
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEqual(self.ui.command("assign_course", ["assign_course", "361", "TA"]), "ERROR")

    def test_assign_lab_by_ta_fail(self):
        # Command: "assign_lab TA 361 801", expect fail
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEqual(self.ui.command("assign_lab", ["assign_lab", "361", "801", "TA"]), "ERROR")

    def test_assign_lab_no_class_given(self):
        # Command: "assign_lab TA", expect failure (no class given)
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEqual(self.ui.command("assign_lab", ["assign_lab", "TA"]), "ERROR")

    def test_assign_lab_no_args(self):
        # Command: "assign_lab", expect failure (no ta name given)
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEqual(self.ui.command("assign_lab", ["assign_lab"]), "ERROR")

    def test_assign_lab_not_a_ta(self):
        # Command: "assign_lab Instructor 361", expect failure (not a TA)
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEqual(self.ui.command("assign_lab", ["assign_lab", "361", "Instructor"]), "ERROR")

    """
        When assign_course command is entered, it takes two arguments:
        - Instructor Name
        - Class Number
        The response is a string, either:
        - Success: "Assigned to class."
        - Failure: "Error assigning to class."
    """
    def test_assign_course_by_supervisor(self):
        # Command: "assign_course 361 Instructor ", expect success
        self.ui.command("login", {"username": "******", "password": "******"})

        response = self.ui.command("assign_course", ["assign_course", "361", "Instructor"])
        self.assertEqual(response, "Course assigned successfully.")

    def test_assign_course_by_instructor(self):
        # Command: "assign_course 361 Instructor", expect failure
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEqual(self.ui.command("assign_course", ["assign_course", "361", "Instructor"]),
                         "ERROR")

    def test_assign_course_by_ta(self):
        # Command: "assign_course 361 Instructor", expect failure
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEqual(self.ui.command("assign_course", ["assign_course", "361", "Instructor"]), "ERROR")

    def test_assign_course_TA(self):
        # Command: "assign_course 361 TA", expect error (not an instructor)
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEqual(self.ui.command("assign_course", ["assign_course", "361", "TA"]), "Course assigned successfully.")

    def test_assign_course_no_class(self):
        # Command: "assign_course Instructor", expect error (no class given)
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEqual(self.ui.command("assign_course", ["assign_course", "Instructor"]), "ERROR")

    def test_assign_course_no_args(self):
        # Command: "assign_course", expect error (no instructor given)
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEqual(self.ui.command("assign_course", ["assign_course"]), "ERROR")

    """
        When assign_lab command is entered, it takes two arguments:
        - TA Name
        - Class Number
        - Lab Number
        The response is a string, either:
        - Success: "Assigned to lab."
        - Failure: "Error assigning to Lab."
    """
    def test_assign_lab(self):
        # Command: "assign_lab 361 801 TA", expect success
        self.ui.command("login", {"username": "******", "password": "******"})

        response = self.ui.command("assign_lab", ["assign_lab", "361", "801", "TA"])
        self.assertEqual(response, "Assigned to lab.")

    def test_assign_lab_no_class(self):
        # Command: "assign_lab TA", expect failure (no class or lab given)
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEqual(self.ui.command("assign_lab", ["assign_lab", "TA"]), "ERROR")

    def test_assign_lab_bad_args(self):
        # Command: "assign_lab", expect failure (no ta name given)
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEqual(self.ui.command("assign_lab", ["assign_lab", "TA", "361", "801"]), "ERROR")

    def test_assign_lab_not_ta(self):
        # Command: "assign_lab 361 801 Instructor", expect failure (not a TA)
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEqual(self.ui.command("assign_lab", ["assign_lab", "361", "801", "Instructor"]), "ERROR")

    """
        When view_course_assignments command is entered, it takes no arguments
        The response is a string with a line for each course in format
            "{Course Number} {Course Name} {Instructor Name}"
        Fail if the logged in user does not have permission:
            "ERROR"
    """
    def test_view_instructor_assignments_by_supervisor(self):
        self.environment.database.set_course_instructor(361, "Instructor")
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEquals(self.ui.command("view_courses", "")[0]["instructor"], "Instructor")

    def test_view_instructor_assignments_by_administrator(self):
        self.environment.database.set_course_instructor(361, "Instructor")
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEquals(self.ui.command("view_courses", "")[0]["instructor"],
                          "Instructor")

    def test_view_instructor_assignments_by_instructor(self):
        self.environment.database.set_course_instructor(361, "Instructor")
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEquals(self.ui.command("view_courses", "")[0]["instructor"],
                          "Instructor")

    def test_view_instructor_assignments_by_ta(self):
        self.environment.database.set_course_instructor(361, "Instructor")
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEquals(self.ui.command("view_courses", ""),
                          "ERROR")

    """
        When view_lab_assignments command is entered, it takes no arguments
        The response is a string with a line for each course in format
            "{Course Number} {Course Name} lab {Lab Number} {TA Name}"
        Fail if logged in user does not have permissions:
            "Error viewing ta assignments."
    """
    def test_view_ta_assignments_by_supervisor(self):
        self.environment.database.set_lab_assignment(361, 801, "TA")
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEqual(self.ui.command("view_labs", ["view_labs"])[0]["ta"], "TA")

    def test_view_ta_assignments_by_administrator(self):
        self.environment.database.set_lab_assignment(361, 801, "TA")
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEquals(self.ui.command("view_labs", ["view_lab_assignments"])[0]["ta"], "TA")

    def test_view_ta_assignments_by_instructor(self):
        self.environment.database.set_lab_assignment(361, 801, "TA")
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEquals(self.ui.command("view_labs", ["view_lab_assignments"])[0]["ta"], "TA")

    def test_view_ta_assignments_by_ta(self):
        self.environment.database.set_lab_assignment(361, 801, "TA")
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEquals(self.ui.command("view_labs", ["view_lab_assignments"])[0]["ta"], "TA")
예제 #4
0
class CreateAccountTest(TestCase):
    def setUp(self):
        """
            create dummy account for each of the types of users:
            supervisor, administrator, instructor and TA and then
            log them in for their respected tests
        """
        self.di = DjangoModelInterface()

        self.di.create_account("Supervisor", "SupervisorPassword",
                               "supervisor")
        self.di.create_account("Administrator", "AdministratorPassword",
                               "administrator")
        self.di.create_account("Instructor", "InstructorPassword",
                               "instructor")
        self.di.create_account("TA", "TAPassword", "TA")

        self.di.create_course("361", "CompSci361")
        self.di.create_lab("361", "801")

        self.environment = Environment.Environment(self.di, DEBUG=True)
        self.ui = UI.UI(self.environment)
        """
            The supervisor and administrator are able to create accounts
            when create_account command is entered, it expects 3 arguments:
            - email
            - username
            - password
            The response is a string of either:
            - "Account created." if successful
            - "Error creating account." if unsuccessful
    """

    def test_command_create_account_supervisor(self):

        # login as supervisor
        self.ui.command("login", {
            "username": "******",
            "password": "******"
        })
        self.assertEqual(
            self.ui.command("create_account",
                            ["create_account", "john", "password", "TA"]),
            "Account created.")

    def test_command_create_account_administrator(self):

        # login as administrator
        self.ui.command("login", {
            "username": "******",
            "password": "******"
        })
        self.assertEqual(
            self.ui.command(
                "create_account",
                ["create_account", "adam", "password", "supervisor"]),
            "Account created.")

    def test_command_create_account_instructor(self):

        # login as instructor
        self.ui.command("login", {
            "username": "******",
            "password": "******"
        })
        # instructor cannot create accounts
        self.assertEqual(
            self.ui.command(
                "create_account",
                ["create_account", "aaron", "password", "instructor"]),
            "ERROR")

    def test_command_create_account_TA(self):

        # login as TA
        self.ui.command("login", {"username": "******", "password": "******"})
        # TA cannot create accounts
        self.assertEqual(
            self.ui.command(
                "create_account",
                ["create_account", "*****@*****.**", "tim", "password"]), "ERROR")

    def test_command_create_account_format(self):
        # login as administrator
        self.ui.command("login", {
            "username": "******",
            "password": "******"
        })

        self.assertEqual(self.ui.command("create_account", ["create_account"]),
                         "ERROR")
        self.assertEqual(
            self.ui.command("create_account", ["create_account", "tyler"]),
            "ERROR")
        self.assertEqual(
            self.ui.command("create_account", ["create_account", "password"]),
            "ERROR")
        self.assertEqual(
            self.ui.command("create_account",
                            ["create_account", "Administrator", "pass"]),
            "ERROR")

    def test_command_create_account_duplicate(self):
        # login as supervisor
        self.ui.command("login", {
            "username": "******",
            "password": "******"
        })
        self.assertEqual(
            self.ui.command(
                "create_account",
                ["create_account", "userTA", "password", "instructor"]),
            "Account created.")
        self.assertEqual(
            self.ui.command(
                "create_account",
                ["create_account", "userTA", "password", "instructor"]),
            "ERROR")
예제 #5
0
class CreateCourseTests(TestCase):
    def setUp(self):
        self.di = DjangoModelInterface()

        self.di.create_account("Supervisor", "SupervisorPassword",
                               "supervisor")
        self.di.create_account("Administrator", "AdministratorPassword",
                               "administrator")
        self.di.create_account("Instructor", "InstructorPassword",
                               "instructor")
        self.di.create_account("TA", "TAPassword", "TA")

        self.di.create_course("361", "CompSci361")
        self.di.create_lab("361", "801")

        self.environment = Environment.Environment(self.di, DEBUG=True)
        self.ui = UI.UI(self.environment)

    def test_command_create_course_supervisor(self):
        """
            @jkuniqh
            The only ones able to create a course are the supervisor and the administrator

            When create_course command is entered, it expects two arguments (for now, maybe later we can add more details):
             - class number
             - class name
            The response is a string, either:
             - If Successful: "Created course."
             - If Failure: "Error creating course."
        """
        # Create a supervisor account and log in as part of the setup
        self.ui.command("login", {
            "username": "******",
            "password": "******"
        })

        # Command: "create_course 361 SystemsProgramming", expect success
        self.assertEqual(
            self.ui.command("create_course",
                            ["create_course", "337", "SystemsProgramming"]),
            "Course Created Successfully.")

    def test_command_create_course_administrator(self):
        self.ui.command("login", {
            "username": "******",
            "password": "******"
        })
        self.assertEqual(
            self.ui.command("create_course",
                            ["create_course", "337", "SystemsProgramming"]),
            "Course Created Successfully.")

    def test_command_create_course_instructor(self):
        self.ui.command("login", {
            "username": "******",
            "password": "******"
        })
        self.assertEqual(
            self.ui.command("create_course",
                            ["create_course", "361", "SystemsProgramming"]),
            "ERROR")

    def test_command_create_course_TA(self):
        self.ui.command("login", {"username": "******", "password": "******"})
        self.assertEqual(
            self.ui.command("create_course",
                            ["create_course", "361", "SystemsProgramming"]),
            "ERROR")

    def test_command_create_course_format(self):
        # Command: "create_course", expect error, not enough arguments
        self.ui.command("login", {
            "username": "******",
            "password": "******"
        })

        self.assertEqual(self.ui.command("create_course", ["create_course"]),
                         "ERROR")
        self.assertEqual(
            self.ui.command("create_course", ["create_course", "361"]),
            "ERROR")
        self.assertEqual(
            self.ui.command("create_course",
                            ["create_course", "SystemProgramming"]), "ERROR")
        self.assertEqual(
            self.ui.command("create_course",
                            ["create_course", "SystemsProgramming", "361"]),
            "ERROR")

    def test_command_create_course_duplicate(self):
        self.ui.command("login", {
            "username": "******",
            "password": "******"
        })
        self.assertEqual(
            self.ui.command("create_course",
                            ["create_course", "361", "SystemsProgramming"]),
            "ERROR")