Пример #1
0
def login(request):
    resp = {'result': "", 'code': 0, 'message': ""}
    print('received an http request: user login!')
    print('request.body == %s' %request.body)

    if len(request.body) == 0:
        userName = request.COOKIES.get('userName', '')
        print('userName from cookie is: ' + userName)
        if userName is not None and len(userName) > 0:
            resp['result'] = userName
        else:
            resp['code'] = 110
        respstr = simplejson.dumps(resp)
        return HttpResponse(respstr)

    req = simplejson.loads(request.body)
    print('the req == ' + str(req))

    userName = req['userName']
    password = req['password']
    usrMgr = UserManager()
    usrMgr.login(userName, password, resp)

    respstr = simplejson.dumps(resp)
    print(respstr)
    httpResp = HttpResponse(respstr)
    if resp['result'] == "success":
        httpResp.set_cookie('userName', userName, 120)
    return httpResp
Пример #2
0
    def modify_totp(username, password):
        """
        Update the TOTP secret
        """
        resp = Response("OK")

        if UserManager.verify_match(username, password):
            try:
                totp_secret = UserManager._reset_totp(username)

                otpauth_link = 'otpauth://totp/%s?secret=%s' % (username,
                                                                totp_secret)
                qr_code = pyqrcode.create(otpauth_link)

                template_args = {
                    'username': username,
                    'totp_secret': totp_secret,
                    'qr_blob': qr_code.png_as_base64_str(scale=5)
                }

                mako_template = LOOKUP.get_template('modify_totp.mako')
                resp.message = mako_template.render(**template_args)
            except RuntimeError:
                resp = BadRequest("Username not found")
        else:
            resp = BadRequest("Username/password mismatch")
        return resp
Пример #3
0
def register(request):
    resp = {'result': "", 'code': 0, 'message': ""}
    print('received an http request: user register!')
    print('request.body == %s' %request.body)

    args = simplejson.loads(request.body)
    usrMgr = UserManager()
    usrMgr.register(args, resp)

    respstr = simplejson.dumps(resp)
    print(respstr)
    return HttpResponse(respstr)
Пример #4
0
    def show_question(self, url):
        """
        Returns the secret question for the given user
        :param username: Username given by the user
        :return:
        """
        resp = Response("OK")
        try:
            question_str = UserManager._read_lostqstn(self.username)
            # question_str = 'Have you lost your marbles'

            template_args = {
                'title': 'Password Recovery',
                'question': 'Question: ',
                'question_str': question_str,
                'answer': 'Answer:',
                'submit_text': 'Submit',
                'wrong_answer': 0,
                'url': url
            }
            mako_template = LOOKUP.get_template(self.mako_template2)
            resp.message = mako_template.render(**template_args)

        except RuntimeError:
            resp = BadRequest("Username not found")

        return resp
Пример #5
0
    def test_DictUser():
        """ Unit test for DictionaryToUser function """

        dict = {'firstName': 'test', 'lastName': '[pew', 'orders': ['wdav']}

        user = UserManager.DictionaryToUser(dict)

        assert user.firstName == "test"
Пример #6
0
    def test_UserDict():
        """ Unit test for UserToDictionary function """

        newUser = User("beaf;o", "test", ["koidw"])

        dict = UserManager.UserToDictionary(newUser)

        assert dict['lastName'] == "test"
Пример #7
0
	def testLoginCase(self):
		'''
		Тест Case-a
		'''
		test_name = "testuser"
		test_pass = "******"
		test_code = 0
		real_code = UserManager.connectUser(test_name, test_pass)
		self.assertTrue(test_code < real_code)
Пример #8
0
    def test_AddUser():
        """ Unit test for addUser function """

        newUser = User("eaf", "foperski", ["fea"])
        list = []

        list = UserManager.addUser(list, newUser)

        assert len(list) == 1
Пример #9
0
	def testPassCase(self):
		'''
		Тест Case-a
		'''
		test_name = "TestUser"
		test_pass = "******"
		test_code = -102
		real_code = UserManager.connectUser(test_name, test_pass)
		self.assertEqual(test_code, real_code)
