def setUp(self): super().setUp() with db.atomic() as txn: profile = Profile.create(username='******', hashed_password='******') self.token = AuthToken.create(profile=profile, token='thevalidtoken').token
def register(username: str, password: str): profile = Profile.get_or_none(Profile.username == username) if profile is not None: raise BadRequest('A user with this username already exists') hashed = bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode() profile = Profile.create( username=username, hashed_password=hashed, ) global_game = Game.get_or_none(Game.name == 'Global Indefinite') GameProfile.create(game=global_game, profile=profile, cash=global_game.starting_cash) global_game = Game.get_or_none(Game.name == 'Global Timed') GameProfile.create(game=global_game, profile=profile, cash=global_game.starting_cash) send_notification(profile, 'Welcome to Fortune!') send_notification( profile, 'Click the Play button in the menubar on top to create a new game.') send_notification( profile, 'To adjust account options, see achiements, and add friends, click on your username on the top and select Profile' ) return create_auth_token(profile)
def call(program, argv): parser = argparse.ArgumentParser(prog=program) parser.add_argument("dbid", help="new profile's account DBID", type=int) parser.add_argument("name", help="new profile's username") parser.add_argument("agent", help="new profile's agent") parser.add_argument("-u", "--uuid", help="new profile's UUID", type=UUID) args = parser.parse_args(argv) input_uuid = args.uuid if args.uuid is not None else uuid4() account: Account = Account.get(id=args.dbid) if account is None: print("No account matches that DBID!") exit(1) try: profile = Profile.create(uuid=input_uuid, agent=args.agent, account=account, name=args.name) except ExistsException: print("Name not available.") exit(1) try: commit() except Exception as e: print(str(e)) exit(1) print(profile)
def up(db): with db.atomic(): migrator = PostgresqlMigrator(db) db.bind(MODELS, bind_refs=False, bind_backrefs=False) db.create_tables(MODELS) if Coin.get_or_none(Coin.id == 1) is None: Coin.create(name='Bitcoin', symbol='BTC') Coin.create(name='Ethereum', symbol='ETH') Coin.create(name='Litecoin', symbol='LTC') Coin.create(name='Coin 3', symbol='CO3') Coin.create(name='Coin 4', symbol='CO4') Coin.create(name='Coin 5', symbol='CO5') global_indef = Game.create(name='Global Indefinite', starting_cash=10000.00, shareable_link='INDEF', shareable_code='INDEF', ends_at=None) # insert achievements into database Achievement.create( name="Win", description="Finish in first place in a private game") Achievement.create( name="Double net worth", description="Achieved by doubling your net worth in a game") Achievement.create(name="Identity Crisis", description="Change your username") # insert goals into database Goal.create(name="Entrepreneur", description="Create a private game") all_coins = Coin.select() for coin in all_coins: GameCoin.create(game=global_indef, coin=coin) global_timed = Game.create(name='Global Timed', starting_cash=10000.00, shareable_link='TIMED', shareable_code='TIMED', ends_at=datetime.utcnow() + timedelta(minutes=1)) # CHANGEME for devel purposes, making it 1 min for now GameCoin.create(game=global_timed, coin=Coin.get()) # from auth.services import register hashed = bcrypt.hashpw("admin".encode(), bcrypt.gensalt()).decode() admin = Profile.create(username="******", hashed_password=hashed, is_admin=True) # Required so that admin can still view graphs in the landing page GameProfile.create(profile=admin, game=global_indef, cash=0.0)
def setUp(self): super().setUp() with db.atomic() as txn: #don't need to create a game, migrations/v1.py gets run before every test #Coin.create(id=1, name='Bitcoin', symbol='BTC') Game.create(name='Game', starting_cash=10000.00, shareable_link='aaaabbbbccccdddd', shareable_code='aaaa', ends_at=(datetime.utcnow().replace(tzinfo=pytz.utc) + timedelta(days=7)).isoformat()) profile = Profile.create(username='******', hashed_password='******') self.token = AuthToken.create(profile=profile, token='thevalidtoken').token
def setUp(self): super().setUp() with db.atomic() as txn: self.game = Game.create( name='Game', starting_cash=10000.00, shareable_link='aaaabbbbccccdddd', shareable_code='aaaa', ends_at=(datetime.utcnow().replace(tzinfo=pytz.utc) + timedelta(days=7)).isoformat()) profile = Profile.create(username='******', hashed_password='******') GameProfile.create(game=self.game, profile=profile, cash=-1.0) Message.create( game=self.game.id, profile=profile.id, content="first message", # use default value for created_on ) self.token = AuthToken.create(profile=profile, token='thevalidtoken').token
def test_price_alerts(self): os.environ['NOMICS_BASE_URL'] = 'foo' profile = Profile.create(username='******', hashed_password='******') coin = Coin.create(name='foocoin', symbol='FOO') alert = PriceAlert.create( profile=profile, above=True, coin=coin, strike_price=Decimal(0.1), ) alert = PriceAlert.create( profile=profile, above=False, coin=coin, strike_price=Decimal(0.1), ) ping('FOO') self.assertEqual(1, Notification.select().count()) # ok, the line below throws an exception which causes all other tests to fail # as tearDown is not called and because db is in inconsistent state notif = Notification.get(Notification.profile == profile)
def test_can_create_db_record(self): username = '******' profile = Profile.create(username=username, hashed_password='******') self.assertEqual(username, profile.username) profile.delete_instance()