Ejemplo n.º 1
0
 def test_student(self):
     self.user = Student(first_name="Alex",
                         last_name="Weber",
                         user_name="WEBER68",
                         password="")
     self.user.password = self.user.key()
     self.assertEqual(self.user.first_name, "Alex")
     self.assertEqual(self.user.last_name, "Weber")
     self.assertEqual(self.user.user_name, "WEBER68")
     self.assertEqual(self.user.password, "password")
     self.assertIsInstance(self.user, Student)
     self.assertIsInstance(self.user, User)
Ejemplo n.º 2
0
def parse_info(input_list):
    input_list = input_list.replace(' ','')
    logging.info("parse info called")
    while len(input_list) > 5:

        pos = input_list.find(',')
        l_name = input_list[0:pos]
        input_list = input_list[pos+1:len(input_list)]
        logging.info("name" + l_name)

        pos = input_list.find(',')
        f_name = input_list[0:pos]
        input_list = input_list[pos+1:len(input_list)]
        logging.info(f_name)

        pos = input_list.find(',')
        u_name = input_list[0:pos]
        input_list = input_list[pos+1:len(input_list)]
        logging.info(u_name)

        pos = input_list.find('\n')
        if pos < 0:
            pos = len(input_list)
        u_type = input_list[0:pos]
        input_list = input_list[pos+1:len(input_list)]
        logging.info(u_type)

        # add user
        if u_type == "Instructor":
            prof = Professor(first_name=f_name, last_name=l_name, user_name=u_name, password="******").put()
            logging.info(prof)
        else:
            stud = Student(first_name=f_name, last_name=l_name, user_name=u_name, password="******").put()
            logging.info(stud)
Ejemplo n.º 3
0
 def test_unique_user_names(self):
     student2 = Student(first_name="first",
                        last_name="last",
                        user_name="user",
                        password="")
     self.assertIsNone(student2)
     student2.key.delete()
Ejemplo n.º 4
0
 def test_professor(self):
     self.user = Professor(first_name="Jayson",
                           last_name="Rock",
                           user_name="ROCK32",
                           password="******")
     self.assertEqual(self.user.first_name, "Jayson")
     self.assertEqual(self.user.last_name, "Rock")
     self.assertEqual(self.user.user_name, "ROCK32")
     self.assertEqual(self.user.password, "password")
     self.assertIsInstance(self.user, Professor)
     self.assertIsInstance(self.user, User)
Ejemplo n.º 5
0
 def post(self):
     username = self.session['username']
     logging.info(username)
     student = Student.query(Student.user_name == username).fetch()[0]
     if self.request.get('first_pass') == self.request.get('second_pass'): #check if passwords match
         logging.info(self.request.get('first_pass'))
         if student.change_password(self.request.get('first_pass')): # password change successful
             student.put()
             self.redirect('/')
         else:
             template = JINJA_ENVIRONMENT.get_template('templates/StudentAccountSettingsPage.html')
             self.response.write(template.render({'user': student}))
     else:
         template = JINJA_ENVIRONMENT.get_template('templates/StudentAccountSettingsPage.html')
         self.response.write(template.render({'user': student, 'password_match': False}))
Ejemplo n.º 6
0
 def get(self):
     username = self.session['username']
     logging.info(username)
     students = Student.query(Student.user_name == username).fetch()
     student = students[0]
     if student:
         logging.info(student)
         template = JINJA_ENVIRONMENT.get_template('templates/StudentAccountSettingsPage.html')
         self.response.write(template.render({'user': student}))
     else:
         html="""<html>
         <head><meta http-equiv="refresh" content="3;URL='/'"><title>Redirect</title></head>
         <body style="color: red;"> Invalid Credentials, you are being redirected.</body></html>
         """
         self.response.write(html)
Ejemplo n.º 7
0
    def get(self):
        # populate data store with mock info if it doesn't exist
        users = User.query().fetch()
        if not users:
            Professor(user_name='SampleProfessor', password='******', first_name='Jayson', last_name='Rock').put()
            Student(user_name='SampleStudent', password='******', first_name='Kylie', last_name='Weber').put()

        if 'username' in self.session and self.session['username']:
            username = self.session['username']
            profs = Professor.query(Professor.user_name == username).fetch()
            if profs:
                self.redirect('/adminhome')
            else:
                self.redirect('/studenthome')
        else:
            template = JINJA_ENVIRONMENT.get_template('templates/protologin.html')
            self.response.write(template.render())