Пример #10
0
	def testEmptyPass(self):
		'''
		Тест пустого пароля
		'''
		test_name = "TestUser"
		test_pass = ''
		test_code = -102
		real_code = UserManager.connectUser(test_name, test_pass)
		self.assertEqual(test_code, real_code)
Пример #11
0
	def testEmptyLogin(self):
		'''
		Тест пустого логина
		'''
		test_name = ''
		test_pass = "******"
		test_code = -101
		real_code = UserManager.connectUser(test_name, test_pass)
		self.assertEqual(test_code, real_code)
Пример #12
0
	def testBadPass(self):
		'''
		Тест плохого пароля
		'''
		test_name = "TestUser"
		test_pass = "******"
		test_code = -102
		real_code = UserManager.connectUser(test_name, test_pass)
		self.assertEqual(test_code, real_code)
Пример #13
0
    def testBadLogin(self):
        '''
		Тест плохого логина
		'''
        test_name = "UserNotExist"
        test_pass = "******"
        test_code = -101
        real_code = UserManager.connectUser(test_name, test_pass)
        self.assertEqual(test_code, real_code)
Пример #14
0
    def testLoginCase(self):
        '''
		Тест Case-a
		'''
        test_name = "testuser"
        test_pass = "******"
        test_code = 0
        real_code = UserManager.connectUser(test_name, test_pass)
        self.assertTrue(test_code < real_code)
Пример #15
0
    def testPassCase(self):
        '''
		Тест Case-a
		'''
        test_name = "TestUser"
        test_pass = "******"
        test_code = -102
        real_code = UserManager.connectUser(test_name, test_pass)
        self.assertEqual(test_code, real_code)
Пример #16
0
    def testEmptyLogin(self):
        '''
		Тест пустого логина
		'''
        test_name = ''
        test_pass = "******"
        test_code = -101
        real_code = UserManager.connectUser(test_name, test_pass)
        self.assertEqual(test_code, real_code)
Пример #17
0
    def testEmptyPass(self):
        '''
		Тест пустого пароля
		'''
        test_name = "TestUser"
        test_pass = ''
        test_code = -102
        real_code = UserManager.connectUser(test_name, test_pass)
        self.assertEqual(test_code, real_code)
Пример #18
0
    def testBadPass(self):
        '''
		Тест плохого пароля
		'''
        test_name = "TestUser"
        test_pass = "******"
        test_code = -102
        real_code = UserManager.connectUser(test_name, test_pass)
        self.assertEqual(test_code, real_code)
Пример #19
0
	def testBadLogin(self):
		'''
		Тест плохого логина
		'''
		test_name = "UserNotExist"
		test_pass = "******"
		test_code = -101
		real_code = UserManager.connectUser(test_name, test_pass)
		self.assertEqual(test_code, real_code)
Пример #20
0
    def testGoodData(self):
        '''
		Метод начальной инициализации
		'''
        test_name = "TestUser"
        test_pass = "******"
        test_code = 0
        real_code = UserManager.connectUser(test_name, test_pass)
        res = real_code > test_code
        self.assertTrue(res)
Пример #21
0
	def testGoodData(self):
		'''
		Метод начальной инициализации
		'''
		test_name = "TestUser"
		test_pass = "******"
		test_code = 0
		real_code = UserManager.connectUser(test_name, test_pass)
		res = real_code > test_code
		self.assertTrue(res)
Пример #22
0
    def modify_password(username, password, newpassword):
        """
        Update the password
        """
        resp = Response("OK")
        if UserManager.verify_match(username, password):
            """
            Update the password
            """
            try:
                usernm = UserManager._update_password(username, newpassword)

                mako_template = LOOKUP.get_template('modify_pwd.mako')

            except RuntimeError:
                resp = BadRequest("Username not found")
                return False, resp
        else:
            resp = BadRequest("Username/password mismatch")
            return False, resp
        return True, resp
