Ejemplo n.º 1
0
    def test_buy_rawgs(self):
        # setup
        rawg_demands = [30, 20, 100, 10]
        rawg_prices = [11, 14, 1, 4]
        rawgs_bought = [30, 20, 40, 10]
        for i,(d,p) in enumerate(zip(rawg_demands, rawg_prices)):
            market.add_player(username=i, cash=1000, rawg_demand=d, rawg_price=p)

        # market stuff
        market.buy_rawgs()

        # assert
        for i, r in enumerate(rawgs_bought):
            self.assertEqual(r, market.players[i].rawg_quantity )
Ejemplo n.º 2
0
    def test_sell_rigs(self):
        # setup
        rig_quantities = [100, 80, 20, 0]
        rig_supplies   = [30,  20, 10, 0]
        rig_prices     = [6,   14, 10, 4]
        rigs_sold      = [30,  20, 10, 0]
        i = 0
        for i, (q,s,p) in enumerate(zip(rig_quantities, rig_supplies, rig_prices)):
            market.add_player(username=i, rig_quantity=q, rig_supply=s, rig_price=p, cash=0)

        # market stuff
        market.sell_rigs()

        #assert
        for i,(q,s) in enumerate(zip(rig_quantities, rigs_sold)):
            self.assertEqual(q-s, market.players[i].rig_quantity)
Ejemplo n.º 3
0
def login():
    if request.method == 'POST':
        username = request.form['username']
        if not username: # empty string is not allowed
            flash('Invalid username.')
            return redirect(url_for('login'))
        if username in market.players:
            flash('That username is already taken.')
            return redirect(url_for('login'))
        else:
            market.add_player(username)
        session['username'] = request.form['username']
        return redirect(url_for('index'))

    # request.method == 'GET'
    if 'username' in session: # already logged in
        return redirect(url_for('index'))
    return render_template('login.html')