Ejemplo n.º 8
0
def load_user(userid):
    usr = UserData()
    if not userid:
        raise TypeError("Please provide your user id.")
    try:
        role = usr.findById(int(userid))[2]
    except Exception as e:
        raise TypeError("Wrong username/password, please try again.")
    # initialise the class by the role
    if role == 'admin':
        return Admin(userid)
    elif role == 'student':
        return Student(userid)
    elif role in ["guest", "unguest"]:
        return Guest(userid)
    elif role == 'staff':
        return Staff(userid)
Ejemplo n.º 9
0
 def get(self):
     if 'username' in self.session and self.session['username']:
         username = self.session['username']
         students = Student.query(Student.user_name == username).fetch()
         if students:
             student = students[0]
             template = JINJA_ENVIRONMENT.get_template('templates/StudentHomePage.html')
             self.response.write(template.render({
                 'answered_questions': student.get_answered_questions,
                 'unanswered_questions': student.get_unanswered_questions,
                 'user': student.first_name+" "+student.last_name
             }))
         else:
             self.response.write("Invalid Credentials")
             self.redirect('/')
     else:
         self.response.write("Invalid Credentials")
         self.redirect('/')
Ejemplo n.º 10
0
 def getGuest(self, userID):
     users = self._controller.getGuest(userID)
     if (len(users) == 0):
         return []
     if (users[0] == -1):
         u = User(-1)
         u.setPass(-1)
         return u
     uList = []
     for user in users:
         u = Student(user[uDict['id']])
         u.setPass(user[uDict['pass']])
         u.setClasses(user[uDict['class'] - 1])
         uList.append(copy.deepcopy(u))
     if userID == None:
         return uList
     else:
         return uList[0]
Ejemplo n.º 11
0
    def getUser(self, userID):
        user = self._controller.getUser(userID)
        if (user[0] == -1):
            u = User(-1)
            u.setPass(-1)
            return u
        if user[uDict['type']] == 1:
            u = Admin(user[uDict['id']])
        elif user[uDict['type']] == 2:
            u = Staff(user[uDict['id']])
        else:
            u = Student(user[uDict['id']])

        u.setPass(user[uDict['pass']])
        if u.type != 1:
            for c in user[uDict['class']]:
                u.addClasses(c)
        return u
Ejemplo n.º 12
0
def registerUser():

    if request.method == "POST":
        name = request.form["name"]
        if not validEmail(handle, name):
            print("invalid email")
            return redirect("/register")
        usr = Student(name)
        usr.setPass(request.form["pass"])
        usr.setClasses(request.form["course-IDs"])
        user = handle.addGuest(usr)
        return redirect("/")
    return render_template("register.html",
                           courses=handle.getClass(None),
                           incorrect='false')
Ejemplo n.º 13
0
 def get(self):
     if 'username' in self.session and self.session['username']:
         username = self.session['username']
         students = Student.query(Student.user_name == username).fetch()
         if students:
             template = JINJA_ENVIRONMENT.get_template('templates/submitquestion.html')
             self.response.write(template.render({
                 'submitagain': False,
                 'emptyfield': False
             }))
         else:
             html = """<html>
             <head><meta http-equiv="refresh" content="3;URL='/'"><title>Redirect</title></head>
             <body style="color: red;"> Invalid Credentials, you are being redirected.</body></html>
             """
             self.response.write(html)
     else:
         html="""<html>
         <head><meta http-equiv="refresh" content="3;URL='/'"><title>Redirect</title></head>
         <body style="color: red;"> Invalid Credentials, you are being redirected.</body></html>
         """
         self.response.write(html)