Пример #23
0
	def authoriseContext(agentMessage):
		'''
		Контекст пакета авторизации
		'''
		context = {}
		context['type'] = 'auth'	
		#sessionRes = 1
		sessionRes = UserManager.connectUser(agentMessage['login'], agentMessage['password'])
		context['result'] = sessionRes
		context['description'] = 'Nothing'
		context['session_id'] = sessionRes
		return context
Пример #24
0
    def check_answer(self, answer, url):
        """
        Checks if the answer is correct
        :param username: Username given by the user
        :param answer: Answer to the question
        :return:
        """
        resp = Response("Username not found")
        try:
            # question_str = UserManager.verify_lostpwd(self.username,answer)

            if UserManager.verify_lostpwd(self.username, answer):

                template_args = {
                    'title': 'Password Recovery',
                    'password_title': 'New password: '******'newpassword_title': 'Confirm new password: '******'submit_text': 'Submit',
                    'url': url
                }

                mako_template = LOOKUP.get_template(self.mako_template3)
                resp.message = mako_template.render(**template_args)
            else:
                question_str = UserManager._read_lostqstn(self.username)
                template_args = {
                    'title': 'Password Recovery',
                    'question': 'Question: ',
                    'question_str': question_str,
                    'answer': 'Answer:',
                    'submit_text': 'Submit',
                    'wrong_answer': 1,
                    'url': url
                }

                mako_template = LOOKUP.get_template(self.mako_template2)
                resp.message = mako_template.render(**template_args)
        except RuntimeError:
            resp = BadRequest("Username not found")
        return resp
Пример #25
0
    def update_password(self, newpassword, url):
        """
        Updates the password
        :param username: Username given by the user
        :param newpassword: New Password selected by the user
        """
        resp = Response("OK")
        try:
            usernm = UserManager._update_password(self.username, newpassword)

            # mako_template = LOOKUP.get_template(self.mako_template3)

        except RuntimeError:
            resp = BadRequest("Username %s not found" % self.username)
        """
        Update the TOTP secret
        """
        try:
            totp_secret = UserManager._reset_totp(self.username)

            otpauth_link = 'otpauth://totp/%s?secret=%s' % (self.username,
                                                            totp_secret)
            qr_code = pyqrcode.create(otpauth_link)

            template_args = {
                'username': self.username,
                'totp_secret': totp_secret,
                'qr_blob': qr_code.png_as_base64_str(scale=5),
                'home_url': url
            }

            mako_template = LOOKUP.get_template('modify_totp.mako')
            resp.message = mako_template.render(**template_args)
        except RuntimeError:
            resp = BadRequest("Username not found")
        return resp
Пример #26
0
 def add_new_user():
     new_user = UserManager('prénom', 'nom', 'trigramme', 'email')
     new_user.nom = nom_entry.get().upper()
     new_user.prenom = prenom_entry.get().upper()
     new_user.email = email_entry.get().lower()
     new_user.set_trigramme()
     if new_user.nom == '' or new_user.prenom == '' or new_user.email == '':
         messagebox.showerror(title='Attention',
                              message='Complétez tous les champs.')
     else:
         new_user_pushed = self.db.push_new_auteur(new_user.user_tuple)
         if new_user_pushed:
             self.set_combobox_widgets()
             add_user_win.destroy()
             messagebox.showinfo(title='Info',
                                 message='Utilisateur ajouté.')
         else:
             messagebox.showinfo(
                 title='Info',
                 message='Database occupée, Essayez à nouveau.')
