def test_create_course(self):
        cmd = SuperUserCommandController()

        userInfo = {
            'data_type': "User",
            'username': "******",
            'name': "Harry",
            'password': "******",
            'role': "Instructor".upper(),
            'email': "*****@*****.**",
            'phone': "4142245326",
            'address': "123 fake st."
        }

        cmd.create("User", userInfo)
        user1 = User.objects.get(username__iexact="HarryPotter")

        courseInfo = {
            'data_type': "Course",
            'course_name': "Intro to CS",
            'course_code': "007",
            'course_instructor': user1
        }

        action = cmd.create("Course", courseInfo)
        result = "Intro to CS created as 007."
        self.assertEqual(result, action)
 def set_pointer_to_app(self, app):
     self.app = app
     self.adminsuper_stuff = SuperUserCommandController()
     self.searcher = Searcher()
     self.UserCommandCntrl = UserCommandController()
     self.CourseCommand = CourseCommandController()
     self.LabCommand = LabSectionCommandController()
Esempio n. 3
0
    def test_edit_user(self):
        scmd = SuperUserCommandController()
        userInfo = {
            'data_type': "User",
            'username': "******",
            'name': "john",
            'password': "******",
            'role': "Instructor".upper(),
            'email': "*****@*****.**",
            'phone': "4142240088",
            'address': "777 fake st."
        }
        scmd.create("User", userInfo)

        newInfo = {
            'data_type': "User",
            'username': "******",
            'name': "Mojo",
            'password': "******",
            'role': "Instructor".upper(),
            'email': "*****@*****.**",
            'phone': "4147771111",
            'address': "777 real st."
        }

        action = cmd.editUser("johnDoe", newInfo)
        result = "User information has been successfully updated"

        self.assertEqual(result, action)
    def test_edit_course_Instructor(self):
        scmd = SuperUserCommandController()
        cmd = CourseCommandController()

        userInfo = {
            'data_type': "User",
            'username': "******",
            'name': "Harry",
            'password': "******",
            'role': "Instructor".upper(),
            'email': "*****@*****.**",
            'phone': "4142245326",
            'address': "123 fake st."
        }

        scmd.create("User", userInfo)
        user1 = User.objects.get(username__iexact="HarryPotter")

        course1 = {
            'data_type': "Course",
            'course_name': "Intro to Comp Sci",
            'course_code': "111",
            'course_instructor': user1
        }
        scmd.create("Course", course1)

        userInfo2 = {
            'data_type': "User",
            'username': "******",
            'name': "john",
            'password': "******",
            'role': "Instructor".upper(),
            'email': "*****@*****.**",
            'phone': "4142240088",
            'address': "1234 fake st."
        }
        scmd.create("User", userInfo2)

        user2 = User.objects.get(username__iexact="johnDoe")

        course2 = {
            'data_type': "Course",
            'course_name': "Intro to Comp Sci",
            'course_code': "111",
            'course_instructor': user2
        }

        scmd.create("Course", course2)

        action = cmd.editCourse(course1['course_name'], course2)
        result = "Course information has been successfully updated"
        self.assertEqual(result, action)