Ejemplo n.º 14
0
 def get(self):
     unanswered_questions = Question.query(Question.unAnswered == True).order(-Question.date_created).fetch()
     recent_questions = Question.query().order(-Question.date_answered).fetch(6)
     students = Student.query().fetch()
     if 'username' in self.session and self.session['username']:
         username = self.session['username']
         profs = Professor.query(Professor.user_name == username).fetch()
         qqtab = 1
         if self.request.get('NewQ'):
             qqtab = 1
         elif self.request.get('RecentQ'):
             qqtab = 2
         elif self.request.get('ByStudent'):
             qqtab = 3
         elif self.request.get('FAQs'):
             self.redirect('/FAQADMIN')
         if profs:
             template = JINJA_ENVIRONMENT.get_template('templates/QuestionQueue.html')
             self.response.write(template.render({
                 'QQTAB': qqtab,
                 'unanswered_questions': unanswered_questions,
                 'recent_questions': recent_questions,
                 'students': students
             }))
         else:
             html = """<html>
             <head><meta http-equiv="refresh" content="3;URL='/'"><title>Redirect</title></head>
             <body style="color: red;"> Invalid Credentials, you are being redirected.</body></html>
             """
             self.response.write(html)
     else:
         html="""<html>
         <head><meta http-equiv="refresh" content="3;URL='/'"><title>Redirect</title></head>
         <body style="color: red;"> Invalid Credentials, you are being redirected.</body></html>
         """
         self.response.write(html)
Ejemplo n.º 15
0
#
# from user.Person import Person
# p1 = Person()


from user import Person

# p1 = Person('Green', 12)
# print(p1.name, p1.age)
p2 = Person('Lucy', 14)
# print(p2.name, p2.age)
p2.sleep(10)
# print(p1.__name, p1.__age)

from user import Student
student1 = Student('Green', 12)
# print(student1.get_name())
student1.sleep(10)

# from user import Programmer
# p = Programmer('Green', 18)
# print(Programmer.count_by_name('Green'))
# count = Programmer.count_by_name('Green')

# 静态继承问题

# class Gx(Programmer):
#     pass
    # programmers = {}  # 静态变量

    # @classmethod
Ejemplo n.º 16
0
 def setUp(self):
     self.user = User()
Ejemplo n.º 17
0
class TestRegisterUsers(unittest.TestCase):
    def setUp(self):
        self.user = User()

    def tearDown(self):
        self.user.delete()

    def test_null_file(self):
        main.parse_info(input_list="")
        users = User.query.fetch()
        self.assertIsNone(users)

    def test_professor(self):
        self.user = Professor(first_name="Jayson",
                              last_name="Rock",
                              user_name="ROCK32",
                              password="******")
        self.assertEqual(self.user.first_name, "Jayson")
        self.assertEqual(self.user.last_name, "Rock")
        self.assertEqual(self.user.user_name, "ROCK32")
        self.assertEqual(self.user.password, "password")
        self.assertIsInstance(self.user, Professor)
        self.assertIsInstance(self.user, User)

    def test_student(self):
        self.user = Student(first_name="Alex",
                            last_name="Weber",
                            user_name="WEBER68",
                            password="")
        self.user.password = self.user.key()
        self.assertEqual(self.user.first_name, "Alex")
        self.assertEqual(self.user.last_name, "Weber")
        self.assertEqual(self.user.user_name, "WEBER68")
        self.assertEqual(self.user.password, "password")
        self.assertIsInstance(self.user, Student)
        self.assertIsInstance(self.user, User)

    def test_no_input(self):
        main.parse_info(input_list="")
        users = User.query.fetch()
        self.assertIsNone(users)

    def test_create_one_user(self):
        main.parse_info(input_list="kyle, vandaalwyk, VANDA24, Student")
        users = User.query.fetch()
        self.assertIsNotNone(users)
        self.assertEqual(len(users), 1)
        self.assertEqual(users[0].first_name, "kyle")
        self.assertEqual(users[0].last_name, "vandaalwyk")
        self.assertEqual(users[0].user_name, "VANDA24")
        self.assertEqual(users[0].password, "password")

    def test_create_two_users(self):
        main.parse_info(
            input_list=
            "kyle, vandaalwyk, VANDA24, Student\njen, fox, FOX36, Student")
        users = User.query.fetch()
        self.assertIsNotNone(users)
        self.assertEqual(len(users), 2)
        self.assertEqual(users[0].first_name, "kyle")
        self.assertEqual(users[0].last_name, "vandaalwyk")
        self.assertEqual(users[0].user_name, "VANDA24")
        self.assertEqual(users[0].password, "password")
        self.assertEqual(users[1].first_name, "jen")
        self.assertEqual(users[1].last_name, "fox")
        self.assertEqual(users[1].user_name, "FOX36")
        self.assertEqual(users[1].password, users[1].key())

    def test_create_same_name_users(self):
        main.parse_info(
            input_list=
            "kyle, vandaalwyk, VANDA24, Student\nkyle, vandaalwyk, FOX36, Student"
        )
        users = User.query.fetch()
        self.assertIsNotNone(users)
        self.assertEqual(len(users), 2)
        self.assertEqual(users[0].first_name, "kyle")
        self.assertEqual(users[0].last_name, "vandaalwyk")
        self.assertEqual(users[0].user_name, "VANDA24")
        self.assertEqual(users[0].password, "password")
        self.assertEqual(users[1].first_name, "kyle")
        self.assertEqual(users[1].last_name, "vandaalwyk")
        self.assertEqual(users[1].user_name, "FOX36")
        self.assertEqual(users[1].password, "password2")