Пример #27
0
    def main():
        #MAIN FUNCTION OF THE PROGRAM
        
        movieList = [] #Main movie list of the program
        userList = [] #Main user list of the programs

        shouldExit = False #Set to true to exit loop

        initializationText = """ Hello! What would you like to do?
        User menu:
            1. Add a user
            2. Change a user's name
            3. Remove a user
        Movie menu:
            4. Add a movie
            5. Update a movie's price
            6. List all movies
        Miscellaneous menu:
            7. Order a movie
            8. List user's movie orders
            9. Search movies by rating
            10. Filter movies by actors

            0. Exit program
        """
        
        #Run Unit tests
        TestClass.RunTests()

        #The main lists of the program
        movieList = []
        userList = []

        #Populate the user list from the database
        try:
            userInfile = open("userDatabase", "rb")
        except:

            print("No user database found!")

        else:
            while True:
            
                try:
                    userList.append(UserManager.DictionaryToUser(pickle.load(userInfile)))
                except:
                    break
        
        #Populate the movie list from the database
        try:
            movieInfile = open("movieDatabase", "rb")
        except:

            print("No movie database found!")

        else:
            while True:
            
                try:
                    movieList.append(MovieManager.DictionaryToMovie(pickle.load(movieInfile)))
                except:
                    break
                

        while shouldExit == False:
            #MAIN LOOP OF THE PROGRAM
            
            #Print the user menu
            print(initializationText)
            
            #Get user input
            try:
                userChoice = int( input("Your choice: ") )
            except ValueError:
                print("Choice is not an integer!")
                continue

            if userChoice == 0:
                #Exits program

                #Save the users to the database
                userOutfile = open("userDatabase", "wb")

                for user in userList:

                    dict = UserManager.UserToDictionary(user)
                    pickle.dump(dict, userOutfile)

                userOutfile.close()

                #Save the movies to the database
                movieOutfile = open("movieDatabase", "wb")

                for movie in movieList:

                    dict = MovieManager.MovieToDictionary(movie)
                    pickle.dump(dict, movieOutfile)

                movieOutfile.close()

                print("Goodbye!")
                shouldExit = True
        
            elif userChoice == 1:
                #Add user option
                newUser = UserManager.getUserInput()
                userList = UserManager.addUser(userList, newUser)         
            
            elif userChoice == 2:
                #Change a user's name          
                userList = UserManager.updateLastname(userList)

            elif userChoice == 3:
                #Remove a user           
                #Check the list isn't empty
                if len(userList) == 0:
        
                    print("The user list is empty!")
                    continue
                
                UserManager.printUsers(userList)

                try:
                    removeUserChoice = int(input("Which user would you like to remove? Index: "))
                except ValueError:
                    print("Choice is not an integer!")
                    continue

                #Clamp the value of the index between the min and the max indexes
                if removeUserChoice < 0:
        
                    removeUserChoice = 0
    
                elif removeUserChoice > len(userList) - 1:

                    removeUserChoice = len(userList) - 1
            
                #Remove the selected user
                del userList[removeUserChoice]

            elif userChoice == 4:
                #Add a movie

                newMovie = MovieManager.getMovieInput()
                movieList = MovieManager.addMovie(movieList, newMovie)
            
            elif userChoice == 5:
                #Update a movie's price

                movieList = MovieManager.updatePrice(movieList)

            elif userChoice == 6:
                #List all movies
            
                MovieManager.printMovies(movieList)

            
            elif userChoice == 7:
                #Order a movie
            
                userList = MiscManager.orderMovies(userList, movieList)

            elif userChoice == 8:
                #List all user's movie orders
                        
                UserManager.printUsers(userList)

            elif userChoice == 9:
                #Search all movies by rating
            
                MiscManager.searchMoviesByRating(movieList)

            elif userChoice == 10:
                #Filter movies by actors
            
                MiscManager.searchMoviesByActor(movieList)
Пример #28
0
 def login(self, name, password):
     self.msg_code = UserManager.connectUser(name, password)
     return self.msg_code
Пример #29
0
class Tests(object):
	def setup_method(self):
		self.centreManager = CentreManager()
		self.userManager = UserManager(self.centreManager)
		self.appointmentManager = AppointmentManager()
		self.centreManager.addProviders(self.userManager)