Esempio n. 5
0
    def test_edit_lab_Number(self):
        scmd = SuperUserCommandController()
        lcmd = LabSectionCommandController()

        userInfo = {
            'data_type': "User",
            'username': "******",
            'name': "Harry",
            'password': "******",
            'role': "Instructor".upper(),
            'email': "*****@*****.**",
            'phone': "4142245326",
            'address': "123 fake st."
        }

        scmd.create("User", userInfo)
        user1 = User.objects.get(username__iexact="HarryPotter")

        courseInfo = {
            'data_type': "Course",
            'course_name': "Intro to CS",
            'course_code': "007",
            'course_instructor': user1
        }

        scmd.create("Course", courseInfo)
        course1 = Course.objects.get(course_name__iexact="Intro to CS")

        labInfo = {
            'data_type': "LabSection",
            'lab_ta': user1,
            'lab_number': "007",
            'course_name': course1
        }
        scmd.create("LabSection", labInfo)

        labInfo2 = {
            'data_type': "LabSection",
            'lab_ta': user1,
            'lab_number': "777",
            'course_name': course1
        }
        scmd.create("LabSection", labInfo2)

        action = lcmd.editLabSection(labInfo['lab_number'], labInfo2)

        result = "Lab Section information has been successfully updated"
        self.assertEqual(result, action)
 def test_delete_user(self):
     cmd = SuperUserCommandController()
     userInfo = {
         'data_type': "User",
         'username': "******",
         'name': "john",
         'password': "******",
         'role': "TA".upper(),
         'email': "*****@*****.**",
         'phone': "4142240088",
         'address': "1234 fake st."
     }
     cmd.create("User", userInfo)
     action = cmd.deleteUser("johnDoe")
     result = (userInfo['username'] + " deleted successfully.")
     self.assertEqual(result, action)
    def test_delete_supervisor(self):
        cmd = SuperUserCommandController()
        userInfo = {
            'data_type': "User",
            'username': "******",
            'name': "jojo",
            'password': "******",
            'role': "SUPERVISOR".upper(),
            'email': "*****@*****.**",
            'phone': "4142247777",
            'address': "777 fake st."
        }
        a123 = cmd.create("User", userInfo)
        print(a123)

        action = cmd.deleteUser("admin123")
        result = (userInfo['username'] +
                  " is a Supervisor and cannot be deleted.")
        self.assertEqual(result, action)
    def test_create_lab_already_exists(self):
        scmd = SuperUserCommandController()

        userInfo = {
            'data_type': "User",
            'username': "******",
            'name': "Harry",
            'password': "******",
            'role': "Instructor".upper(),
            'email': "*****@*****.**",
            'phone': "4142245326",
            'address': "123 fake st."
        }

        scmd.create("User", userInfo)
        user1 = User.objects.get(username__iexact="HarryPotter")

        courseInfo = {
            'data_type': "Course",
            'course_name': "Intro to CS",
            'course_code': "007",
            'course_instructor': user1
        }

        scmd.create("Course", courseInfo)
        course1 = Course.objects.get(course_name__iexact="Intro to CS")

        labInfo = {
            'data_type': "LabSection",
            'lab_ta': user1,
            'lab_number': "007",
            'course_name': course1
        }
        scmd.create("Lab", labInfo)

        labInfo2 = {
            'data_type': "LabSection",
            'lab_ta': user1,
            'lab_number': "007",
            'course_name': course1
        }

        action = scmd.create("Lab", labInfo2)
        result = "Lab Section has already been created!"
        self.assertEqual(result, action)
    def test_delete_course_DNE(self):
        scmd = SuperUserCommandController()
        cmd = CourseCommandController()

        userInfo = {
            'data_type': "User",
            'username': "******",
            'name': "Harry",
            'password': "******",
            'role': "Instructor".upper(),
            'email': "*****@*****.**",
            'phone': "4142245326",
            'address': "123 fake st."
        }

        scmd.create("User", userInfo)
        user1 = User.objects.get(username__iexact="HarryPotter")

        course1 = {
            'data_type': "Course",
            'course_name': "Intro to Comp Sci",
            'course_code': "111",
            'course_instructor': user1
        }
        scmd.create("Course", course1)

        action = cmd.deleteCourse("Intro to Computer Science")
        result = "Course could not be found or does not exist."
        self.assertEqual(result, action)
Esempio n. 10
0
    def test_delete_lab_DNE(self):
        scmd = SuperUserCommandController()
        lcmd = LabSectionCommandController

        userInfo = {
            'data_type': "User",
            'username': "******",
            'name': "Harry",
            'password': "******",
            'role': "Instructor".upper(),
            'email': "*****@*****.**",
            'phone': "4142245326",
            'address': "123 fake st."
        }

        scmd.create("User", userInfo)
        user1 = User.objects.get(username__iexact="HarryPotter")

        courseInfo = {
            'data_type': "Course",
            'course_name': "Intro to CS",
            'course_code': "007",
            'course_instructor': user1
        }

        scmd.create("Course", courseInfo)
        course1 = Course.objects.get(course_name__iexact="Intro to CS")

        labInfo = {
            'data_type': "LabSection",
            'lab_ta': user1,
            'lab_number': "007",
            'course_name': course1
        }
        lab1 = scmd.create("Lab", labInfo)


        action = lcmd.deleteLabSection(lab1['lab_number'])
        result = "Failed to delete, Lab Section does not exist!"
        self.assertEqual(result, action)
from Application_Classes.AdminSuperCommandController import SuperUserCommandController
from WebApplication.models import User, Course
from django.test import TestCase