Ejemplo n.º 18
0
 def test_empty_first_name(self):
     self.failUnlessRaises(
         Student(first_name="",
                 last_name="last",
                 user_name="user",
                 password="******"))
Ejemplo n.º 19
0
 def tearDown(self):
     student = Student.query(
         Student.first_name == self.student.first_name).fetch()
     if student:
         student.key.delete()
Ejemplo n.º 20
0
 def setUp(self):
     self.student = Student(first_name="first",
                            last_name="last",
                            user_name="user",
                            password="******")
Ejemplo n.º 21
0
class TestStudent(unittest.TestCase):
    def setUp(self):
        self.student = Student(first_name="first",
                               last_name="last",
                               user_name="user",
                               password="******")

    def tearDown(self):
        student = Student.query(
            Student.first_name == self.student.first_name).fetch()
        if student:
            student.key.delete()

    def test_user_not_null(self):
        self.assertNotEqual(None, self.student)

    def test_empty_first_name(self):
        self.failUnlessRaises(
            Student(first_name="",
                    last_name="last",
                    user_name="user",
                    password="******"))

    def test_empty_last_name(self):
        self.failUnlessRaises(first_name="first",
                              last_name="",
                              user_name="user",
                              password="******")

    def test_empty_password(self):
        self.failUnlessRaises(first_name="first",
                              last_name="last",
                              user_name="user",
                              password="")

    def test_set_username(self):
        self.student.username = '******'
        self.assertEqual(self.student.username, 'Kyle')

    def test_set_password(self):
        self.student.password = '******'
        self.assertEqual(self.student.password, 'kylesuckslol')

    def test_unique_user_names(self):
        student2 = Student(first_name="first",
                           last_name="last",
                           user_name="user",
                           password="")
        self.assertIsNone(student2)
        student2.key.delete()

    def test_change_password(self):
        self.student.change_password("234")
        self.assertTrue(self.student.password, "234")

    def test_change_blank_password(self):
        self.assertFalse(self.student.change_password(""))
        self.assertTrue(self.student.password, "123")

    def test_change_short_password(self):
        self.assertFalse(self.student.change_password("23"))
        self.assertTrue(self.student.password, "123")

    def test_change_no_numbers_password(self):
        self.assertFalse(self.student.change_password("badpass"))
        self.assertTrue(self.student.password, "123")