# (1) BOOK AN APPOINTMENT
	# 4 
			
	# (i) Testing that the appointment added is in the patient class and the provider class
	def test_book_appointment(self): ##
		self.appointmentManager.addAppointment(self.userManager, "*****@*****.**",
			"*****@*****.**",  "00.00-00.30", "12/31/2018","Biopsy Required")

		# Check that the appointment is in the provider class
		provider = self.userManager.getID("*****@*****.**")
		providerAppointment = provider.getSpecificAppointment(0)
		assert(providerAppointment.provider == "*****@*****.**")
		assert(providerAppointment.patient == "*****@*****.**")
		assert(providerAppointment.date == "12/31/2018")
		assert(providerAppointment.time == "00.00-00.30")
		assert(providerAppointment.reason == "Biopsy Required")
		
		# Check that the appointment is in the patient class
		patient = self.userManager.getID("*****@*****.**")
		patientAppointment = patient.getSpecificAppointment(0)
		assert(patientAppointment.provider == "*****@*****.**")
		assert(patientAppointment.patient == "*****@*****.**")
		assert(patientAppointment.date == "12/31/2018")
		assert(patientAppointment.time == "00.00-00.30")
		assert(patientAppointment.reason == "Biopsy Required")  
		
	# (ii) Check that booking an appointment in the same timeslot does not work
	def test_book_same_time_slot_appointment(self): ##
		self.appointmentManager.addAppointment(self.userManager, "*****@*****.**",
			"*****@*****.**",  "00.00-00.30", "12/31/2018", "Influenza")

		status = self.appointmentManager.addAppointment(self.userManager, "*****@*****.**",
			"*****@*****.**",  "00.00-00.30", "12/31/2018","Same Time slot")

		assert(status == "Time Slot Taken")
	
	# (iii) provider makes an appointment for himself/herself
	def test_provider_makes_appointment(self): ##
		status = self.appointmentManager.addAppointment(self.userManager, "*****@*****.**",
			"*****@*****.**", "00.00-00.30", "12/1/2018", "Arthiritis")

		assert(status == "Provider making appointment")

	# (additional) Check that you cannot book an appointment in the past
	def test_book_past_appointment(self): ##
		status = self.appointmentManager.addAppointment(self.userManager, "*****@*****.**",
			"*****@*****.**",  "00.00-00.30", "09/24/2018","Constipation")

		assert(status == "Date in the past")

# (2) VIEW PATIENT HISTORY	
	# 2	
	# testing that the history is saved and can be accessed
	def test_get_appointment_history(self): ##
		self.appointmentManager.addAppointment(self.userManager, "*****@*****.**",
			"*****@*****.**",  "00.00-00.30", "12/31/2018", "High Blood Pressure")

		self.appointmentManager.addAppointment(self.userManager, "*****@*****.**",
			"*****@*****.**",  "00.30-01.00", "12/31/2018","Vomiting")

		user = self.userManager.getID("*****@*****.**")
		assert(len(self.appointmentManager.getAppointments(user)) == 2) 

	# test updating with multiple people booking and 2 wanting the same time
	def multiple_appointments_clash(self):
		self.appointmentManager.addAppointment(self.userManager, "*****@*****.**",
			"*****@*****.**",  "04.00-04.30", "12/31/2018","Biopsy Required")
		
		self.appointmentManager.addAppointment(self.userManager, "*****@*****.**", 
			"*****@*****.**", "00.30-01.00", "12/31/2018", "Mole on foot")

		# this appointment has the same time and date as the previous appointment   
		clash = self.appointmentManager.addAppointment(self.userManager, "*****@*****.**",
			"*****@*****.**",  "00.30-01.00", "12/31/2018","Mole on foot")
			
		assert(clash == "Time Slot Taken")

		user = self.userManager.getID("*****@*****.**") 
		assert(len(self.appointmentManager.getAppointments(user)) == 1)	 
	
