def generate_users(n): users = list() for i in range(n): user = User(faker.name()) user.username = faker.name() user.password = "******" try: db.session.add(user) db.session.commit() users.append(user) except Exception as e: log.error("Fail to add user %s: %s" % (str(user), e)) db.session.rollback() return users
def main(): user = User('John', 'password', '*****@*****.**', '12/25/1999') print(user.username) print(user.password) print(user) print() print(repr(user)) user2 = User("John", "password", "*****@*****.**", "12/25/1999") print(user == user2) print(user.check_password('1234')) user.username = '******' print(user.username) superuser = SuperUser('jon', 'password', '*****@*****.**', '12/24/1999', 'admin') print(superuser) print() print(repr(superuser)) print('ran demo.main')
#!/usr/bin/python import os, sys import hashlib sys.path.insert(1, os.path.join(sys.path[0], '../src')) from main import db, User items = ['NumerousDiamond', 'AcceptableVillage', 'InformalEditor', 'ImportantRoad', 'HistoricalPainting', 'SexualClimate', 'ConsistentConcept', 'DesperateCoffee', 'ScaredFood', 'OddCurrency', 'AsleepImportance', 'GuiltyManager', 'ScaredGrandmother', 'PoliticalChapter', 'UnusualEmphasis', 'DramaticArt', 'InnerHealth', 'SevereAssociation', 'NiceInternet', 'ElectronicAffair', 'MedicalFeedback', 'ElectricalArrival', 'LatterExplanation', 'SufficientApartment', 'CulturalPeople', 'DistinctGirl', 'DangerousIdea', 'SeriousMeaning', 'SuitableCity', 'HotApplication', 'EasternActivity', 'SeveralGrandmother', 'KnownInsurance', 'EducationalOven', 'IntelligentBeer', 'PoorMoment', 'AdministrativeManagement', 'StrictContext', 'EfficientCandidate', 'MentalTale'] for item in items: u = User() u.username = item u.email = item.lower()+'@pnyx.app' u.password = hashlib.sha384(os.urandom(24)).hexdigest() u.save()
def test_generates_valid_token(): user = User() user.id = 1 user.username = "******" assert user.generate_auth_token()
def test_throws_exception_when_generating_token_without_id(): user = User() user.username = "******" with pytest.raises(Exception): token = user.generate_auth_token()