Пример #1
0
    def update_or_add_user(db_location, user):
        """
        Updates or addes the user to the Master Database

        :param user: User Dict to enter into Database
        :type users: dict that passes validate_user_dict
        :return: Record from the database
        :rtype: dict that conforms with user_schema
        """
        db = LMSLibraryDatabase(db_location)
        db_user = db.get_user(user["username"])
        if not db_user:
            db.add_user(user)
        else:
            db.update_user(user)
Пример #2
0
 def test_update_or_add_user_1(self):
     # Test user add
     user = {
         "first_name": "John",
         "last_name": "Smith",
         "email": "*****@*****.**",
         "username": "******"
     }
     test_db = "lms_library_config_test.json"
     db = LMSLibraryDatabase(test_db)
     user_list = list()
     user_list.append(user["username"])
     user_list.append(user["first_name"])
     user_list.append(user["last_name"])
     user_list.append(user["email"])
     MasterPi.update_or_add_user(test_db, user)
     db_user = db.get_user(user["username"])
     self.assertTupleEqual(tuple(user_list), db_user[0])