# (3) MANAGE A PATIENT HISTORY
	# 4	
	# test to ensure the provider can update appointment with notes and medicine prescribed 
	def notes_and_medicine(self):
		self.appointmentManager.addAppointment(self.userManager, "*****@*****.**",
			"*****@*****.**",  "09.00-09.30", "11/23/2018","Biopsy Required")    
			
		user = self.userManager.getID("*****@*****.**")
		appointment = self.appointmentManager.getAppointmentUsingDate(user, 
			"11/23/2018", "09.00-09.30")
			
		notes = "Baby Shark"
		medicine = "Doo doo doo doo"
		
		self.appointmentManager.updateAppointment(appointment, notes, medicine)
		
		assert(appointment.notes == "Baby Shark")
		assert(appointment.prescribedMedicine == "Doo doo doo doo")	 
		
	# updating notes from a previously inputted notes and medicine
	def test_update_appointment(self): ##
		self.appointmentManager.addAppointment(self.userManager, "*****@*****.**",
			"*****@*****.**",  "09.00-09.30", "11/23/2018", "Biopsy Required")

		user = self.userManager.getID("*****@*****.**")
		appointment = self.appointmentManager.getAppointmentUsingDate(user, 
			"11/23/2018", "09.00-09.30")
			
		appointment.notes = "This person did not require a doctor"
		appointment.prescribedMedicine = "Obecalp pills"
		
		newNotes = "I was wrong"
		newMedicine = "Sugar"
		
		self.appointmentManager.updateAppointment(appointment, newNotes, newMedicine)
		assert(appointment.notes == "This person did not require a doctor\nI was wrong")
		assert(appointment.prescribedMedicine == "Obecalp pills\nSugar")
		
	# updating notes then realising no updates are needed -> NULL submission          
	def test_update_appointment_with_nothing(self): ##
		self.appointmentManager.addAppointment(self.userManager, "*****@*****.**",
			"*****@*****.**",  "08.00-08.30", "11/23/2018", "Biopsy Required")

		user = self.userManager.getID("*****@*****.**")
		appointment = self.appointmentManager.getAppointmentUsingDate(user, 
			"11/23/2018", "08.00-08.30")
		appointment.notes = "This person did not require a doctor"
		appointment.prescribedMedicine = "Obecalp pills"
		
		newNotes = ""
		newMedicine = ""
		
		self.appointmentManager.updateAppointment(appointment, newNotes, newMedicine)
		assert(appointment.notes == "This person did not require a doctor\n")
		assert(appointment.prescribedMedicine == "Obecalp pills\n")
			
	# Test getting the history with an email that does not have any appointments    
	def test_get_wrong_id_history(self): ##
		self.appointmentManager.addAppointment(self.userManager, "*****@*****.**",
			"*****@*****.**", "00.00-00.30", "12/31/2018", "Biopsy Required")

		self.appointmentManager.addAppointment(self.userManager, "*****@*****.**", 
			"*****@*****.**", "00.30-01.00", "12/31/2018", "Mole on foot")
		
		user = self.userManager.getID("*****@*****.**")
		assert(len(self.appointmentManager.getAppointments(user)) == 0)
Пример #30
0
 def logout(self, userid, session_id):
     self.msg_code = UserManager.disconnectUser(userid, session_id)
     return self.msg_code
Пример #31
0
 def setup_method(self):
     self.centreManager = CentreManager()
     self.userManager = UserManager(self.centreManager)
     self.appointmentManager = AppointmentManager()
     self.centreManager.addProviders(self.userManager)
Пример #32
0
class Tests(object):
    def setup_method(self):
        self.centreManager = CentreManager()
        self.userManager = UserManager(self.centreManager)
        self.appointmentManager = AppointmentManager()
        self.centreManager.addProviders(self.userManager)
#this will be where tests for user stories are conducted
# According to the google doc
# 1: Book and Appointment
# US7
# "User-Story Description:
# As a patient, I want to book an appointment so I can receive healthcare service easily
# Acceptance Criteria:
# Enter required information including Medicare number into a form
# Be able to book an appointment through a healthcare provider?s or centre?s profile page
# Have an option of 48 equally sized time slots, each of which is 30 minutes long
# Be able to enter brief information for the appointment
# Be able to display a confirmation that the appointment has been booked to the user

# 2: View Patient History
# US13
# User-Story Description:
# As a patient, I want to be able to view my own appointments history so I can easily access which appointments I have recently attended
# Acceptance Criteria:
# The list of appointments should have links to the profile pages of the corresponding health provider and healthcare centre
# The list of appointments should be chronological and listed with the date of appointment

# US15
# User-Story Description:
# As a healthcare provider, I want to be able to view a patient?s appointment history so I can consult with the patient accordingly
# Acceptance Criteria:
# The patient?s appointment history should be accessed through their profile page
# A description of what occured in a specific appointment should be viewable, including any medication prescribed and notes taken at the previous visit

