def test_is_manager_of(self): t = Team(name="haha", tag="ha", region=self.bre, manager=self.s) t.save() TeamUser(team=t, summoner=self.s).save() self.assertTrue(self.s.is_manager_of(t)) t.manager = self.s2 t.save() self.assertFalse(self.s.is_manager_of(t))
def invite(name, leader, tel, mail): inv_code = str(random6()) if Pwd.objects.filter(mail=mail).count() > 0: return None pwd = Pwd(mail=mail, invite_code=inv_code, state=1) pwd.save() team = Team(pwd=pwd, name=name, leader=leader, contact_tel=tel) team.save() return pwd.invite_code
def test_leave_team_last(self): """ Set incative the team when nobody is here """ t = Team(name="haha", tag="ha", region=self.bre) t.save() TeamUser(team=t, summoner=self.s).save() self.s.leave_team(t) self.assertFalse(self.reload(t).active)
def start(self): c = int(self.count / 10) for i in range(c): t1 = Team( name='team_{}'.format(i), games=self.count, ) t2 = Team( name='team_{}'.format(i), games=self.count, ) t1.save(using='db1') t2.save(using='db2') for j in range(10): u = User(username='******'.format(j + 10 * i), email='ivan@ivan{}.ru'.format(j + 10 * i)) u.set_password('ivan123') u.first_name = 'ivan{}'.format(j + 10 * i) u.last_name = 'ivanov{}'.format(j + 10 * i) ran_db = random.randint(1, 2) u.id = int(get_pk() + str(ran_db)) print(u.id) u.save(using='db' + str(ran_db)) if ran_db == 1: tu = UserTeam( user=u, team=t1, ) else: tu = UserTeam( user=u, team=t2, ) tu.save(using='db' + str(ran_db)) cc = int(self.count / 100) for i in range(cc): t = Turn(name='turn{}'.format(i)) t.save(using='db1') t.save(using='db2') for j in range(10): m = Match(name='match{}'.format(j + 10 * i), turn_id=t.id) m.save(using='db1') m.save(using='db2') for l in range(10): g = Game(name='game___{}'.format(l + 10 * j + 100 * i), match_id=m.id) ran_db = random.randint(1, 2) g.id = int(get_pk() + str(ran_db)) g.save(using='db' + str(ran_db)) tm = Team.objects.using('db' + str(ran_db)).filter( name='team_{}'.format(j + 10 * i))[0] gt = GameTeam(game=g, team=tm) gt.save(using='db' + str(ran_db))
def test_team_user_unicode(self): t0 = Team(name="team2", tag="OPSuperTeam", region=self.bre, manager=self.s) t0.save() tu_in = TeamUser(team=t0, summoner=self.s) tu_in.save() tu_out = TeamUser.objects.get(team=t0, summoner=self.s) tu_out.date_out = timezone.now() tu_out.save() self.assertEqual(str(tu_in), 'amoki is currently playing with [OPSuperTeam] team2') self.assertEqual(str(tu_out), 'amoki played with [OPSuperTeam] team2')
def generate(using, count): for i in range(count): t = Team(name='team{}'.format(count), games=count, admin_id=1) t.save(using=using) for j in range(10): u = User.objects.get(username='******'.format(j + 10 * i)) tu = UserTeam( user=u, team=t, ) tu.save(using=using)
def get_teams(self): teams = self.stats.make_request(host="erikberg.com", sport='nba', method="teams", id=None, format="json", parameters={}) for team in teams: try: team_obj = Team.objects.get(team_id=team['team_id']) except Team.DoesNotExist: team_obj = Team() for attr, value in team.items(): setattr(team_obj, attr, value) team_obj.save()
class ModelTestCase(TestCase): def setUp(self): self.team_id = "1" self.team_name = "India" self.team_image = "India.png" self.team = Team(name=self.team_name, image=self.team_image) def test_model_can_create_a_team(self): """Test the game model can create a game.""" old_count = Team.objects.count() self.team.save() new_count = Team.objects.count() self.assertNotEqual(old_count, new_count)
def test_team_request_unicode(self): tr_team = TeamRequest(team=self.t, summoner=self.s2, origin=TeamRequest.TEAM) tr_team.save() t0 = Team(name="team2", tag="OPSuperTeam", region=self.bre, manager=self.s) t0.save() tr_s = TeamRequest(team=t0, summoner=self.s, origin=TeamRequest.SUMMONER) tr_s.save() self.assertEqual(str(tr_team), '[OPTeam] team1 wants to add Telu to its roster') self.assertEqual(str(tr_s), 'amoki wants to join [OPSuperTeam] team2')
def setUp(self): user = get_user_model()(username='******', email='*****@*****.**') user.save() admin_user = get_user_model()( username='******', email='*****@*****.**') admin_user.is_staff = True admin_user.save() team = Team(name='recalculate-team', owner=user, password='******') team.save() user.team = team user.save() self.user = user self.admin_user = admin_user self.team = team
def populate(): for i in range(15): user = get_user_model()(username=f'scorelist-test{i}', email=f'scorelist-test{i}@example.org') user.save() team = Team(name=f'scorelist-test{i}', password=f'scorelist-test{i}', owner=user) team.points = i * 100 team.leaderboard_points = i * 100 team.save() user.team = team user.points = i * 100 user.leaderboard_points = i * 100 user.save() Score(team=team, user=user, reason='test', points=i * 100).save()
class TeamSetupMixin: def setUp(self): self.user = get_user_model()(username='******', email='*****@*****.**') self.user.save() self.team = Team(name='team-test', password='******', description='', owner=self.user) self.team.save() self.user.team = self.team self.user.save() self.admin_user = get_user_model()(username='******', email='*****@*****.**') self.admin_user.is_staff = True self.admin_user.save()
class TeamSetupMixin: def setUp(self): self.user = get_user_model()( username="******", email="*****@*****.**" ) self.user.save() self.team = Team( name="team-test", password="******", description="", owner=self.user ) self.team.save() self.user.team = self.team self.user.save() self.admin_user = get_user_model()( username="******", email="*****@*****.**" ) self.admin_user.is_staff = True self.admin_user.save()
def setUp(self): user = get_user_model()( username="******", email="*****@*****.**" ) user.save() admin_user = get_user_model()( username="******", email="*****@*****.**", ) admin_user.is_staff = True admin_user.save() team = Team(name="recalculate-team", owner=user, password="******") team.save() user.team = team user.save() self.user = user self.admin_user = admin_user self.team = team
def start(self): c = int(self.count / 10) for i in range(c): t = Team( name='team{}'.format(i), games=self.count, ) t.save(using=self.using) for j in range(10): u = User(username='******'.format(j + 10 * i), email='ivan@ivan{}.ru'.format(j + 10 * i)) u.set_password('ivan123') u.first_name = 'ivan{}'.format(j + 10 * i) u.last_name = 'ivanon{}'.format(j + 10 * i) u.save(using=self.using) tu = UserTeam( user=u, team=t, ) tu.save(using=self.using) cc = int(self.count / 100) for i in range(cc): t = Turn(name='turn{}'.format(i)) t.save(using=self.using) for j in range(10): m = Match(name='match{}'.format(j + 10 * i), turn_id=t.id) m.save(using=self.using) for l in range(10): g = Game(name='game{}'.format(l + 10 * j + 100 * i), match_id=m.id) g.save(using=self.using) tm = Team.objects.using( self.using).get(name='team{}'.format(j + 10 * i)) print(g.name, t.name) gt = GameTeam(game=g, team=tm) gt.save(using=self.using)
def index(request): if request.method == 'POST': if 'delete' in request.POST: team_list = Team.objects.all().order_by('-team_name') delete_team = team_list.get(pk=request.POST['delete-team']) delete_team.delete() team_list = Team.objects.all().order_by('-team_name') new_form = AddTeamForm() dictionary = {'team_list': team_list, 'form': new_form} render(request, 'team/index.html', dictionary) else: form = AddTeamForm(request.POST) if form.is_valid(): new_team = Team() new_team.team_name = form.cleaned_data['team_name'] new_team.save() team_list = Team.objects.all().order_by('-team_name') new_form = AddTeamForm() dictionary = {'team_list': team_list, 'form': new_form} render(request, 'team/index.html', dictionary) form = AddTeamForm() team_list = Team.objects.all().order_by('-team_name') context = {'team_list': team_list, 'form': form} return render(request, 'team/index.html', context)
def setUp(self): category = Category(name='test', display_order=0, contained_type='test', description='') category.save() challenge1 = Challenge(name='test1', category=category, description='a', challenge_type='basic', challenge_metadata={}, flag_type='plaintext', flag_metadata={'flag': 'ractf{a}'}, author='dave', score=1000) challenge2 = Challenge(name='test2', category=category, description='a', challenge_type='basic', challenge_metadata={}, flag_type='plaintext', flag_metadata={'flag': 'ractf{a}'}, author='dave', score=1000, auto_unlock=True) challenge3 = Challenge(name='test3', category=category, description='a', challenge_type='basic', challenge_metadata={}, flag_type='plaintext', flag_metadata={'flag': 'ractf{a}'}, author='dave', score=1000, auto_unlock=False) challenge1.save() challenge2.save() challenge3.save() challenge2.unlocks.add(challenge1) challenge2.save() hint1 = Hint(name='hint1', challenge=challenge1, text='a', penalty=100) hint2 = Hint(name='hint2', challenge=challenge1, text='a', penalty=100) hint3 = Hint(name='hint3', challenge=challenge2, text='a', penalty=100) hint1.save() hint2.save() hint3.save() user = get_user_model()(username='******', email='*****@*****.**') user.save() team = Team(name='team', password='******', owner=user) team.save() user.team = team user.save() user2 = get_user_model()(username='******', email='*****@*****.**') user2.team = team user2.save() user3 = get_user_model()(username='******', email='*****@*****.**') user3.save() team2 = Team(name='team2', password='******', owner=user3) team2.save() user3.team = team2 user3.save() self.user = user self.user2 = user2 self.user3 = user3 self.team = team self.team2 = team2 self.category = category self.challenge1 = challenge1 self.challenge2 = challenge2 self.challenge3 = challenge3 self.hint1 = hint1 self.hint2 = hint2 self.hint3 = hint3
def create_team(self, name, tag): new_team = Team(name=name, tag=tag, region=self.region, manager=self) new_team.save() TeamUser(team=new_team, summoner=self).save() return new_team
def insert(request): if request.method == 'POST': # If the form has been submitted... t = Team(team_name=request.POST["teamName"]) t.save() return HttpResponseRedirect('/Team/')
def create(self, name: str, description: str) -> Team: team = Team(name=name, description=description) team.save() return team
def test_leave_team_manager_no_last(self): t = Team(name="haha", tag="ha", region=self.bre, manager=self.s) t.save() TeamUser(team=t, summoner=self.s).save() TeamUser(team=t, summoner=self.s2).save() self.assertRaises(IntegrityError, lambda: self.s.leave_team(t))
def handle(self, *args, **options): print('Creating 10 categories...') for i in range(10): category = Category(name='category-' + str(i), display_order=i, contained_type='test', description='Category ' + str(i)) category.save() print('Creating 100 challenges for each category...') for i in range(10): category = Category.objects.get(name='category-' + str(i)) for j in range(50): challenge = Challenge(name='cat-' + str(i) + '-chal-' + str(j), category=category, description='An example challenge ' + str(j), flag_metadata={'flag': f'ractf{{{j}}}'}, author='dave', auto_unlock=True, score=j, challenge_metadata={}) challenge.save() for j in range(50, 100, 2): challenge = Challenge(name='cat-' + str(i) + '-chal-' + str(j), category=category, description='An example challenge ' + str(j), flag_metadata={'flag': f'ractf{{{j}}}'}, author='dave', auto_unlock=True, score=j, challenge_metadata={}) challenge2 = Challenge(name='cat-' + str(i) + '-chal-' + str(j + 1), category=category, description='An example challenge ' + str(j + 1), flag_metadata={'flag': f'ractf{{{j + 1}}}'}, author='dave', auto_unlock=False, score=j, challenge_metadata={}) challenge2.save() challenge.save() challenge.unlocks.add(challenge2) print('Creating 20000 users with 10000 teams with 100 solves per team...') for i in range(10000): user = get_user_model()(username='******' + str(i), email='user-' + str(i) + '@example.org') user.save() team = Team(name='team-' + str(i), password='******', owner=user) team.save() user2 = get_user_model()(username='******' + str(i) + '-second', email='user-' + str(i) + '*****@*****.**', team=team) user2.save() for j in range(50): challenge = Category.objects.get(name='category-' + str(j % 5))\ .category_challenges.get(name='cat-' + str(j % 5) + '-chal-' + str(j)) points = random.randint(0, 1000) score = Score(team=team, reason='challenge', points=points, penalty=0, leaderboard=True) score.save() solve = Solve(team=team, solved_by=user, challenge=challenge, first_blood=challenge.first_blood is None, flag='ractf{}', score=score, correct=True) solve.save() user.points += points team.points += points user.leaderboard_points += points team.leaderboard_points += points for j in range(50): challenge = Category.objects.get(name='category-' + str(j % 5 + 5))\ .category_challenges.get(name='cat-' + str(j % 5 + 5) + '-chal-' + str(j)) points = random.randint(0, 1000) score = Score(team=team, reason='challenge', points=points, penalty=0, leaderboard=True) score.save() solve = Solve(team=team, solved_by=user2, challenge=challenge, first_blood=challenge.first_blood is None, flag='ractf{}', score=score, correct=True) solve.save() user2.points += points team.points += points user.leaderboard_points += points team.leaderboard_points += points