def test_saves_retrieves_games(self): a_player = Player() a_player.save() first_game = Game() first_game.text = "a_score : a_player" first_game.player = a_player first_game.save() second_game = Game() second_game.text = "b_score : b_player" second_game.player = a_player second_game.save() saved_player = Player.objects.first() self.assertEqual(saved_player, a_player) saved_games = Game.objects.all() self.assertEqual(saved_games.count(), 2) first_saved_game = saved_games[0] second_saved_game = saved_games[1] self.assertEqual(first_saved_game.text, "a_score : a_player") self.assertEqual(second_saved_game.text, "b_score : b_player") self.assertEqual(first_saved_game.player, a_player) self.assertEqual(second_saved_game.player, a_player)
def setUpTestData(cls): super().setUpTestData() cls.game = Game(name="F-Zero") cls.game.save() ct1 = ChartType(name="CT1", game=cls.game, format_spec=[], order_ascending=True) ct1.save() cls.cg_kl = ChartGroup(name="Knight League", order_in_parent=1, game=cls.game) cls.cg_kl.save() cls.cg_ql = ChartGroup(name="Queen League", order_in_parent=2, game=cls.game) cls.cg_ql.save() cls.cg_mc1 = ChartGroup(name="Mute City I", order_in_parent=1, game=cls.game, parent_group=cls.cg_kl) cls.cg_mc1.save() cls.chart_mc1c = Chart(name="Course Time", order_in_group=1, chart_group=cls.cg_mc1, chart_type=ct1) cls.chart_mc1c.save() game_2 = Game(name="F-Zero: Maximum Velocity") game_2.save() ChartGroup(name="Pawn Cup", order_in_parent=1, game=game_2).save()
def setUp(self): self.user = User.objects.create_user('user1', '', 'password') self.player = Player(user=self.user) self.player.save() self.winning_game = Game() self.losing_game = Game() self.in_progress_game = Game() self.winning_game.save() self.losing_game.save() self.in_progress_game.save() self.winning_team = Team( game=self.winning_game, player=self.player, alive=True, winner=True ) self.losing_team = Team( game=self.losing_game, player=self.player, alive=False, winner=False ) self.in_progress_team = Team( game=self.in_progress_game, player=self.player, alive=True, winner=False ) self.winning_team.save() self.losing_team.save() self.in_progress_team.save()
def test_ship_creation(self): """Test that Ship instances are created correctly.""" game = Game() game.save() user = User(username='******', password='******') user.save() player = Player(user=user) player.save() team = Team(player=player, game=game) team.save() ship = Ship( team=team, x=0, y=0, length=3, direction=Ship.CARDINAL_DIRECTIONS['WEST'] ) self.assertTrue(isinstance(ship, Ship)) self.assertEqual( str(ship), 'Game 1 - user\'s 3L at (0, 0) facing West' )
def create(self, request): serializer = GameSerializer(data=request.data) if serializer.is_valid(): user = request.user player = user.player player.hosted_count += 1 player.game_count += 1 if request.data['nickname'] != "": player.nickname = request.data['nickname'] elif player.nickname == "": player.nickname = player.user.username player.save() new_game = Game() new_game.host = player new_game.name = request.data['name'] new_game.motto = request.data['motto'] new_game.passcode = request.data['passcode'] new_game.save() new_game_player_detail = GamePlayerDetail() new_game_player_detail.game = new_game new_game_player_detail.player = player new_game_player_detail.save() return Response({'status': 'game set', 'game_id': new_game.id}) else: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def setUpTestData(cls): super().setUpTestData() cls.game = Game(name="BS F-Zero Grand Prix 2") cls.game.save() cls.ct1 = ChartType(name="CT1", game=cls.game, format_spec=[], order_ascending=True) cls.ct1.save() cls.cg_mc4 = ChartGroup(name="Mute City IV", order_in_parent=1, game=cls.game) cls.cg_mc4.save() cls.cg_bb2 = ChartGroup(name="Big Blue II", order_in_parent=2, game=cls.game) cls.cg_bb2.save() cls.chart_mc4c = Chart(name="Course Time", order_in_group=1, chart_group=cls.cg_mc4, chart_type=cls.ct1) cls.chart_mc4c.save() cls.chart_mc4l = Chart(name="Lap Time", order_in_group=2, chart_group=cls.cg_mc4, chart_type=cls.ct1) cls.chart_mc4l.save() cls.chart_bb2c = Chart(name="Course Time", order_in_group=1, chart_group=cls.cg_bb2, chart_type=cls.ct1) cls.chart_bb2c.save()
def post(self, request): body = request.body if not body.decode('UTF-8'): return Response(status=status.HTTP_400_BAD_REQUEST) body = json.loads(body) host_uuid = body.get("host_uuid") if not host_uuid: return Response("host_uuid field is needed", status=status.HTTP_400_BAD_REQUEST) host = get_object_or_404(User, id=host_uuid) quiz_uuid = body.get("quiz_uuid") if not quiz_uuid: return Response("quiz_uuid field is needed", status=status.HTTP_400_BAD_REQUEST) quiz = get_object_or_404(Quiz, uuid=quiz_uuid) game_name = body.get("game_name") if not game_name: return Response("game_name field is needed", status=status.HTTP_400_BAD_REQUEST) name_taken = Game.objects.filter(game_name=game_name) if name_taken: return Response("Name is taken, choose a new name", status=status.HTTP_400_BAD_REQUEST) new_game = Game(game_name=game_name, host=host, quiz=quiz) new_game.save() new_game.init_game() return Response(GameSerializer(new_game).data, status=status.HTTP_201_CREATED)
def send_contractor_on_game(self, character): game = Game( scenario=self.scenario, title="title", creator=self.user2, gm=self.user2, created_date=timezone.now(), scheduled_start_time=timezone.now(), actual_start_time=timezone.now(), end_time=timezone.now(), status=GAME_STATUS[6][0], cell=self.cell, ) game.save() attendance = Game_Attendance( relevant_game=game, notes="notes", outcome=WIN, attending_character=character, ) game_invite = Game_Invite(invited_player=character.player, relevant_game=game, as_ringer=False, ) attendance.save() game_invite.attendance = attendance game_invite.save() game.give_rewards() return attendance
def new_game(request): """ Creates a new game. player_id should already be stored inside cookie. """ private = (request.POST['isPrivate'] == 'on' if 'isPrivate' in request.POST else False) game_type = request.POST['gameType'] player_id = sessions.get_player_id(request.session) player = Player.get_by_id(Player.get_model_id(player_id)) game = Game(game_type=game_type, creator=player, private=private, current_turn=player) game.save() game_id = Game.get_game_id(game.id) game.game_id = game_id game.save() text = 'Game created' entry = GameLogEntry(game=game, text=text) entry.save() # Send a ws message to the lobby group Group('lobby').send({'text': json.dumps(Game.get_all_games_list())}) return HttpResponseRedirect(reverse('games:game', args=(game.id,)))
def mutate_and_get_payload(root, info, **input): if input.get("collectionname"): collection, created = Collection.objects.get_or_create(collectionname=input.get("collectionname")) game=Game(name=input.get("name"), price=input.get("price"), datereleased=input.get("datereleased"), collection=collection ) else: game=Game(name=input.get("name"), price=input.get("price"), datereleased=input.get("datereleased"), ) game.save() return addGame(game=game)
def put_games(): category1 = Category.query.get(1) category2 = Category.query.get(2) new_game = Game("FIFA19") new_game.categories.append(category1) new_game.categories.append(category2) db.session.add(new_game) new_game = Game("SubwayRunner") new_game.categories.append(category2) db.session.add(new_game) db.session.commit() return "Games Created!"
def submit_game(request): cur_user = Account.objects.get(id=request.user.id) if cur_user.account_type == 'player': #no permission if user is not a developer return render(request, 'unpermitted.html') else: if request.method == 'POST': form = SubmitForm(request.POST, request.FILES) if form.is_valid(): #insert the new game into db game = Game(title=form.cleaned_data.get('title'), description=form.cleaned_data.get('description'), price=form.cleaned_data.get('price'), genre=form.cleaned_data.get('genre'), link=form.cleaned_data.get('link'), developer=cur_user) #check if preview pic was submitted and if so, add it to the game if form.cleaned_data['preview_pic'] is not None: game.preview_pic = form.cleaned_data['preview_pic'] game.save() #make dev also an owner game.owners.add(cur_user) return HttpResponseRedirect('/accounts/profile/') else: form = SubmitForm() return render(request, 'submit.html', {'form': form})
def create_game(self, fake, teams, round_number): home_teams = teams[1::2] away_teams = teams[0::2] for i in range(len(home_teams)): home_score = fake.random_int(min=0, max=186, step=1) away_score = fake.random_int(min=0, max=186, step=1) winning_team = home_teams[ i] if home_score > away_score else away_teams[i] home = home_teams[i] if round_number == 'QF' else home_teams[ i].game_winning_team away = away_teams[i] if round_number == 'QF' else away_teams[ i].game_winning_team winner = winning_team if round_number == 'QF' else winning_team.game_winning_team try: game = Game(home_team=home, away_team=away, game_played=True, game_winning_team=winner, round_number=round_number, home_team_score=home_score, away_team_score=away_score, date=fake.date_time_this_decade(before_now=True, after_now=False, tzinfo=None)) except ObjectDoesNotExist: raise CommandError('games populated') game.save() self.stdout.write( self.style.SUCCESS( '%s Game %s Vs %s => winner : %s ' % (round_number, home.id, away.id, winner.id)))
def handle(self, *args, **options): g = Game(name="F-Zero GX") g.save() gx_time_spec = [ dict(multiplier=60, suffix="'"), dict(multiplier=1000, suffix='"', digits=2), dict(digits=3)] course = ChartType( game=g, name="Course Time", format_spec=gx_time_spec, order_ascending=True) course.save() lap = ChartType( game=g, name="Lap Time", format_spec=gx_time_spec, order_ascending=True) lap.save() speed = ChartType( game=g, name="Speed", format_spec=[dict(suffix=" km/h")], order_ascending=False) speed.save() machine = FilterGroup( game=g, name="Machine", show_by_default=True, order_in_game=1, description="Racing machine used for the run.", kind=FilterGroup.Kinds.SELECT.value) machine.save() setting = FilterGroup( game=g, name="Setting", show_by_default=True, order_in_game=2, description="Acceleration/max speed setting used for the run." " 0% all the way at the left, 100% all the way at" " the right.", kind=FilterGroup.Kinds.NUMERIC.value) setting.save() Filter(name="0%", numeric_value=0, filter_group=setting).save() Filter(name="100%", numeric_value=100, filter_group=setting).save() checks = FilterGroup( game=g, name="Checkpoint skips", show_by_default=False, order_in_game=3, description="Whether checkpoint skipping" " was used in the run or not.", kind=FilterGroup.Kinds.SELECT.value) checks.save() Filter(name="Yes", filter_group=checks).save() Filter(name="No", filter_group=checks).save() for ct in [course, lap, speed]: ct.filter_groups.add(machine, setting) for ct in [course, lap]: ct.filter_groups.add(checks) call_command('chart_import') call_command( 'filter_import', 'fzc_data_import/data/gx_machine_filters.csv') call_command( 'record_player_import_for_fzc', *[options[arg_name] for arg_name in ['mysql_host', 'mysql_port', 'mysql_dbname', 'mysql_user']])
def setUp(self): self.duke = School(abbrev="DUKE", name="Duke") self.maryland = School(abbrev="MARY", name="Maryland") self.season = Season(year=2012, start_date="2011-11-01", end_date="2012-04-15") self.duke_2012 = Team(school=self.duke, season=self.season) self.maryland_2012 = Team(school=self.maryland, season=self.season) self.game = Game(team=self.duke_2012, opponent=self.maryland_2012)
def test_game_id(self): self._test_field_type(Game, 'Game', 'id', models.AutoField) game = Game(title=self.randstr, id=self.randint) game.save() self.assertEquals( game.id, self.randint, "Testing if id %s equals assigned id %s" % (game.id, self.randint)) game.delete()
def post(self, request, *args, **kwargs): if request.user.is_authenticated(): form = CreateGameForm(request.POST, max_players=MAX_PLAYERS) if form.is_valid(): opponent_usernames = [] for i in range(0, MAX_PLAYERS): field_name = 'opponent_username_{}'.format(i) opponent_usernames.append(form.cleaned_data[field_name]) try: opponent_users = [] for opponent_username in opponent_usernames: if len(opponent_username) > 0: opponent_users.append( User.objects.get(username=opponent_username)) except User.DoesNotExist: error_message = 'User does not exist! '\ 'Are you sure the username is correct?' messages.error(request, error_message) context = {'form': form} return render(request, self.template_name, context) user_player = Player.objects.get(user=request.user) opponent_players = [ Player.objects.get(user=opponent_user) for opponent_user in opponent_users ] # Create a game plus teams and ships for both players # Creation in Game -> Team -> Ships order is important # to satisfy ForeignKey dependencies. game = Game() game.save() user_team = Team(player=user_player, game=game, last_turn=-2) opponent_teams = [ Team(player=opponent_player, game=game, last_turn=-1) for opponent_player in opponent_players ] user_team.save() for opponent_team in opponent_teams: opponent_team.save() user_ships = make_ships(user_team, Ship.LENGTHS) for opponent_team in opponent_teams: opponent_ships = make_ships(opponent_team, Ship.LENGTHS) for user_ship in user_ships: user_ship.save() for opponent_ship in opponent_ships: opponent_ship.save() return HttpResponseRedirect(reverse('game', args=[game.id])) else: messages.error(request, 'Invalid form.') context = {'form': form} return render(request, self.template_name, context) else: return HttpResponseRedirect('/login')
def post(self): args = self.reqparse.parse_args(strict=True) abort_if_no_auth(args['token']) new_game = Game(args['title']) db.session.add(new_game) db.session.commit() return {"result": new_game.id}, 201
def test_game_slugify_on_save(self): """ Tests the slug generated when saving a Game. """ # Author is a required field in our model. # Create a user for this test and save it to the test database. user = User() user.save() # Create and save a new page to the test database. game = Game(name="My Test Game", description="test") game.save()
def setUp(self): self.game_id = "1" self.game_home_team = "1" self.game_away_team = "2" self.game_start_date = "2019-05-16" self.game_start_time = "2019-05-16T08:24:00" self.gameList = Game(home_team=self.game_home_team, away_team=self.game_away_team, start_date=self.game_start_date, start_time=self.game_start_time)
def setUp(self): self.game = Game() self.game.save() self.user = User.objects.create_user('user', '', 'password') self.player = Player(user=self.user) self.player.save() self.team = Team(player=self.player, game=self.game) self.team.save()
def setUp(self): self.game1 = Game() self.game2 = Game() self.game1.save() self.game2.save() self.user1 = User.objects.create_user('user1', '', 'password') self.user2 = User.objects.create_user('user2', '', 'password') self.player1 = Player(user=self.user1) self.player2 = Player(user=self.user2) self.player1.save() self.player2.save() self.team_game1 = Team(player=self.player1, game=self.game1) self.team_game2 = Team(player=self.player1, game=self.game2, alive=False) self.team_game1.save() self.team_game2.save()
def save(request, company_id, office_id): game_name = request.POST.get('name') game_mode = request.POST.get('mode') game_updated = timezone.now() game = Game(office_id=office_id, name=game_name, mode=game_mode, updated=game_updated) game.save() return HttpResponseRedirect('/company/' + str(company_id) + '/office/' + str(office_id) + '/game/' + str(game.id))
def test_archive_game_death(self): self.assertEquals(self.char_user1_cell.unspent_rewards().count(), 0) self.assertEquals(self.char_user1_cell.unspent_gifts().count(), 0) self.assertEquals(self.char_user1_cell.completed_games().count(), 0) self.assertEquals(self.char_user1_cell.number_of_victories(), 0) self.assertEquals(self.char_user1_cell.number_of_losses(), 0) self.assertEquals(self.char_user1_cell.stats_snapshot.sources.count(), 0) self.assertEquals(self.char_user1_cell.exp_earned(), EXP_NEW_CHAR) self.assertEquals( self.user1.rewarded_player .filter(rewarded_character=None, is_charon_coin=True) .filter(is_void=False).all().count(), 0) game = Game( title="title", creator=self.user2, gm=self.user2, created_date=timezone.now(), scheduled_start_time=timezone.now(), actual_start_time=timezone.now(), end_time=timezone.now(), status=GAME_STATUS[6][0], cell=self.cell, ) game.save() attendance = Game_Attendance( relevant_game=game, notes="notes", outcome=OUTCOME[2][0], # death attending_character=self.char_user1_cell, ) game_invite = Game_Invite(invited_player=self.user1, relevant_game=game, as_ringer=False, ) attendance.save() game_invite.attendance = attendance game_invite.save() game.give_rewards() self.assertEquals(self.char_user1_cell.unspent_rewards().count(), 0) self.assertEquals(self.char_user1_cell.unspent_gifts().count(), 0) self.assertEquals(self.char_user1_cell.completed_games().count(), 1) self.assertEquals(self.char_user1_cell.number_of_victories(), 0) self.assertEquals(self.char_user1_cell.number_of_losses(), 0) self.assertEquals(self.char_user1_cell.stats_snapshot.sources.count(), 0) self.assertEquals(self.char_user1_cell.exp_earned(), EXP_NEW_CHAR) self.assertEquals(self.char_user1_cell.is_dead(), True) self.assertEquals( self.user1.rewarded_player .filter(rewarded_character=None, is_charon_coin=True) .filter(is_void=False).all().count(), 1)
def setUpTestData(self): self.reqfactory = RequestFactory() # dummy platform for testing POST self.test_plat = Platform(name='Test Platform', display_color='ffffff') self.test_plat.save() # dummy game for testing POST self.test_game = Game(name='Test Game', platform=self.test_plat, start_date='2015-03-21', end_date='2015-04-02') self.test_game.save()
def create_game(request): if request.method == 'POST': form = make_game_form(user=request.user, game_status=GAME_STATUS[0][0])(request.POST) if form.is_valid(): game = Game( title=form.cleaned_data['title'], creator=request.user, gm=request.user, required_character_status=form. cleaned_data['required_character_status'], hook=form.cleaned_data['hook'], created_date=timezone.now(), scheduled_start_time=form.cleaned_data['scheduled_start_time'], open_invitations=form.cleaned_data['open_invitations'], status=GAME_STATUS[0][0], cell=form.cleaned_data['cell']) if form.cleaned_data['scenario']: game.scenario = form.cleaned_data['scenario'] with transaction.atomic(): game.save() if form.cleaned_data['invite_all_members']: for member in game.cell.cellmembership_set.exclude( member_player=game.gm): game_invite = Game_Invite( invited_player=member.member_player, relevant_game=game, invite_text=game.hook, as_ringer=False) game_invite.save() game_invite.notify_invitee(request, game) game_url = reverse('games:games_view_game', args=(game.id, )) messages.add_message( request, messages.SUCCESS, mark_safe( "Your Game has been created Successfully." "<br>" "<a href='" + game_url + "'> Click Here</a> " "if you do not want to invite anyone else at this time.")) return HttpResponseRedirect( reverse('games:games_invite_players', args=(game.id, ))) else: print(form.errors) return None else: # Build a game form. form = make_game_form(user=request.user, game_status=GAME_STATUS[0][0]) context = { 'form': form, } return render(request, 'games/edit_game.html', context)
def setUpTestData(cls): super().setUpTestData() cls.game = Game(name="G") cls.game.save() game_2 = Game(name="G") game_2.save() cg1 = ChartGroup(name="CG1", game=cls.game, order_in_parent=1) cg1.save() cls.ct1 = ChartType( name="CT1", game=cls.game, format_spec=[], order_ascending=True) cls.ct1.save() cls.ct2 = ChartType( name="CT2", game=cls.game, format_spec=[], order_ascending=True) cls.ct2.save() cls.c1 = Chart( name="C1", chart_group=cg1, order_in_group=1, chart_type=cls.ct1) cls.c1.save() cls.c2 = Chart( name="C2", chart_group=cg1, order_in_group=2, chart_type=cls.ct2) cls.c2.save() # Add FGs to game 1 specifying a different order from alphabetical # or FG ID, so we can tell the order field is respected. cls.fg1 = FilterGroup(name="FG1", game=cls.game, order_in_game=2) cls.fg1.save() cls.fg2 = FilterGroup(name="FG2", game=cls.game, order_in_game=1) cls.fg2.save() cls.fg3 = FilterGroup(name="FG3", game=cls.game, order_in_game=3) cls.fg3.save() cls.fg4 = FilterGroup(name="FG4", game=cls.game, order_in_game=4) cls.fg4.save() # Add one FG to game 2, so that we can tell we're only getting FGs # of game 1. cls.fg5 = FilterGroup(name="FG5", game=game_2, order_in_game=1) cls.fg5.save() # Don't link FG4, so we can tell we're only getting FGs of this CT. cls.ct1.filter_groups.add(cls.fg1, cls.fg2, cls.fg3)
def _create_tags(self): f = open(r'C:/Users/Sam/.spyder-py3/chessData.txt','r') line = f.readline() string = "" while line: if ("split" in line): tlisp = Game(pgn = string) tlisp.save() string = "" line = f.readline() continue if ('[' not in line): string += line line = f.readline()
def setUpTestData(cls): super().setUpTestData() cls.game = Game(name="G") cls.game.save() cls.ct1 = ChartType(game=cls.game, name="CT1", format_spec=[], order_ascending=True) cls.ct1.save() cls.fg1 = FilterGroup(game=cls.game, name="FG1", description="Test", order_in_game=1) cls.fg1.save()
def map(self, row): # Ensure that we have a game object to map to try: game = Game.objects.get(external_id=row['id']) except Game.DoesNotExist: game = Game() # Do the mapping... game.name = row['name'] game.external_id = row['id'] game.description = row['deck'] or '' game.release_date = row['original_release_date'][:10] return game