# 3: Manage a patient history

# 	def addAppointment(self, userManager, provider_email, patient_email, date, time, reason):

# Testing that the appointment added is in the patient class and the provider class

    def test_book_appointment(self):
        self.appointmentManager.addAppointment(self.userManager,
                                               "*****@*****.**",
                                               "*****@*****.**", "00.00-00.30",
                                               "12/31/2018", "Biopsy Required")

        # Check that the appointment is in the provider class
        provider = self.userManager.getID("*****@*****.**")
        providerAppointment = provider.getSpecificAppointment(0)
        assert (providerAppointment.provider == "*****@*****.**")
        assert (providerAppointment.patient == "*****@*****.**")
        assert (providerAppointment.date == "12/31/2018")
        assert (providerAppointment.time == "00.00-00.30")
        assert (providerAppointment.reason == "Biopsy Required")

        # Check that the appointment is in the patient class
        patient = self.userManager.getID("*****@*****.**")
        patientAppointment = patient.getSpecificAppointment(0)
        assert (patientAppointment.provider == "*****@*****.**")
        assert (patientAppointment.patient == "*****@*****.**")
        assert (patientAppointment.date == "12/31/2018")
        assert (patientAppointment.time == "00.00-00.30")
        assert (patientAppointment.reason == "Biopsy Required")

    # Check that booking an appointment in the same timeslot does not work
    def test_book_same_time_slot_appointment(self):
        self.appointmentManager.addAppointment(self.userManager,
                                               "*****@*****.**",
                                               "*****@*****.**", "00.00-00.30",
                                               "12/31/2018", "Biopsy Required")

        status = self.appointmentManager.addAppointment(
            self.userManager, "*****@*****.**", "*****@*****.**", "00.00-00.30",
            "12/31/2018", "Same Time slot")

        assert (status == "Time Slot Taken")

    # Check that you cannot book an appointment in the past
    def test_book_past_appointment(self):
        status = self.appointmentManager.addAppointment(
            self.userManager, "*****@*****.**", "*****@*****.**",
            "00.00-00.30", "09/24/2018", "Biopsy Required")

        assert (status == "Date in the past")

    # provider makes an appointment for himself/herself
    def test_provider_makes_appointment(self):
        status = self.appointmentManager.addAppointment(
            self.userManager, "*****@*****.**", "*****@*****.**",
            "00.00-00.30", "12/1/2018", "Biopsy Required")

        assert (status == "Provider making appointment")

    # Test that getting the history works
    def test_get_appointment_history(self):
        self.appointmentManager.addAppointment(self.userManager,
                                               "*****@*****.**",
                                               "*****@*****.**", "00.00-00.30",
                                               "12/31/2018", "Biopsy Required")

        self.appointmentManager.addAppointment(self.userManager,
                                               "*****@*****.**",
                                               "*****@*****.**", "00.30-01.00",
                                               "12/31/2018", "Mole on foot")

        user = self.userManager.getID("*****@*****.**")
        assert (len(self.appointmentManager.getAppointments(user)) == 2)

    # Test getting the history with an email that does not have any appointments
    def test_get_wrong_id_history(self):
        self.appointmentManager.addAppointment(self.userManager,
                                               "*****@*****.**",
                                               "*****@*****.**", "00.00-00.30",
                                               "12/31/2018", "Biopsy Required")

        self.appointmentManager.addAppointment(self.userManager,
                                               "*****@*****.**",
                                               "*****@*****.**", "00.30-01.00",
                                               "12/31/2018", "Mole on foot")

        user = self.userManager.getID("*****@*****.**")
        assert (len(self.appointmentManager.getAppointments(user)) == 0)

    # Test updating an appointment
    def test_update_appointment(self):
        self.appointmentManager.addAppointment(self.userManager,
                                               "*****@*****.**",
                                               "*****@*****.**", "00.00-00.30",
                                               "12/31/2018", "Biopsy Required")

        # def getAppointmentUsingDate(self, user, date, time)
        user = self.userManager.getID("*****@*****.**")
        appointment = self.appointmentManager.getAppointmentUsingDate(
            user, "12/31/2018", "00.00-00.30")
        appointment.notes = "Original Notes"
        appointment.prescribedMedicine = "Original Medicine"
        notes = "Updated Notes"
        medicine = "Updated Medicine"
        self.appointmentManager.updateAppointment(appointment, notes, medicine)
        assert (appointment.notes == "Original Notes\nUpdated Notes")
        assert (appointment.prescribedMedicine ==
                "Original Medicine\nUpdated Medicine")

    # Test updating history with nothing
    def test_update_appointment_nothing(self):
        self.appointmentManager.addAppointment(self.userManager,
                                               "*****@*****.**",
                                               "*****@*****.**", "00.00-00.30",
                                               "12/31/2018", "Biopsy Required")

        # def getAppointmentUsingDate(self, user, date, time)
        user = self.userManager.getID("*****@*****.**")
        appointment = self.appointmentManager.getAppointmentUsingDate(
            user, "12/31/2018", "00.00-00.30")
        appointment.notes = "Original Notes"
        appointment.prescribedMedicine = "Original Medicine"

        self.appointmentManager.updateAppointment(appointment, "", "")
        assert (appointment.notes == "Original Notes\n")
        assert (appointment.prescribedMedicine == "Original Medicine\n")