cmd = SuperUserCommandController()


class TestAdminSuperCommandController(TestCase):

    # database testing for create
    def test_User(self):
        with self.assertRaises(Exception):
            User.objects.get(username="******").username
        userInfo = {
            'data_type': "user",
            'username': "******",
            'name': "boyland123",
            'password': "******",
            'role': "TA".upper(),
            'email': "*****@*****.**",
            'phone': "phone",
            'address': "address"
        }
        str = cmd.create("User", userInfo)
        print(str)
        self.assertEqual(
            User.objects.get(username="******").username, 'boyland123')
        self.assertEqual(
            User.objects.get(username="******").password, 'password')
        self.assertTrue(
            User.objects.get(
Esempio n. 12
0
class CommandController(object):
    def set_pointer_to_app(self, app):
        self.app = app
        self.adminsuper_stuff = SuperUserCommandController()
        self.searcher = Searcher()
        self.UserCommandCntrl = UserCommandController()
        self.CourseCommand = CourseCommandController()
        self.LabCommand = LabSectionCommandController()

    # takes the command and variables and runs the correct function
    def parse(self, command, table_data):
        if command == 'create':
            creation_type = table_data['data_type']
            return self.adminsuper_stuff.create(creation_type, table_data)
        elif command == 'login':
            username = table_data['username']
            password = table_data['password']
            return self.login(username, password)
        elif command == 'search':
            return self.searcher.searchuser(table_data)
        elif command == 'searchCourse':
            return self.searcher.searchCourse(table_data)
        elif command == 'searchLab':
            return self.searcher.searchLabSection(table_data)
        elif command == 'editUser':
            username = table_data['username']
            return self.UserCommandCntrl.editUser(username, table_data)
        elif command == 'deleteAccount':
            username = table_data['username']
            return self.adminsuper_stuff.deleteUser(username)
        elif command == 'editCourse':
            course_name = table_data['course_name']
            return self.CourseCommand.editCourse(course_name, table_data)
        elif command == 'editLab':
            lab_number = table_data['lab_id']
            return self.LabCommand.editLabSection(lab_number, table_data)
        elif command == 'deleteCourse':
            course_name = table_data['course_name']
            return self.CourseCommand.deleteCourse(course_name)
        elif command == 'deleteLab':
            lab_number = table_data['lab_id']
            return self.LabCommand.deleteLabSection(lab_number)

    # returns the user as a list by username
    def get_user_by_username(self, username):
        user_object = User.objects.filter(username__iexact=username)
        if user_object.count() == 0:
            return None
        else:
            return user_object.values()[0]

    # returns the course as a list by name
    def get_course_by_name(self, name):
        course_object = Course.objects.filter(course_name__iexact=name)
        if course_object.count() == 0:
            return None
        else:
            return course_object.values()[0]

    # returns the lab as a list by id
    def get_lab(self, number):
        lab_object = LabSection.objects.filter(id=number)
        if lab_object.count() == 0:
            return None
        else:
            return lab_object.values()[0]

    # return the user object by username
    def get_user_object(self, username):
        if username == "None":
            return None

        user_object = User.objects.get(username__iexact=username)
        return user_object

    # returns the user object by id
    def get_user_object_byid(self, id):
        if id is None:
            return None

        user_object = User.objects.get(id=id)
        return user_object

    # returns the course object by name
    def get_course_object(self, course_name):
        if course_name == "None":
            return None

        course_object = Course.objects.get(course_name=course_name)
        return course_object

    # returns the lab object by id
    def get_lab_object(self, lab_number):
        if lab_number == "None":
            return None

        lab_object = LabSection.objects.get(id=lab_number)
        return lab_object

    # performs the login and verifies the username and password
    def login(self, username, password):
        # try to grab user
        try:
            user_logging_in = User.objects.get(username__iexact=username)

            if user_logging_in.password == password:
                # everything looks good!
                response = "Correct login"
            else:
                # password is incorrect
                response = "Incorrect password."

        except User.DoesNotExist:
            # user does not exist
            response = "Username does not exist."

        return response

    # grabs an overall count of all the objects for the homepage
    def get_database_count(self):
        objects = {
            'num_users': User.objects.all().count(),
            'num_courses': Course.objects.all().count(),
            'num_labs': LabSection.objects.all().count()
        }

        return objects