Ejemplo n.º 22
0
class TestQuestion(unittest.TestCase):
    def setUp(self):
        self.student = Student(first_name="first",
                               last_name="last",
                               user_name="user",
                               password="******")

    def tearDown(self):
        # self.student_key.delete()
        # self.prof_key.delete()
        pass

    def test_post_FAQ(self):
        self.faq_as_student = Question(isFAQ=True,
                                       question='?',
                                       answer="aaaaaaa")
        self.faq_as_admin = Question(isFAQ=True,
                                     question='???',
                                     answer="BbBbBb")
        self.assertFalse(self.faq_as_student.isFAQ)
        self.assertTrue(self.faq_as_admin.isFAQ)
        self.assertEqual('?', self.faq_as_student.question)
        self.assertEqual('???', self.faq_as_admin.question)
        self.assertEqual('aaaaaaa', self.faq_as_student.answer)
        self.assertEqual('BbBbBb', self.faq_as_admin.answer)
        del self.faq_as_student
        del self.faq_as_admin

    def test_set_FAQ(self):
        self.faq_as_student = Question(isFAQ=False,
                                       question='?',
                                       answer="answer")
        self.faq_as_admin = Question(isFAQ=False,
                                     question='???',
                                     answer="ANSWER")
        self.assertFalse(self.faq_as_student.isFAQ)
        self.assertFalse(self.faq_as_admin.isFAQ)
        self.faq_as_student.set_FAQ(isFAQ=True)  # , self.faq_as_student
        self.faq_as_admin.set_FAQ(isFAQ=True)  # , self.faq_as_admin
        self.assertFalse(self.faq_as_student.isFAQ)
        self.assertTrue(self.faq_as_admin.isFAQ)
        del self.faq_as_student
        del self.faq_as_admin

    def test_set_answer(self):
        self.faq_as_student = Question(isFAQ=False,
                                       question='?',
                                       answer="answer")
        self.faq_as_admin = Question(isFAQ=False,
                                     question='???',
                                     answer="ANSWER")
        self.faq_as_student.set_answer("")
        self.faq_as_admin.set_answer("   .   ")
        self.assertEqual("", self.faq_as_student.answer)
        self.assertEqual("   .   ", self.faq_as_admin)

    def test_display_FAQ(self):
        self.faq1 = Question(isFAQ=True, question="?", answer="!")
        self.faq2 = Question(isFAQ=True, question="??", answer="!!")
        self.faq3 = Question(isFAQ=True, question="???", answer="!!!")
        self.notfaq = Question(isFAQ=False, question="!????", answer="?!!!!")
        self.assertTrue(self.faq1.isFAQ)
        self.assertTrue(self.faq2.isFAQ)
        self.assertTrue(self.faq3.isFAQ)
        self.assertFalse(self.notfaq.isFAQ)

    def test_autoset_time(self):
        pass

    def test_check_date(self):
        pass

    def test_empty_question(self):
        pass

    # to be implements next sprint?
    def test_get_questions(self):
        self.assertIsNotNone(self.student.get_all_questions())

    def test_get_unseen_questions(self):
        self.assertIsNotNone(self.student.get_all_unseen_questions())

    def test_get_url_safe_key(self):
        self.assertIsNotNone(
            self.student.get_all_questions()[0].get_url_safe_key())

    def test_get_question_obj_from_url_safe_key(self):
        self.assertIs(Question().get_question_from_url_safe_key(
            self.student.get_all_questions()[0].get_url_safe_key()))
Ejemplo n.º 23
0
""" модуль запуска всей программы """

from quiz import launch
from user import Student
from decorators import logger


@logger
def start(login, name, course, role):
    launch()


print('You are:\n1 - Teacher\n2 - Student\nPlease, enter 1 or 2: ')
answer = int(input())

if answer == 1:
    print('Coming soon...\nBye!)')
else:
    user = Student.authorization()
    start(user.login, user.name, user.course, user.role)
Ejemplo n.º 24
0
# 多态

from user import Student
from user import Person

p1 = Person('Green', 12)
s1 = Student('Green', 12)
print(type(s1))
print(type(p1))

print(isinstance(p1, Person))
print(isinstance(p1, Student))

print(type(p1) == Person)
print(type(p1) == Student)

type(s1) == Person  # False
type(s1) == Student  # True
isinstance(s1, Person)  # True
isinstance(s1, Student)  # True


def poly_test(person):
    if not isinstance(person, Person):
        raise ValueError('数据类型传入错误')
    return person.sleep(10)


try:
    poly_test(p1)
    poly_test(s1)
Ejemplo n.º 25
0
 def test_student(self):  # 测试用例
     s = Student('Green', 12)
     self.assertEqual(12, s.get_age())
     self.assertEqual('Green', s.get_name())