Пример #33
0
 def get_friendly_name(self) -> str:
     lid = request.cookies.get('Login_ID')
     if not (lid in self.mem):
         return ''
     return UserManager().get_friendly_name(self.mem[lid])
Пример #34
0
 def get_privilege(self) -> int:
     lid = request.cookies.get('Login_ID')
     if not (lid in self.mem):
         return -1  # lowest Privilege for Guests
     return UserManager().get_privilege(self.mem[lid])
Пример #35
0
	def login (self, name, password):
		self.msg_code = UserManager.connectUser(name, password)
                return self.msg_code
Пример #36
0
	def logout (self, userid, session_id):
		self.msg_code = UserManager.disconnectUser(userid, session_id)
                return self.msg_code
Пример #37
0
    def orderMovies(userList, movieList):
        """ Add an order to a user's order list. Print the final price
            In: List of users, List of movies
            Out: List of users """

        localUserList = userList.copy()
        localMovieList = movieList.copy()

        #Check if the lists are empty
        if len(localMovieList) == 0:

            print("The movie list is empty!")
            return localUserList

        if len(localUserList) == 0:
            print("The user list is empty!")
            return localUserList

        #USER PART
        UserManager.printUsers(localUserList)

        #Get the user for which to place the order
        while True:
            try:
                userChoice = int(
                    input(
                        "Select the user for which to place the order; Index:")
                )
            except ValueError:
                print("Choice is not an integer!")
            else:
                break

        #Clamp the index between the min and max indexes
        if userChoice < 0:

            userChoice = 0

        elif userChoice > len(localUserList) - 1:

            userChoice = len(localUserList) - 1

        selectedUser = localUserList[userChoice]

        #MOVIE PART
        MovieManager.printMovies(localMovieList)

        totalPrice = 0
        currentOrder = []

        while True:
            try:
                nrOfMovies = int(
                    input("How many movies would you like to order? "))
            except ValueError:
                print("Choice is not an integer!")
            else:
                break

        for i in range(nrOfMovies):

            while True:
                try:
                    movieIndex = int(
                        input("Which movie would you like to order? Index: "))
                except ValueError:
                    print("Choice is not an integer!")
                else:
                    break

            #Clamp the index between the min and max indexes
            if movieIndex < 0:

                movieIndex = 0

            elif movieIndex > len(localMovieList) - 1:

                movieIndex = len(localMovieList) - 1

            currentOrder.append(localMovieList[movieIndex].title)
            totalPrice += localMovieList[movieIndex].price

        userOrders = selectedUser.orders.copy()
        userOrders.append(currentOrder)

        localUserList[userChoice].orders = userOrders

        print("Total price of the order: " + str(totalPrice))

        return localUserList