Ejemplo n.º 1
0
 def setUp(self):
     self.ui = CmdHandler()
     self.ui.parse_command("setup")
     self.ui.parse_command("login [email protected] password")
     self.ui.parse_command(
         "create_account [email protected] password instructor")
     self.ui.parse_command("create_account [email protected] password ta")
     self.ui.parse_command("logout")
Ejemplo n.º 2
0
class LoginTests(TestCase):
    def setUp(self):
        self.ui = CmdHandler()

    def test_login(self):

        self.ui.parse_command("setup")
        client = Client()
        response = client.post("/login/",
                               data={
                                   'email': "*****@*****.**",
                                   'password': "******"
                               },
                               follow="true")
        session = client.session
        self.assertEqual(session["email"], "*****@*****.**")
        self.assertEqual(session["type"], "supervisor")
        self.assertEqual(response.status_code, 200)

    def test_bad_login(self):

        self.ui.parse_command("setup")
        client = Client()
        response = client.post("/login/",
                               data={
                                   'email': "*****@*****.**",
                                   'password': "******"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "username/password incorrect")

    def test_bad_password_login(self):

        self.ui.parse_command("setup")
        client = Client()
        response = client.post("/login/",
                               data={
                                   'email': "*****@*****.**",
                                   'password': "******"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "username/password incorrect")

    def test_already_login(self):

        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.get('/login/')
        self.assertEqual(response.get('location'), '/index/')
class CreateAccessInfo(TestCase):
    def setUp(self):
        self.ui = CmdHandler()

    def test_no_login_get(self):

        client = Client()
        response = client.get('/view_ta_assign/')
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message, "Please login first.")
        self.assertEqual(response.get('location'), '/login/')

    def test_admin_get(self):

        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.get('/view_ta_assign/')
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message,
                         "You do not have access to this page.")
        self.assertEqual(response.get('location'), '/index/')

    def test_super_get(self):

        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.get('/view_ta_assign/')
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message,
                         "You do not have access to this page.")
        self.assertEqual(response.get('location'), '/index/')

    def test_view_ta_assign_instructor(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'instructor'
        session.save()
        response = client.get('/view_ta_assign/')
        self.assertEqual(response.status_code, 200)
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        info_string = str(all_messages)
        self.assertEqual(info_string, "[]")

    def test_view_ta_assign_ta(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'ta'
        session.save()
        response = client.get('/view_ta_assign/')
        self.assertEqual(response.status_code, 200)
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        info_string = str(all_messages[0])
        self.assertEqual(info_string,
                         "TA: DEFAULT | [email protected] | 000.000.0000\n\n")

    def test_view_ta_assign_instructor_no_ta(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'instructor'
        session.save()
        response = client.get('/view_ta_assign/')
        self.assertEqual(response.status_code, 200)
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        info_string = str(all_messages)
        self.assertEqual(info_string, "[]")

    def test_view_ta_assign_ta_no_class(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'ta'
        session.save()
        response = client.get('/view_ta_assign/')
        self.assertEqual(response.status_code, 200)
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        info_string = str(all_messages[0])
        self.assertEqual(info_string,
                         "TA: DEFAULT | [email protected] | 000.000.0000\n\n")

    def test_view_ta_assign_inst_one_course(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("create_course CS101-401 0")
        self.ui.parse_command("assign_ta [email protected] CS101-401")
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'instructor'
        session.save()
        response = client.get('/view_ta_assign/')
        self.assertEqual(response.status_code, 200)
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        info_string = str(all_messages[0])
        self.assertEqual(
            info_string,
            "TA: DEFAULT | [email protected] | 000.000.0000\n\tCourse: CS101-401\n\n")

    def test_view_ta_assign_ta_one_course(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("create_course CS101-401 0")
        self.ui.parse_command("assign_ta [email protected] CS101-401")
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'ta'
        session.save()
        response = client.get('/view_ta_assign/')
        self.assertEqual(response.status_code, 200)
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        info_string = str(all_messages[0])
        self.assertEqual(
            info_string,
            "TA: DEFAULT | [email protected] | 000.000.0000\n\tCourse: CS101-401\n\n")

    def test_view_ta_assign_all_the_things(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("create_course CS101-401 0")
        self.ui.parse_command("create_course CS102-401 0")
        self.ui.parse_command("assign_instructor [email protected] CS101-401")
        self.ui.parse_command("assign_instructor [email protected] CS102-401")
        self.ui.parse_command("assign_ta [email protected] CS101-401")
        self.ui.parse_command("assign_ta [email protected] CS102-401")
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'ta'
        session.save()
        response = client.get('/view_ta_assign/')
        self.assertEqual(response.status_code, 200)
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        info_string = str(all_messages[0])
        self.assertEqual(
            info_string, "TA: DEFAULT | [email protected] | 000.000.0000\n\n"
            "TA: DEFAULT | [email protected] | 000.000.0000\n"
            "\tCourse: CS101-401\n\n"
            "TA: DEFAULT | [email protected] | 000.000.0000\n"
            "\tCourse: CS102-401\n\n")
Ejemplo n.º 4
0
class EditInfoTests(TestCase):

    def setUp(self):
        self.ui = CmdHandler()

    def test_no_login_get(self):

        client = Client()
        response = client.get('/edit_info/')
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message, "Please login first.")
        self.assertEqual(response.get('location'), '/login/')

    def test_admin_get(self):

        self.ui.parse_command("setup")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.get('/edit_info/')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(len(all_messages), 0)

    def test_super_get(self):

        self.ui.parse_command("setup")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.get('/edit_info/')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(len(all_messages), 0)

    def test_instructor_get(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'instructor'
        session.save()
        response = client.get('/edit_info/')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(len(all_messages), 0)

    def test_ta_get(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'ta'
        session.save()
        response = client.get('/edit_info/')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(len(all_messages), 0)

    def test_admin_change_email(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.post('/edit_info/', data={'email': "*****@*****.**", 'password': "", 'name': "",
                                                    'phone': ""}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Email address changed.")

    def test_super_change_email(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.post('/edit_info/', data={'email': "*****@*****.**", 'password': "", 'name': "",
                                                    'phone': ""}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Email address changed.")

    def test_instructor_change_email(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'instructor'
        session.save()
        response = client.post('/edit_info/', data={'email': "*****@*****.**", 'password': "", 'name': "",
                                                    'phone': ""}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Email address changed.")

    def test_ta_change_email(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'ta'
        session.save()
        response = client.post('/edit_info/', data={'email': "*****@*****.**", 'password': "", 'name': "",
                                                    'phone': ""}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Email address changed.")

    def test_bad_email(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.post('/edit_info/', data={'email': "*****@*****.**", 'password': "", 'name': "",
                                                    'phone': ""}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Invalid/taken email address.")

    def test_weird_email(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.post('/edit_info/', data={'email': "[email protected]@uwm.edu", 'password': "", 'name': "",
                                                    'phone': ""}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Invalid/taken email address.")

    def test_taken_email(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.post('/edit_info/', data={'email': "*****@*****.**", 'password': "", 'name': "",
                                                    'phone': ""}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Invalid/taken email address.")

    def test_admin_change_password(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.post('/edit_info/', data={'email': "", 'password': "******", 'name': "",
                                                    'phone': ""}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Password changed.")

    def test_super_change_password(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.post('/edit_info/', data={'email': "", 'password': "******", 'name': "",
                                                    'phone': ""}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Password changed.")

    def test_instructor_change_password(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'instructor'
        session.save()
        response = client.post('/edit_info/', data={'email': "", 'password': "******", 'name': "",
                                                    'phone': ""}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Password changed.")

    def test_ta_change_password(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'ta'
        session.save()
        response = client.post('/edit_info/', data={'email': "", 'password': "******", 'name': "",
                                                    'phone': ""}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Password changed.")

    def test_admin_change_name(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.post('/edit_info/', data={'email': "", 'password': "", 'name': "Admin",
                                                    'phone': ""}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Name changed.")

    def test_super_change_name(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.post('/edit_info/', data={'email': "", 'password': "", 'name': "Super",
                                                    'phone': ""}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Name changed.")

    def test_instructor_change_name(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'instructor'
        session.save()
        response = client.post('/edit_info/', data={'email': "", 'password': "", 'name': "Instructor",
                                                    'phone': ""}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Name changed.")

    def test_ta_change_name(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'ta'
        session.save()
        response = client.post('/edit_info/', data={'email': "", 'password': "", 'name': "TA",
                                                    'phone': ""}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Name changed.")

    def test_big_name(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.post('/edit_info/', data={'email': "", 'password': "", 'name': "Jim Joe Bob Henry Bob Bob",
                                                    'phone': ""}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Name changed.")

    def test_admin_change_phone(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.post('/edit_info/', data={'email': "", 'password': "", 'name': "",
                                                    'phone': "414.867.5309"}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Phone number changed.")

    def test_super_change_phone(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.post('/edit_info/', data={'email': "", 'password': "", 'name': "",
                                                    'phone': "414.867.5309"}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Phone number changed.")

    def test_instructor_change_phone(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'instructor'
        session.save()
        response = client.post('/edit_info/', data={'email': "", 'password': "", 'name': "",
                                                    'phone': "414.867.5309"}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Phone number changed.")

    def test_ta_change_phone(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'ta'
        session.save()
        response = client.post('/edit_info/', data={'email': "", 'password': "", 'name': "",
                                                    'phone': "414.867.5309"}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Phone number changed.")

    def test_bad_phone(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.post('/edit_info/', data={'email': "", 'password': "", 'name': "",
                                                    'phone': "414-867-5309"}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Invalid phone format.")

    def test_bad_phone_two(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.post('/edit_info/', data={'email': "", 'password': "", 'name': "",
                                                    'phone': "4148675309"}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Invalid phone format.")

    def test_nothing(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.post('/edit_info/', data={'email': "", 'password': "", 'name': "",
                                                    'phone': ""}, follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "You should pick something to change.")
Ejemplo n.º 5
0
class CreateAccountTests(TestCase):
    def setUp(self):
        self.ui = CmdHandler()

    def test_no_login_get(self):

        client = Client()
        response = client.get('/create_account/')
        # this gets any messages
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        # this should be the first and only message, tagged error
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message, "Please login first.")
        # since we returned a redirect, we can check the location
        self.assertEqual(response.get('location'), '/login/')

    def test_admin_get(self):

        client = Client()
        # make a session, email and type are all you need
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        # save the session
        session.save()
        response = client.get('/create_account/')
        # status code 200, we loaded the correct page
        self.assertEqual(response.status_code, 200)
        # since we returned a render, it has all the content of the page
        # we'll just look for the header
        self.assertContains(response, "Create Account")
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        # no error messages
        self.assertEqual(len(all_messages), 0)

    def test_super_get(self):

        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.get('/create_account/')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Account")
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(len(all_messages), 0)

    def test_instructor_get(self):

        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'instructor'
        session.save()
        response = client.get('/create_account/')
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message,
                         "You do not have access to this page.")
        self.assertEqual(response.get('location'), '/index/')

    def test_ta_get(self):

        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'ta'
        session.save()
        response = client.get('/create_account/')
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message,
                         "You do not have access to this page.")
        self.assertEqual(response.get('location'), '/index/')

    def test_admin_create_ta(self):

        # we still need to have some sort of setup on tests, the command handler still gets this
        # done easiest right now
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.post('/create_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'password': "******",
                                   'type': "ta"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Account")
        self.assertContains(response, "Account created!")

    def test_admin_create_instructor(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.post('/create_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'password': "******",
                                   'type': "instructor"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Account")
        self.assertContains(response, "Account created!")

    def test_super_create_ta(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.post('/create_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'password': "******",
                                   'type': "ta"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Account")
        self.assertContains(response, "Account created!")

    def test_super_create_instructor(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.post('/create_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'password': "******",
                                   'type': "instructor"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Account")
        self.assertContains(response, "Account created!")

    def test_bad_email(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.post('/create_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'password': "******",
                                   'type': "ta"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Account")
        self.assertContains(response, "Account creation error.")

    def test_no_email(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.post('/create_account/',
                               data={
                                   'email': "",
                                   'password': "******",
                                   'type': "ta"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Account")
        self.assertContains(response, "Parameter error.")

    def test_no_password(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.post('/create_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'password': "",
                                   'type': "ta"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Account")
        self.assertContains(response, "Parameter error.")

    def test_email_already_exists(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.post('/create_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'password': "******",
                                   'type': "ta"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Account")
        self.assertContains(response, "Account created!")
        response = client.post('/create_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'password': "******",
                                   'type': "ta"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Account")
        self.assertContains(response, "Account creation error.")

    def test_weird_email(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.post('/create_account/',
                               data={
                                   'email': "[email protected][email protected]",
                                   'password': "******",
                                   'type': "ta"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Account")
        self.assertContains(response, "Account creation error.")
class EditAccountTests(TestCase):
    def setUp(self):
        self.ui = CmdHandler()
        """
        Admins and supervisors have permission to edit accounts
        edit_account takes 3 arguments
            -username
            -type of info to update
            -new info
        if account edit is successful
            -"account edited" displayed
        if permission not granted
            -"do not have permission to edit accounts" displayed
        if # arguments invalid
            -"invalid number of arguments" displayed
        if data type invalid
            -"invalid data to edit"
        """

    def test_edit_admin(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] password new_password"),
            "Command successful.")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] name Dr. John Tang Boyland"
            ), "Command successful.")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] phone_number 999.999.9999"
            ), "Command successful.")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] email [email protected]"
            ), "Command successful.")

    def test_edit_sup(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] password new_password"),
            "Command successful.")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] name Dr. John Tang Boyland"
            ), "Command successful.")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] phone_number 999.999.9999"
            ), "Command successful.")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] email [email protected]"
            ), "Command successful.")

    def test_edit_TA_as_admin(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] password new_password"),
            "Command successful.")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] name Dr. John Tang Boyland"),
            "Command successful.")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] phone_number 999.999.9999"),
            "Command successful.")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] email [email protected]"),
            "Command successful.")

    def test_edit_TA_as_super(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] password new_password"),
            "Command successful.")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] name Dr. John Tang Boyland"),
            "Command successful.")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] phone_number 999.999.9999"),
            "Command successful.")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] email [email protected]"),
            "Command successful.")

    def test_edit_ins_as_admin(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] password new_password"),
            "Command successful.")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] name Dr. John Tang Boyland"),
            "Command successful.")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] phone_number 999.999.9999"),
            "Command successful.")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] email [email protected]"),
            "Command successful.")

    def test_edit_ins_as_super(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] password new_password"),
            "Command successful.")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] name Dr. John Tang Boyland"),
            "Command successful.")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] phone_number 999.999.9999"),
            "Command successful.")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] email [email protected]"),
            "Command successful.")

    def test_edit_as_ta(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] email [email protected]"),
            "Invalid command")

    def test_edit_as_ins(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] email [email protected]"),
            "Invalid command")

    def test_edit_noargs(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("edit_account"),
                         "Invalid command")

    def test_edit_invalid_args(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command(
                "edit_account [email protected] jajajaj new_password"),
            "Command error.")
Ejemplo n.º 7
0
class AssignTACourse(TestCase):
    def setUp(self):
        self.ui = CmdHandler()

    def test_assign_ta_no_setup(self):
        self.assertEqual(
            self.ui.parse_command("assign_instructor [email protected] CS201-401"),
            "Please run setup before attempting to execute commands.")

    def test_assign_ta_no_login(self):
        self.ui.parse_command("setup")
        self.assertEqual(
            self.ui.parse_command("assign_instructor [email protected] CS201-401"),
            "Please login first.")

    def test_assign_ta_course_sup(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("create_course CS201-401 3")
        self.assertEqual(
            self.ui.parse_command("assign_ta [email protected] CS201-401"),
            "command successful")

    def test_assign_ta_course_ins(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("create_course CS201-401 3")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("assign_ta [email protected] CS201-401"),
            "Access Denied")

    def test_assign_instructor_administrator(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("assign_ta [email protected] CS201-401"),
            "Access Denied")

    def test_assign_instructor_TA(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] TAPassword ta")
        self.ui.parse_command("create_course CS201-401 3")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] TAPassword")
        self.assertEqual(
            self.ui.parse_command("assign_ta [email protected] CS201-401"),
            "Access Denied")

    def test_assign_ta_course_course_dne(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.assertEqual(
            self.ui.parse_command("assign_ta [email protected] CS400-601"),
            "no such course")

    def test_assign_ta_course_ta_dne(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_course CS400-601 4")
        self.assertEqual(
            self.ui.parse_command("assign_ta [email protected] CS400-601"),
            "no such ta")

    def test_assign_ta_course_num_args(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("assign_ta [email protected]"),
                         "Incorrect Command")

    def test_assign_ta_course_non_ta(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.assertEqual(
            self.ui.parse_command("assign_ta [email protected] CS201-401"),
            "no such ta")
Ejemplo n.º 8
0
class AssignInstructorTests(TestCase):
    def setUp(self):
        self.ui = CmdHandler()

    """
        Assigning an instructor requires user logged in as Supervisor or Administrator.
        When the create account command is entered, it takes two arguments:
            - Instructor ID
            - Course ID
        If the course does not currently have an instructor, assigns instructor to that course and
        is successful:
        - "Instructor *Instructor Name* assigned to class *Class Name*."
        If the course is already assigned to an instructor then failure:
        - "*Class Name* already has an instructor."
        If the Instructor ID or Course ID is omitted, failure:
        - "Invalid arguments in command."
        If attempting to assign a role that is not instructor, failure:
        - "Only instructors can be assigned to classes."
        If the user is not logged in as a Supervisor or Administrator, failure:
        - "You are not authorized to assign instructors."
        If an invalid email address is used for the instructor, failure:
        - "Invalid email address."
        If the course entered does not exist, failure:
        - "Course does not exist."
        If the instructor entered does not exist, failure:
        - "Instructor does not exist."
    """

    def test_assign_instructor_no_setup(self):
        self.assertEqual(
            self.ui.parse_command("assign_instructor [email protected] CS201-401"),
            "Please run setup before attempting to execute commands.")

    def test_assign_instructor_no_login(self):
        self.ui.parse_command("setup")
        self.assertEqual(
            self.ui.parse_command("assign_instructor [email protected] CS201-401"),
            "Please login first.")

    def test_assign_instructor_supervisor(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("create_course CS201-401 3")
        self.assertEqual(
            self.ui.parse_command("assign_instructor [email protected] CS201-401"),
            "command successful")

    def test_assign_instructor_administrator(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command(
                "assign_instructor [email protected] CS201-401"),
            "Access Denied")

    def test_assign_instructor_instructor(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("create_course CS201-401 3")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("assign_instructor [email protected] CS201-401"),
            "Access Denied")

    def test_assign_instructor_TA(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] TAPassword ta")
        self.ui.parse_command("create_course CS201-401 3")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] TAPassword")
        self.assertEqual(
            self.ui.parse_command("assign_instructor [email protected] CS201-401"),
            "Access Denied")

    def test_assign_instructor_invalid_arguments(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("assign_instructor [email protected]"),
            "Incorrect Command")

    def test_assign_instructor_assign_TA(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.assertEqual(
            self.ui.parse_command("assign_instructor [email protected] CS201-401"),
            "no such instructor")

    def test_invalid_email(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("assign_instructor ins1, SomeCSClass3"),
            "no such instructor")

    def test_nonexistent_course(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.assertEqual(
            self.ui.parse_command("assign_instructor [email protected] CS400-601"),
            "no such course")
class CreateCourseTests(TestCase):
    def setUp(self):
        self.ui = CmdHandler()

    """
    When the create course cmd is entered, it takes < 3 > arguments:
    - Course ID
    - Number of Labs
    If Title and lab fields are filled in, create course is a success:
    - "Created course *Course* with *x* labs."
    If user is not an Administrator or Instructor, failure:
    - "You are not authorized to create courses."
    If Title field is omitted, failure:
    - "Error creating course."
    If Instructor field is omitted, failure:
    - "Error creating course."
    If Title already exists, failure:
    - "Course already exists."
    """

    def test_create_course_admin(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("create_course CS361-401 3"),
                         "CS361-401 has been created successfully.")

    def test_create_course_supervisor(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("create_course CS361-401 3"),
                         "CS361-401 has been created successfully.")

    def test_create_course_instructor(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("create_course CS361-401 3"),
            "Yeah, you don't have access to that command. Nice try buddy.")

    def test_create_course_ta(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("create_course CS361-401 3"),
            "Yeah, you don't have access to that command. Nice try buddy.")

    def test_create_course_no_title(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("create_course 3"),
            "Command not of the right format: [create_course CS###-### #]")

    def test_command_create_course_no_num_labs(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("create_course CS361-401"),
            "Command not of the right format: [create_course CS###-### #]")

    def test_command_create_course_already_exists(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_course CS361-401 3")
        self.assertEqual(self.ui.parse_command("create_course CS361-401 3"),
                         "An error occurred")
Ejemplo n.º 10
0
class ViewInfoTests(TestCase):
    def setUp(self):
        self.ui = CmdHandler()

    def test_view_info_no_setup(self):
        self.assertEqual(
            self.ui.parse_command("view_info"),
            "Please run setup before attempting to execute commands.")

    def test_command_view_info_no_login(self):
        self.ui.parse_command("setup")
        self.assertEqual(self.ui.parse_command("view_info"),
                         "Please login first.")

    def test_command_view_info_admin(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("view_info"),
            ["*****@*****.**", "password", "DEFAULT", "000.000.0000"])

    def test_command_view_info_super(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("view_info"),
            ["*****@*****.**", "password", "DEFAULT", "000.000.0000"])

    def test_command_view_info_instructor(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("view_info"),
            ["*****@*****.**", "password", "DEFAULT", "000.000.0000"])

    def test_command_view_info_ta(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("view_info"),
                         ["*****@*****.**", "password", "DEFAULT", "000.000.0000"])
Ejemplo n.º 11
0
class CreateAccessInfo(TestCase):
    def setUp(self):
        self.ui = CmdHandler()

    def test_no_login_get(self):

        client = Client()
        response = client.get('/access_info/')
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message, "Please login first.")
        self.assertEqual(response.get('location'), '/login/')

    def test_instructor_get(self):

        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'instructor'
        session.save()
        response = client.get('/access_info/')
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message,
                         "You do not have access to this page.")
        self.assertEqual(response.get('location'), '/index/')

    def test_ta_get(self):

        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'ta'
        session.save()
        response = client.get('/access_info/')
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message,
                         "You do not have access to this page.")
        self.assertEqual(response.get('location'), '/index/')

    def test_access_info_admin(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.get('/access_info/')
        self.assertEqual(response.status_code, 200)
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        big_string = str(all_messages[0])
        parse_string = big_string.split("\n")
        self.assertEqual(parse_string[0], "Administrator:")
        self.assertEqual(parse_string[1],
                         "DEFAULT | [email protected] | 000.000.0000")
        self.assertEqual(parse_string[2], "")
        self.assertEqual(parse_string[3], "Supervisor:")
        self.assertEqual(parse_string[4],
                         "DEFAULT | [email protected] | 000.000.0000")

    def test_access_info_super(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.get('/access_info/')
        self.assertEqual(response.status_code, 200)
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        big_string = str(all_messages[0])
        parse_string = big_string.split("\n")
        self.assertEqual(parse_string[0], "Administrator:")
        self.assertEqual(parse_string[1],
                         "DEFAULT | [email protected] | 000.000.0000")
        self.assertEqual(parse_string[2], "")
        self.assertEqual(parse_string[3], "Supervisor:")
        self.assertEqual(parse_string[4],
                         "DEFAULT | [email protected] | 000.000.0000")

    def test_access_info_instructor_no_class(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.get('/access_info/')
        self.assertEqual(response.status_code, 200)
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        big_string = str(all_messages[0])
        parse_string = big_string.split("\n")
        self.assertEqual(parse_string[6], "Instructors:")
        self.assertEqual(parse_string[7],
                         "DEFAULT | [email protected] | 000.000.0000")

    def test_access_info_ta_no_class(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.get('/access_info/')
        self.assertEqual(response.status_code, 200)
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        big_string = str(all_messages[0])
        parse_string = big_string.split("\n")
        self.assertEqual(parse_string[8], "TAs:")
        self.assertEqual(parse_string[9],
                         "DEFAULT | [email protected] | 000.000.0000")

    def test_access_info_inst_one_course(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("create_course CS101-401 0")
        self.ui.parse_command("assign_instructor [email protected] CS101-401")
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.get('/access_info/')
        self.assertEqual(response.status_code, 200)
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        big_string = str(all_messages[0])
        parse_string = big_string.split("\n")
        self.assertEqual(parse_string[8], "\tCourse: CS101-401")

    def test_access_info_ta_one_course(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("create_course CS101-401 0")
        self.ui.parse_command("assign_ta [email protected] CS101-401")
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.get('/access_info/')
        self.assertEqual(response.status_code, 200)
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        big_string = str(all_messages[0])
        parse_string = big_string.split("\n")
        self.assertEqual(parse_string[10], "\tCourse: CS101-401")

    def test_access_info_just_course(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("create_course CS101-401 0")
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.get('/access_info/')
        self.assertEqual(response.status_code, 200)
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        big_string = str(all_messages[0])
        parse_string = big_string.split("\n")
        self.assertEqual(parse_string[12], "Courses:")
        self.assertEqual(parse_string[13], "CS101-401")

    def test_access_info_all_the_things(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("create_course CS101-401 0")
        self.ui.parse_command("create_course CS102-401 0")
        self.ui.parse_command("assign_instructor [email protected] CS101-401")
        self.ui.parse_command("assign_instructor [email protected] CS102-401")
        self.ui.parse_command("assign_ta [email protected] CS101-401")
        self.ui.parse_command("assign_ta [email protected] CS102-401")
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.get('/access_info/')
        self.assertEqual(response.status_code, 200)
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        big_string = str(all_messages[0])
        parse_info = big_string.split("\n")
        self.assertEqual(parse_info[0], "Administrator:")
        self.assertEqual(parse_info[1],
                         "DEFAULT | [email protected] | 000.000.0000")
        self.assertEqual(parse_info[2], "")
        self.assertEqual(parse_info[3], "Supervisor:")
        self.assertEqual(parse_info[4],
                         "DEFAULT | [email protected] | 000.000.0000")
        self.assertEqual(parse_info[5], "")
        self.assertEqual(parse_info[6], "Instructors:")
        self.assertEqual(parse_info[7],
                         "DEFAULT | [email protected] | 000.000.0000")
        self.assertEqual(parse_info[8], "\tCourse: CS101-401")
        self.assertEqual(parse_info[9], "")
        self.assertEqual(parse_info[10],
                         "DEFAULT | [email protected] | 000.000.0000")
        self.assertEqual(parse_info[11], "\tCourse: CS102-401")
        self.assertEqual(parse_info[12], "")
        self.assertEqual(parse_info[13], "")
        self.assertEqual(parse_info[14], "TAs:")
        self.assertEqual(parse_info[15],
                         "DEFAULT | [email protected] | 000.000.0000")
        self.assertEqual(parse_info[16], "\tCourse: CS101-401")
        self.assertEqual(parse_info[17], "")
        self.assertEqual(parse_info[18],
                         "DEFAULT | [email protected] | 000.000.0000")
        self.assertEqual(parse_info[19], "\tCourse: CS102-401")
        self.assertEqual(parse_info[20], "")
        self.assertEqual(parse_info[21], "")
        self.assertEqual(parse_info[22], "Courses:")
        self.assertEqual(parse_info[23], "CS101-401")
        self.assertEqual(parse_info[24], "CS102-401")
Ejemplo n.º 12
0
class LogoutTests(TestCase):
    def setUp(self):
        self.ui = CmdHandler()

    """
    When a user wants to logout no arguments are required 
    if logout works properly
        -"logout successful"
    if logout does not work
        -"logout failed"
    """

    def test_logout_Admin(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("login [email protected] ADMIN")
        self.assertTrue(self.ui.parse_command("logout"))

    def test_logout_TA(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("login [email protected] TA")
        self.assertTrue(self.ui.parse_command("logout"))

    def test_logout_Instructor(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("login [email protected] INS")
        self.assertTrue(self.ui.parse_command("logout"))

    def test_logout_Supervisor(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("login [email protected] SUP")
        self.assertTrue(self.ui.parse_command("logout"))

    def test_invalid_logout(self):
        self.ui.parse_command("setup")
        self.assertEqual(self.ui.parse_command("logout"),
                         "Please login first.")
Ejemplo n.º 13
0
class LoginTests(TestCase):
    def setUp(self):
        self.ui = CmdHandler()
    """
    When a user wants to login two arguments are required
        -Username
        -password
    the password must match the password for the given username
    if login is successful
        -"login successful" displayed"
    if password is incorrect
        -"password invalid" displayed
    if username does not exist
        -"no such user" displayed
    """

    def test_valid_login_Admin(self):
        self.ui.parse_command("setup")
        self.assertEqual(self.ui.parse_command("login [email protected] password"), "Login successful")
        self.assertEqual(self.ui.parse_command("login [email protected] password"), "User already logged in")
        self.ui.parse_command("logout")
        self.assertEqual(self.ui.parse_command("login [email protected] wrong"), "Invalid login info")

    def test_valid_login_TA(self):
        self.ui.parse_command("setup")
        self.assertEqual(self.ui.parse_command("login [email protected] password"), "Login successful")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("logout")
        self.assertEqual(self.ui.parse_command("login [email protected] password"), "Login successful")
        self.ui.parse_command("logout")
        self.assertEqual(self.ui.parse_command("login [email protected] wrong"), "Invalid login info")

    def test_valid_login_Instructor(self):
        self.ui.parse_command("setup")
        self.assertEqual(self.ui.parse_command("login [email protected] password"), "Login successful")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.assertEqual(self.ui.parse_command("login [email protected] wrong"), "Invalid login info")
        self.assertEqual(self.ui.parse_command("login [email protected] password"), "Login successful")
        self.ui.parse_command("logout")

    def test_valid_login_Supervisor(self):
        self.ui.parse_command("setup")
        self.assertEqual(self.ui.parse_command("login [email protected] password"), "Login successful")
        self.assertEqual(self.ui.parse_command("login [email protected] password"), "User already logged in")
        self.ui.parse_command("logout")
        self.assertEqual(self.ui.parse_command("login [email protected] wrong"), "Invalid login info")
class CreateAccountTests(TestCase):
    def setUp(self):
        self.ui = CmdHandler()

    """
        Account creation requires user logged in as Supervisor or Administrator.
        When the create account command is entered, it takes three arguments:
            - Username
            - Password
            - email address
        If the username and password do not already exist in the database, account creation
        is successful.
        If the username is already taken, failure.
        If the username or password is omitted, failure.
        If the user is not logged in as a Supervisor or Administrator, failure.
    """

    def test_command_create_account_no_setup(self):
        self.assertEqual(
            self.ui.parse_command("create_account [email protected] password ta"),
            "Please run setup before attempting to execute commands.")

    def test_command_create_account_no_login(self):
        self.ui.parse_command("setup")
        self.assertEqual(
            self.ui.parse_command("create_account [email protected] password ta"),
            "Please login first.")

    def test_command_create_account_supervisor_make_ta(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("create_account [email protected] password ta"),
            "Account created!")

    def test_command_create_account_administrator_make_ta(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("create_account [email protected] password ta"),
            "Account created!")

    def test_command_create_account_supervisor_make_instructor(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command(
                "create_account [email protected] password instructor"),
            "Account created!")

    def test_command_create_account_administrator_make_instructor(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command(
                "create_account [email protected] password instructor"),
            "Account created!")

    def test_command_create_account_instructor(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("create_account [email protected] password ta"),
            "Invalid command.")

    def test_command_create_account_ta(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command(
                "create_account [email protected] password instructor"),
            "Invalid command.")

    def test_command_create_account_already_exists(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.assertEqual(
            self.ui.parse_command("create_account [email protected] password ta"),
            "Account creation error.")

    def test_command_create_account_invalid_type(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("create_account [email protected] password horse"),
            "Account creation error.")

    def test_command_create_account_invalid_email(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("create_account [email protected] password horse"),
            "Account creation error.")

    def test_command_create_account_weird_email(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command(
                "create_account [email protected] password ta"),
            "Account creation error.")

    def test_command_create_account_missing_arg(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("create_account [email protected] ta"),
                         "Invalid command.")

    def test_command_create_account_too_many_args(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("create_account [email protected] password ta hi"),
            "Invalid command.")
class EditContactInfoTests(TestCase):
    def setUp(self):
        self.ui = CmdHandler()

    def test_command_create_account_no_setup(self):
        self.assertEqual(self.ui.parse_command("change_email [email protected]"),
                         "Please run setup before attempting to execute commands.")

    def test_command_create_account_no_login(self):
        self.ui.parse_command("setup")
        self.assertEqual(self.ui.parse_command("change_email [email protected]"),
                         "Please login first.")

    def test_command_admin_change_email(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_email [email protected]"), "Email address changed.")

    def test_command_super_change_email(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_email [email protected]"), "Email address changed.")

    def test_command_instructor_change_email(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_email [email protected]"), "Email address changed.")

    def test_command_ta_change_email(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_email [email protected]"), "Email address changed.")

    def test_command_bad_email(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_email [email protected]"), "Invalid/taken email address.")

    def test_command_no_email(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_email"), "Parameter error.")

    def test_command_weird_email(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_email [email protected]@uwm.com"),
                         "Invalid/taken email address.")

    def test_command_admin_change_password(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_password 12345"), "Password changed.")

    def test_command_super_change_password(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_password 12345"), "Password changed.")

    def test_command_instructor_change_password(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_password 12345"), "Password changed.")

    def test_command_ta_change_password(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_password 12345"), "Password changed.")

    def test_command_no_password(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_password"), "Parameter error.")

    def test_command_admin_change_name(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_name changeguy"), "Name changed.")

    def test_command_super_change_name(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_name changeguy"), "Name changed.")

    def test_command_instructor_change_name(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_name changeguy"), "Name changed.")

    def test_command_ta_change_name(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_name changeguy"), "Name changed.")

    def test_command_change_multiple_name(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_name Joe Bob Henry Bob Bob"), "Name changed.")

    def test_command_change_no_name(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_name"), "Parameter error.")

    def test_command_admin_change_phone(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_phone 414.867.5309"), "Phone number changed.")

    def test_command_super_change_phone(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_phone 414.867.5309"), "Phone number changed.")

    def test_command_instructor_change_phone(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_phone 414.867.5309"), "Phone number changed.")

    def test_command_ta_change_phone(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_phone 414.867.5309"), "Phone number changed.")

    def test_command_bad_phone(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_phone 414-867-5309"), "Invalid phone format.")

    def test_command_bad_phone_two(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_phone 4148675309"), "Invalid phone format.")

    def test_command_no_phone(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("change_phone"), "Parameter error.")
class CreateCourseTests(TestCase):
    def setUp(self):
        self.ui = CmdHandler()

    def test_no_login_get(self):
        client = Client()
        response = client.get('/create_course/')
        # this gets any messages
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        # this should be the first and only message, tagged error
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message, "Please login first.")
        # since we returned a redirect, we can check the location
        self.assertEqual(response.get('location'), '/login/')

    def test_admin_get(self):

        client = Client()
        # make a session, email and type are all you need
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        # save the session
        session.save()
        response = client.get('/create_course/')
        # status code 200, we loaded the correct page
        self.assertEqual(response.status_code, 200)
        # since we returned a render, it has all the content of the page
        # we'll just look for the header
        self.assertContains(response, "Create Course")
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        # no error messages
        self.assertEqual(len(all_messages), 0)

    def test_super_get(self):

        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.get('/create_course/')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Course")
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(len(all_messages), 0)

    def test_instructor_get(self):

        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'instructor'
        session.save()
        response = client.get('/create_course/')
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message,
                         "You do not have access to this page.")
        self.assertEqual(response.get('location'), '/index/')

    def test_ta_get(self):

        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'ta'
        session.save()
        response = client.get('/create_course/')
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message,
                         "You do not have access to this page.")
        self.assertEqual(response.get('location'), '/index/')

    def test_create_course_admin(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.post('/create_course/',
                               data={
                                   'course_id': "361",
                                   'course_section': "401",
                                   'num_labs': "3"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Course")
        self.assertContains(response, "Course has been created successfully.")

    def test_create_course_supervisor(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.post('/create_course/',
                               data={
                                   'course_id': "361",
                                   'course_section': "401",
                                   'num_labs': "3"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Course")
        self.assertContains(response, "Course has been created successfully.")

    def test_create_course_already_exists(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/create_course/',
                               data={
                                   'course_id': "361",
                                   'course_section': "401",
                                   'num_labs': "3"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Course")
        self.assertContains(response, "Course has been created successfully.")

        response = client.post('/create_course/',
                               data={
                                   'course_id': "361",
                                   'course_section': "401",
                                   'num_labs': "3"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Course")
        self.assertContains(response, "An error occurred")

    def test_create_course_course_id_letters(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/create_course/',
                               data={
                                   'course_id': "ABC",
                                   'course_section': "401",
                                   'num_labs': "3"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Course")
        self.assertContains(response, "An error occurred")

    def test_create_course_course_id_too_big(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/create_course/',
                               data={
                                   'course_id': "1234",
                                   'course_section': "401",
                                   'num_labs': "3"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Course")
        self.assertContains(response, "An error occurred")

    def test_create_course_course_id_too_small(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/create_course/',
                               data={
                                   'course_id': "12",
                                   'course_section': "401",
                                   'num_labs': "3"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Course")
        self.assertContains(response, "An error occurred")

    def test_create_course_course_section_letters(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/create_course/',
                               data={
                                   'course_id': "123",
                                   'course_section': "ABC",
                                   'num_labs': "3"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Course")
        self.assertContains(response, "An error occurred")

    def test_create_course_course_section_too_big(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/create_course/',
                               data={
                                   'course_id': "123",
                                   'course_section': "1234",
                                   'num_labs': "3"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Course")
        self.assertContains(response, "An error occurred")

    def test_create_course_course_section_too_small(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/create_course/',
                               data={
                                   'course_id': "123",
                                   'course_section': "99",
                                   'num_labs': "3"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Course")
        self.assertContains(response, "An error occurred")

    def test_create_course_num_labs_letters(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/create_course/',
                               data={
                                   'course_id': "123",
                                   'course_section': "401",
                                   'num_labs': "A"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Course")
        self.assertContains(response, "An error occurred")

    def test_create_course_num_labs_too_big(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/create_course/',
                               data={
                                   'course_id': "123",
                                   'course_section': "401",
                                   'num_labs': "6"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Course")
        self.assertContains(response, "An error occurred")

    def test_create_course_num_labs_too_small(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/create_course/',
                               data={
                                   'course_id': "123",
                                   'course_section': "401",
                                   'num_labs': "-1"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Create Course")
        self.assertContains(response, "An error occurred")
class ViewInfoTests(TestCase):

    def setUp(self):
        self.ui = CmdHandler()

    def test_no_login_get(self):

        client = Client()
        response = client.get('/edit_info/')
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message, "Please login first.")
        self.assertEqual(response.get('location'), '/login/')

    def test_admin_get(self):

        self.ui.parse_command("setup")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.get('/edit_info/')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Current Email:")
        self.assertContains(response, "*****@*****.**")
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(len(all_messages), 0)

    def test_super_get(self):

        self.ui.parse_command("setup")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.get('/edit_info/')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Current Email:")
        self.assertContains(response, "*****@*****.**")
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(len(all_messages), 0)

    def test_instructor_get(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'instructor'
        session.save()
        response = client.get('/edit_info/')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Current Email:")
        self.assertContains(response, "*****@*****.**")
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(len(all_messages), 0)

    def test_ta_get(self):

        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'ta'
        session.save()
        response = client.get('/edit_info/')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Info")
        self.assertContains(response, "Current Email:")
        self.assertContains(response, "*****@*****.**")
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(len(all_messages), 0)
class ViewTAAssignmentsTest(TestCase):
    def setUp(self):
        self.ui = CmdHandler()

    def test_access_info_no_setup(self):
        self.assertEqual(
            self.ui.parse_command("access_info"),
            "Please run setup before attempting to execute commands.")

    def test_command_view_ta_assign_no_login(self):
        self.ui.parse_command("setup")
        self.assertEqual(
            self.ui.parse_command("create_account [email protected] password ta"),
            "Please login first.")

    def test_command_view_ta_assign_admin(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("view_ta_assign"),
                         "You don't have access to that command.")

    def test_command_view_ta_assign_super(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("view_ta_assign"),
                         "You don't have access to that command.")

    def test_command_view_ta_assign_instructor_no_ta(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("view_ta_assign"), '')

    def test_command_view_ta_assign_ta_no_class(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("view_ta_assign"),
                         'TA: DEFAULT | [email protected] | 000.000.0000\n\n')

    def test_command_view_ta_assign_inst_one_course(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("create_course CS101-401 0")
        self.ui.parse_command("assign_instructor [email protected] CS101-401")
        self.ui.parse_command("assign_ta [email protected] CS101-401")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("view_ta_assign"),
            'TA: DEFAULT | [email protected] | 000.000.0000\n'
            '\tCourse: CS101-401\n\n')

    def test_command_view_ta_assign_ta_one_course(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("create_course CS101-401 0")
        self.ui.parse_command("assign_instructor [email protected] CS101-401")
        self.ui.parse_command("assign_ta [email protected] CS101-401")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("view_ta_assign"),
            'TA: DEFAULT | [email protected] | 000.000.0000\n'
            '\tCourse: CS101-401\n\n')

    def test_command_view_ta_assign_all_the_things(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("create_course CS101-401 0")
        self.ui.parse_command("create_course CS102-401 0")
        self.ui.parse_command("assign_instructor [email protected] CS101-401")
        self.ui.parse_command("assign_instructor [email protected] CS102-401")
        self.ui.parse_command("assign_ta [email protected] CS101-401")
        self.ui.parse_command("assign_ta [email protected] CS102-401")
        self.assertEqual(self.ui.parse_command("view_ta_assign"),
                         "You don't have access to that command.")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(
            self.ui.parse_command("view_ta_assign"),
            'TA: DEFAULT | [email protected] | 000.000.0000\n'
            '\tCourse: CS101-401\n\n'
            'TA: DEFAULT | [email protected] | 000.000.0000\n'
            '\tCourse: CS102-401\n\n')
class AssignTaTests(TestCase):
    def setUp(self):
        self.ui = CmdHandler()

    def test_no_login_get(self):

        client = Client()
        response = client.get('/assign_ta/')
        # this gets any messages
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        # this should be the first and only message, tagged error
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message, "Please login first.")
        # since we returned a redirect, we can check the location
        self.assertEqual(response.get('location'), '/login/')

    def test_instructor_get(self):

        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'instructor'
        session.save()
        response = client.get('/assign_ta/')
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message,
                         "You do not have access to this page.")
        self.assertEqual(response.get('location'), '/index/')

    def test_ta_get(self):

        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'ta'
        session.save()
        response = client.get('/assign_ta/')
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message,
                         "You do not have access to this page.")
        self.assertEqual(response.get('location'), '/index/')

    def test_admin_get(self):

        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.get('/assign_ta/')
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message,
                         "You do not have access to this page.")
        self.assertEqual(response.get('location'), '/index/')

    def test_sup_get(self):

        client = Client()
        # make a session, email and type are all you need
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        # save the session
        session.save()
        response = client.get('/assign_ta/')
        # status code 200, we loaded the correct page
        self.assertEqual(response.status_code, 200)
        # since we returned a render, it has all the content of the page
        # we'll just look for the header
        self.assertContains(response, "Assign TA")
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        # no error messages
        self.assertEqual(len(all_messages), 0)

    def test_super_post(self):
        # we still need to have some sort of setup on tests, the command handler still gets this
        # done easiest right now
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_course CS101-301 3")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.post('/assign_ta/',
                               data={
                                   'email': "*****@*****.**",
                                   'course_id': "101",
                                   'course_section': "301"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Assign TA")
        self.assertContains(response, "command successful")

    def test_invalid_ta(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_course CS101-301 3")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.post('/assign_ta/',
                               data={
                                   'email': "*****@*****.**",
                                   'course_id': "101",
                                   'course_section': "301"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Assign TA")
        self.assertContains(response, "no such ta")

    def test_invalid_course(self):
        # we still need to have some sort of setup on tests, the command handler still gets this
        # done easiest right now
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_course CS101-301 3")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.post('/assign_ta/',
                               data={
                                   'email': "*****@*****.**",
                                   'course_id': "107",
                                   'course_section': "301"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Assign TA")
        self.assertContains(response, "no such course")

    def test_invalid_course_id(self):
        # we still need to have some sort of setup on tests, the command handler still gets this
        # done easiest right now
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_course CS101-301 3")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.post('/assign_ta/',
                               data={
                                   'email': "*****@*****.**",
                                   'course_id': "101",
                                   'course_section': "306"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Assign TA")
        self.assertContains(response, "no such course")

    def test_assign_improper_ins(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_course CS101-301 3")
        self.ui.parse_command("create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.post('/assign_ta/',
                               data={
                                   'email': "*****@*****.**",
                                   'course_id': "101",
                                   'course_section': "301"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Assign TA")
        self.assertContains(response, "no such ta")

    def test_assign_improper_admin(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_course CS101-301 3")
        self.ui.parse_command(
            "create_account [email protected] password administrator")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.post('/assign_ta/',
                               data={
                                   'email': "*****@*****.**",
                                   'course_id': "101",
                                   'course_section': "301"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Assign TA")
        self.assertContains(response, "no such ta")

    def test_assign_improper_sup(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_course CS101-301 3")
        self.ui.parse_command("create_account [email protected] password supervisor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.post('/assign_ta/',
                               data={
                                   'email': "*****@*****.**",
                                   'course_id': "101",
                                   'course_section': "301"
                               },
                               follow="true")
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Assign TA")
        self.assertContains(response, "no such ta")
Ejemplo n.º 20
0
class CreateAccountTests(TestCase):
    def setUp(self):
        self.ui = CmdHandler()

    def test_access_info_no_setup(self):
        self.assertEqual(
            self.ui.parse_command("access_info"),
            "Please run setup before attempting to execute commands.")

    def test_command_access_info_no_login(self):
        self.ui.parse_command("setup")
        self.assertEqual(
            self.ui.parse_command("create_account [email protected] password ta"),
            "Please login first.")

    def test_command_access_info_admin(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        big_string = self.ui.parse_command("access_info")
        parse_string = big_string.split("\n")
        self.assertEqual(parse_string[0], "Administrator:")
        self.assertEqual(parse_string[1],
                         "DEFAULT | [email protected] | 000.000.0000")
        self.assertEqual(parse_string[2], "")
        self.assertEqual(parse_string[3], "Supervisor:")
        self.assertEqual(parse_string[4],
                         "DEFAULT | [email protected] | 000.000.0000")

    def test_command_access_info_super(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        big_string = self.ui.parse_command("access_info")
        parse_string = big_string.split("\n")
        self.assertEqual(parse_string[0], "Administrator:")
        self.assertEqual(parse_string[1],
                         "DEFAULT | [email protected] | 000.000.0000")
        self.assertEqual(parse_string[2], "")
        self.assertEqual(parse_string[3], "Supervisor:")
        self.assertEqual(parse_string[4],
                         "DEFAULT | [email protected] | 000.000.0000")

    def test_command_access_info_instructor(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("access_info"),
                         "Invalid command.")

    def test_command_access_info_ta(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("logout")
        self.ui.parse_command("login [email protected] password")
        self.assertEqual(self.ui.parse_command("access_info"),
                         "Invalid command.")

    def test_command_access_info_instructor_no_class(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        big_string = self.ui.parse_command("access_info")
        parse_string = big_string.split("\n")
        self.assertEqual(parse_string[6], "Instructors:")
        self.assertEqual(parse_string[7],
                         "DEFAULT | [email protected] | 000.000.0000")

    def test_command_access_info_ta_no_class(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        big_string = self.ui.parse_command("access_info")
        parse_string = big_string.split("\n")
        self.assertEqual(parse_string[8], "TAs:")
        self.assertEqual(parse_string[9],
                         "DEFAULT | [email protected] | 000.000.0000")

    def test_command_access_info_inst_one_course(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("create_course CS101-401 0")
        self.ui.parse_command("assign_instructor [email protected] CS101-401")
        big_string = self.ui.parse_command("access_info")
        parse_string = big_string.split("\n")
        self.assertEqual(parse_string[8], "\tCourse: CS101-401")

    def test_command_access_info_ta_one_course(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("create_course CS101-401 0")
        self.ui.parse_command("assign_ta [email protected] CS101-401")
        big_string = self.ui.parse_command("access_info")
        parse_string = big_string.split("\n")
        self.assertEqual(parse_string[10], "\tCourse: CS101-401")

    def test_command_access_info_just_course(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("create_course CS101-401 0")
        big_string = self.ui.parse_command("access_info")
        parse_string = big_string.split("\n")
        self.assertEqual(parse_string[12], "Courses:")
        self.assertEqual(parse_string[13], "CS101-401")

    def test_command_access_info_all_the_things(self):
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("create_course CS101-401 0")
        self.ui.parse_command("create_course CS102-401 0")
        self.ui.parse_command("assign_instructor [email protected] CS101-401")
        self.ui.parse_command("assign_instructor [email protected] CS102-401")
        self.ui.parse_command("assign_ta [email protected] CS101-401")
        self.ui.parse_command("assign_ta [email protected] CS102-401")
        big_string = self.ui.parse_command("access_info")
        parse_info = big_string.split("\n")
        self.assertEqual(parse_info[0], "Administrator:")
        self.assertEqual(parse_info[1],
                         "DEFAULT | [email protected] | 000.000.0000")
        self.assertEqual(parse_info[2], "")
        self.assertEqual(parse_info[3], "Supervisor:")
        self.assertEqual(parse_info[4],
                         "DEFAULT | [email protected] | 000.000.0000")
        self.assertEqual(parse_info[5], "")
        self.assertEqual(parse_info[6], "Instructors:")
        self.assertEqual(parse_info[7],
                         "DEFAULT | [email protected] | 000.000.0000")
        self.assertEqual(parse_info[8], "\tCourse: CS101-401")
        self.assertEqual(parse_info[9], "")
        self.assertEqual(parse_info[10],
                         "DEFAULT | [email protected] | 000.000.0000")
        self.assertEqual(parse_info[11], "\tCourse: CS102-401")
        self.assertEqual(parse_info[12], "")
        self.assertEqual(parse_info[13], "")
        self.assertEqual(parse_info[14], "TAs:")
        self.assertEqual(parse_info[15],
                         "DEFAULT | [email protected] | 000.000.0000")
        self.assertEqual(parse_info[16], "\tCourse: CS101-401")
        self.assertEqual(parse_info[17], "")
        self.assertEqual(parse_info[18],
                         "DEFAULT | [email protected] | 000.000.0000")
        self.assertEqual(parse_info[19], "\tCourse: CS102-401")
        self.assertEqual(parse_info[20], "")
        self.assertEqual(parse_info[21], "")
        self.assertEqual(parse_info[22], "Courses:")
        self.assertEqual(parse_info[23], "CS101-401")
        self.assertEqual(parse_info[24], "CS102-401")
Ejemplo n.º 21
0
 def setUp(self):
     self.ui = CmdHandler()
Ejemplo n.º 22
0
class EditInfoTests(TestCase):
    def setUp(self):
        self.ui = CmdHandler()
        self.ui.parse_command("setup")
        self.ui.parse_command("login [email protected] password")
        self.ui.parse_command(
            "create_account [email protected] password instructor")
        self.ui.parse_command("create_account [email protected] password ta")
        self.ui.parse_command("logout")

    def test_no_login_get(self):
        client = Client()
        response = client.get('/edit_account/')
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message, "Please login first.")
        self.assertEqual(response.get('location'), '/login/')

    def test_admin_get(self):
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()
        response = client.get('/edit_account/')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(len(all_messages), 0)

    def test_super_get(self):
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'supervisor'
        session.save()
        response = client.get('/edit_account/')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(len(all_messages), 0)

    def test_instructor_get(self):
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'instructor'
        session.save()
        response = client.get('/edit_account/')
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message,
                         "You do not have access to this page.")
        self.assertEqual(response.get('location'), '/index/')

    def test_ta_get(self):
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'ta'
        session.save()
        response = client.get('/edit_account/')
        all_messages = [msg for msg in get_messages(response.wsgi_request)]
        self.assertEqual(all_messages[0].tags, "error")
        self.assertEqual(all_messages[0].message,
                         "You do not have access to this page.")
        self.assertEqual(response.get('location'), '/index/')

    def test_admin_edit_admin_email(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "email",
                                   'data': "*****@*****.**"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_admin_edit_admin_password(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "password",
                                   'data': "new_password"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_admin_edit_admin_name(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "name",
                                   'data': "Dr. John Tang Boyland"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_admin_edit_admin_phone(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "phone",
                                   'data': "414.123.4567"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_admin_edit_super_email(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "email",
                                   'data': "*****@*****.**"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_admin_edit_super_password(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "password",
                                   'data': "new_password"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_admin_edit_super_name(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "name",
                                   'data': "Dr. John Tang Boyland"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_admin_edit_super_phone(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "phone",
                                   'data': "414.123.4567"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_admin_edit_instructor_email(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "email",
                                   'data': "*****@*****.**"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_admin_edit_instructor_password(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "password",
                                   'data': "new_password"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_admin_edit_instructor_name(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "name",
                                   'data': "Dr. John Tang Boyland"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_admin_edit_instructor_phone(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "phone",
                                   'data': "414.123.4567"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_admin_edit_ta_email(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "email",
                                   'data': "*****@*****.**"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_admin_edit_ta_password(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "password",
                                   'data': "new_password"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_admin_edit_ta_name(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "name",
                                   'data': "Dr. John Tang Boyland"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_admin_edit_ta_phone(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "phone",
                                   'data': "414.123.4567"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_super_edit_admin_email(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "email",
                                   'data': "*****@*****.**"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_super_edit_admin_password(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "password",
                                   'data': "new_password"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_super_edit_admin_name(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "name",
                                   'data': "Dr. John Tang Boyland"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_super_edit_admin_phone(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "phone",
                                   'data': "414.123.4567"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_super_edit_super_email(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "email",
                                   'data': "*****@*****.**"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_super_edit_super_password(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "password",
                                   'data': "new_password"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_super_edit_super_name(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "name",
                                   'data': "Dr. John Tang Boyland"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_super_edit_super_phone(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "phone",
                                   'data': "414.123.4567"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_super_edit_instructor_email(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "email",
                                   'data': "*****@*****.**"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_super_edit_instructor_password(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "password",
                                   'data': "new_password"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_super_edit_instructor_name(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "name",
                                   'data': "Dr. John Tang Boyland"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_super_edit_instructor_phone(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "phone",
                                   'data': "414.123.4567"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_super_edit_ta_email(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "email",
                                   'data': "*****@*****.**"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_super_edit_ta_password(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "password",
                                   'data': "new_password"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_super_edit_ta_name(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "name",
                                   'data': "Dr. John Tang Boyland"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_super_edit_ta_phone(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "phone",
                                   'data': "414.123.4567"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command successful.")

    def test_edit_bad_email(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "email",
                                   'data': "*****@*****.**"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command error")

    def test_edit_bad_email_too_many_args(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "email",
                                   'data': "[email protected] otherstuff"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Invalid command")

    def test_edit_bad_phone_too_long(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "phone",
                                   'data': "123.123.12345"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command error")

    def test_edit_bad_phone_too_short(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "phone",
                                   'data': "123.123.123"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command error")

    def test_edit_bad_phone_wrong_format(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "phone",
                                   'data': "123-123-1234"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command error")

    def test_edit_bad_phone_non_digits(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "phone",
                                   'data': "123.123.ABCD"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Command error")

    def test_edit_bad_phone_too_many_args(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "phone",
                                   'data': "123.123.1234 otherstuff"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Invalid command")

    def test_edit_account_bad_field(self):
        self.ui.parse_command("login [email protected] password")
        client = Client()
        session = client.session
        session['email'] = '*****@*****.**'
        session['type'] = 'administrator'
        session.save()

        response = client.post('/edit_account/',
                               data={
                                   'email': "*****@*****.**",
                                   'field': "nombre",
                                   'data': "Dr. John Tang Boyland"
                               })
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Edit Account")
        self.assertContains(response, "Invalid command")