def test_overharvest(self): slug = "TEST" + uuid.uuid4().hex gs = GameState.new(slug, 'pwd') recipe_id = CONFIG.general['firstRecipe'] seed_id = CONFIG.recipes[recipe_id]['seedId'] seed_data = CONFIG.seeds[seed_id] gs.buy(recipe_id) gs.sow(seed_id, 0, 0) plot = gs.get_plot(0, 0) plot['sowTime'] -= seed_data[ 'harvestTimeSeconds'] * 1000 + 3000 # set plant time to long enough ago that we can harvest cash_before = gs.data['resources'][CONFIG.CASH_RESOURCE] gs.data['seedCounts'][seed_id] = CONFIG.general['max_seed_count'] msg = gs.harvest(0, 0) # hacky way to extract number of seeds harvested seeds_generated = seed_data['seed'] if 'Got ' in msg: seeds_generated += int(msg.split('Got ')[1].split()[0]) cash_after = gs.data['resources'][CONFIG.CASH_RESOURCE] expected_cash_after = cash_before + seed_data['yield'][ CONFIG.CASH_RESOURCE] + seeds_generated * seed_data['sellCost'] self.assertEqual( cash_after, expected_cash_after, "Did not get the correct amount of money when breaking seed limit. Got $%s, expected $%s" % (cash_after, expected_cash_after))
def state(slug): valid_chars(slug) body = request.json if body['newOrLoad'] == 'new': game_state = GameState.new(slug, body['password']) if body['newOrLoad'] == 'load': game_state = GameState.load(slug, body['password']) if game_state is None: raise NotFound("Game %s does not exist" % slug) db.save(slug, game_state.data) return make_response(game_state)
def new_game_state(self): slug = "TEST" + uuid.uuid4().hex return GameState.new(slug, 'pwd')