refactoring of match creation
This commit is contained in:
parent
3829147bfb
commit
bc4bb63e3b
@ -96,10 +96,16 @@ class Event(models.Model):
|
|||||||
|
|
||||||
match = Match.objects.create(event=self, title_at_stake=title_at_stake)
|
match = Match.objects.create(event=self, title_at_stake=title_at_stake)
|
||||||
for team in teams:
|
for team in teams:
|
||||||
if isinstance(team, (list, tuple)):
|
mt = MatchTeam.objects.create(match=match)
|
||||||
match.add_team(*team)
|
if not isinstance(team, (list, tuple)):
|
||||||
else:
|
team = [team]
|
||||||
match.add_team(team)
|
for member in team:
|
||||||
|
member = Star.objects.get(pk=member)
|
||||||
|
if not mt.title and member.title:
|
||||||
|
# multiple titles?
|
||||||
|
mt.title = member.title
|
||||||
|
mt.save()
|
||||||
|
mt.members.add(member)
|
||||||
if winner:
|
if winner:
|
||||||
match.record_win(winner, win_type)
|
match.record_win(winner, win_type)
|
||||||
return match
|
return match
|
||||||
@ -115,16 +121,6 @@ class Match(models.Model):
|
|||||||
win_type = models.CharField(max_length=10, choices=WIN_TYPES)
|
win_type = models.CharField(max_length=10, choices=WIN_TYPES)
|
||||||
title_at_stake = models.BooleanField(default=False)
|
title_at_stake = models.BooleanField(default=False)
|
||||||
|
|
||||||
def add_team(self, *members, **kwargs):
|
|
||||||
title = kwargs.get('title', None)
|
|
||||||
mt = MatchTeam.objects.create(match=self, title=title)
|
|
||||||
for member in members:
|
|
||||||
member = Star.objects.get(pk=member)
|
|
||||||
if not mt.title and member.title:
|
|
||||||
mt.title = member.title
|
|
||||||
mt.save()
|
|
||||||
mt.members.add(member)
|
|
||||||
|
|
||||||
def record_win(self, star, win_type):
|
def record_win(self, star, win_type):
|
||||||
self.teams.filter(members__pk=star).update(victorious=True)
|
self.teams.filter(members__pk=star).update(victorious=True)
|
||||||
self.winner_id = star
|
self.winner_id = star
|
||||||
|
@ -3,23 +3,23 @@ from django.core.management import call_command
|
|||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from .models import Match, Event, League, Team, TeamPoints, Star
|
from .models import Match, Event, League, Team, TeamPoints, Star
|
||||||
|
|
||||||
|
def _give_belt(star, belt):
|
||||||
|
Star.objects.filter(pk=star).update(title=belt)
|
||||||
|
|
||||||
class MatchTest(TestCase):
|
class MatchTest(TestCase):
|
||||||
fixtures = ['testdata']
|
fixtures = ['testdata']
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.wm29 = Event.objects.create(name='Wrestlemania 29', date='2012-04-01')
|
self.event = Event.objects.create(name='Wrestlemania 29', date='2012-04-01')
|
||||||
|
|
||||||
def test_display(self):
|
def test_basics(self):
|
||||||
match = Match.objects.create(event=self.wm29)
|
match = self.event.add_match('tripleh', 'undertaker')
|
||||||
match.add_team('tripleh')
|
|
||||||
match.add_team('undertaker')
|
|
||||||
self.assertEqual(unicode(match), 'Triple H vs. Undertaker')
|
self.assertEqual(unicode(match), 'Triple H vs. Undertaker')
|
||||||
match.record_win('undertaker', 'pin')
|
match.record_win('undertaker', 'pin')
|
||||||
self.assertEqual(unicode(match), 'Triple H vs. Undertaker (v)')
|
self.assertEqual(unicode(match), 'Triple H vs. Undertaker (v)')
|
||||||
|
|
||||||
match = Match.objects.create(event=self.wm29)
|
_give_belt('cmpunk', 'wwe')
|
||||||
match.add_team('cmpunk', title='wwe')
|
match = self.event.add_match('cmpunk', 'reymysterio')
|
||||||
match.add_team('reymysterio')
|
|
||||||
self.assertEqual(unicode(match), 'CM Punk (c) vs. Rey Mysterio')
|
self.assertEqual(unicode(match), 'CM Punk (c) vs. Rey Mysterio')
|
||||||
match.record_win('cmpunk', 'pin')
|
match.record_win('cmpunk', 'pin')
|
||||||
self.assertEqual(unicode(match), 'CM Punk (c) (v) vs. Rey Mysterio')
|
self.assertEqual(unicode(match), 'CM Punk (c) (v) vs. Rey Mysterio')
|
||||||
@ -27,96 +27,76 @@ class MatchTest(TestCase):
|
|||||||
|
|
||||||
def test_scoring(self):
|
def test_scoring(self):
|
||||||
# one on one : 2 points
|
# one on one : 2 points
|
||||||
match = Match.objects.create(event=self.wm29)
|
match = self.event.add_match('tripleh', 'undertaker',
|
||||||
match.add_team('tripleh')
|
winner='undertaker', win_type='pin')
|
||||||
match.add_team('undertaker')
|
|
||||||
match.record_win('undertaker', 'pin')
|
|
||||||
self.assertEqual(match.points(), {'undertaker': 2, 'tripleh': 0})
|
self.assertEqual(match.points(), {'undertaker': 2, 'tripleh': 0})
|
||||||
|
|
||||||
# fatal 4 way: 6 points
|
# fatal 4 way: 6 points
|
||||||
match = Match.objects.create(event=self.wm29)
|
match = self.event.add_match('randyorton', 'sheamus', 'albertodelrio',
|
||||||
match.add_team('randyorton')
|
'chrisjericho', winner='sheamus',
|
||||||
match.add_team('albertodelrio')
|
win_type='pin')
|
||||||
match.add_team('sheamus')
|
|
||||||
match.add_team('chrisjericho')
|
|
||||||
match.record_win('sheamus', 'pin')
|
|
||||||
self.assertEqual(match.points(), {'sheamus': 6, 'randyorton': 0,
|
self.assertEqual(match.points(), {'sheamus': 6, 'randyorton': 0,
|
||||||
'albertodelrio': 0, 'chrisjericho': 0}
|
'albertodelrio': 0, 'chrisjericho': 0}
|
||||||
)
|
)
|
||||||
|
|
||||||
# win stacked match: 1 point for team (bonuses can apply)
|
# win stacked match: 1 point for team (bonuses can apply)
|
||||||
match = Match.objects.create(event=self.wm29)
|
match = self.event.add_match('santinomarella', ['markhenry', 'kane'],
|
||||||
match.add_team('santinomarella')
|
winner='markhenry', win_type='pin')
|
||||||
match.add_team('markhenry', 'kane')
|
|
||||||
match.record_win('markhenry', 'pin')
|
|
||||||
self.assertEqual(match.points(), {'markhenry': 2, 'kane': 1,
|
self.assertEqual(match.points(), {'markhenry': 2, 'kane': 1,
|
||||||
'santinomarella': 0})
|
'santinomarella': 0})
|
||||||
|
|
||||||
# DQ : 1 point
|
# DQ : 1 point
|
||||||
match = Match.objects.create(event=self.wm29)
|
match = self.event.add_match('kane', 'undertaker', winner='undertaker',
|
||||||
match.add_team('kane')
|
win_type='DQ')
|
||||||
match.add_team('undertaker')
|
|
||||||
match.record_win('undertaker', 'DQ')
|
|
||||||
self.assertEqual(match.points(), {'undertaker': 1, 'kane': 0})
|
self.assertEqual(match.points(), {'undertaker': 1, 'kane': 0})
|
||||||
|
|
||||||
# submission: +1
|
# submission: +1
|
||||||
match = Match.objects.create(event=self.wm29)
|
match = self.event.add_match('danielbryan', 'cmpunk',
|
||||||
match.add_team('danielbryan')
|
winner='danielbryan',
|
||||||
match.add_team('cmpunk')
|
win_type='submission')
|
||||||
match.record_win('danielbryan', 'submission')
|
|
||||||
self.assertEqual(match.points(), {'danielbryan': 3, 'cmpunk': 0})
|
self.assertEqual(match.points(), {'danielbryan': 3, 'cmpunk': 0})
|
||||||
|
|
||||||
# complicated one, outnumbered + submission
|
# complicated one, outnumbered + submission
|
||||||
match = Match.objects.create(event=self.wm29)
|
match = self.event.add_match('cmpunk', ['danielbryan', 'chrisjericho'],
|
||||||
match.add_team('danielbryan', 'chrisjericho')
|
winner='cmpunk', win_type='submission')
|
||||||
match.add_team('cmpunk')
|
|
||||||
match.record_win('cmpunk', 'submission')
|
|
||||||
self.assertEqual(match.points(), {'cmpunk': 5, 'chrisjericho': 0,
|
self.assertEqual(match.points(), {'cmpunk': 5, 'chrisjericho': 0,
|
||||||
'danielbryan': 0})
|
'danielbryan': 0})
|
||||||
|
|
||||||
# tag team: 2 points, +1 for the person who made pin
|
# tag team: 2 points, +1 for the person who made pin
|
||||||
match = Match.objects.create(event=self.wm29)
|
match = self.event.add_match(['kofikingston', 'rtruth'],
|
||||||
match.add_team('kofikingston', 'rtruth')
|
['jackswagger', 'dolphziggler'],
|
||||||
match.add_team('jackswagger', 'dolphziggler')
|
winner='dolphziggler', win_type='pin')
|
||||||
match.record_win('dolphziggler', 'pin')
|
|
||||||
self.assertEqual(match.points(), {'jackswagger': 2,
|
self.assertEqual(match.points(), {'jackswagger': 2,
|
||||||
'dolphziggler': 3,
|
'dolphziggler': 3,
|
||||||
'kofikingston': 0,
|
'kofikingston': 0,
|
||||||
'rtruth': 0})
|
'rtruth': 0})
|
||||||
|
|
||||||
# tag team submission: stacks on ziggler
|
# tag team submission: stacks on ziggler
|
||||||
match = Match.objects.create(event=self.wm29)
|
match = self.event.add_match(['kofikingston', 'rtruth'],
|
||||||
match.add_team('kofikingston', 'rtruth')
|
['jackswagger', 'dolphziggler'],
|
||||||
match.add_team('jackswagger', 'dolphziggler')
|
winner='dolphziggler',
|
||||||
match.record_win('dolphziggler', 'submission')
|
win_type='submission')
|
||||||
self.assertEqual(match.points(), {'jackswagger': 2,
|
self.assertEqual(match.points(), {'jackswagger': 2,
|
||||||
'dolphziggler': 4,
|
'dolphziggler': 4,
|
||||||
'kofikingston': 0,
|
'kofikingston': 0,
|
||||||
'rtruth': 0})
|
'rtruth': 0})
|
||||||
|
|
||||||
# tag team DQ: 1 point each member
|
# tag team DQ: 1 point each member
|
||||||
match = Match.objects.create(event=self.wm29)
|
match = self.event.add_match(['kofikingston', 'rtruth'],
|
||||||
match.add_team('kofikingston', 'rtruth')
|
['jackswagger', 'dolphziggler'],
|
||||||
match.add_team('jackswagger', 'dolphziggler')
|
winner='dolphziggler',
|
||||||
match.record_win('dolphziggler', 'DQ')
|
win_type='DQ')
|
||||||
self.assertEqual(match.points(), {'jackswagger': 1,
|
self.assertEqual(match.points(), {'jackswagger': 1,
|
||||||
'dolphziggler': 1,
|
'dolphziggler': 1,
|
||||||
'kofikingston': 0,
|
'kofikingston': 0,
|
||||||
'rtruth': 0})
|
'rtruth': 0})
|
||||||
|
|
||||||
# rumble: participants / 2
|
# rumble: participants / 2
|
||||||
match = Match.objects.create(event=self.wm29)
|
match = self.event.add_match('kofikingston', 'rtruth', 'themiz',
|
||||||
match.add_team('kofikingston')
|
'dolphziggler', 'johncena', 'jackswagger',
|
||||||
match.add_team('rtruth')
|
'kharma', 'kane', 'albertodelrio',
|
||||||
match.add_team('themiz')
|
'christian', winner='christian',
|
||||||
match.add_team('dolphziggler')
|
win_type='pin')
|
||||||
match.add_team('johncena')
|
|
||||||
match.add_team('jackswagger')
|
|
||||||
match.add_team('kharma')
|
|
||||||
match.add_team('kane')
|
|
||||||
match.add_team('albertodelrio')
|
|
||||||
match.add_team('christian')
|
|
||||||
match.record_win('christian', 'pin')
|
|
||||||
self.assertEqual(match.points(), {'christian': 5,
|
self.assertEqual(match.points(), {'christian': 5,
|
||||||
'kofikingston': 0,
|
'kofikingston': 0,
|
||||||
'rtruth': 0,
|
'rtruth': 0,
|
||||||
@ -130,71 +110,71 @@ class MatchTest(TestCase):
|
|||||||
})
|
})
|
||||||
|
|
||||||
def test_champ_scoring(self):
|
def test_champ_scoring(self):
|
||||||
|
_give_belt('cmpunk', 'wwe')
|
||||||
|
_give_belt('christian', 'ic')
|
||||||
|
_give_belt('kofikingston', 'tag')
|
||||||
|
_give_belt('rtruth', 'tag')
|
||||||
|
|
||||||
# champ doesn't get a bonus just for winning
|
# champ doesn't get a bonus just for winning
|
||||||
match = Match.objects.create(event=self.wm29)
|
match = self.event.add_match('cmpunk', 'reymysterio', winner='cmpunk',
|
||||||
match.add_team('cmpunk', title='wwe')
|
win_type='pin')
|
||||||
match.add_team('reymysterio')
|
|
||||||
match.record_win('cmpunk', 'pin')
|
|
||||||
self.assertEqual(match.points(), {'cmpunk': 2, 'reymysterio': 0})
|
self.assertEqual(match.points(), {'cmpunk': 2, 'reymysterio': 0})
|
||||||
|
|
||||||
|
# +2 bonus for beating a champ in a non-title match
|
||||||
|
match = self.event.add_match('cmpunk', 'reymysterio',
|
||||||
|
winner='reymysterio', win_type='pin')
|
||||||
|
self.assertEqual(match.points(), {'cmpunk': 0, 'reymysterio': 4})
|
||||||
|
|
||||||
# defending wwe belt is worth +5
|
# defending wwe belt is worth +5
|
||||||
match = Match.objects.create(event=self.wm29, title_at_stake=True)
|
match = self.event.add_match('cmpunk', 'reymysterio', winner='cmpunk',
|
||||||
match.add_team('cmpunk', title='wwe')
|
win_type='pin', title_at_stake=True)
|
||||||
match.add_team('reymysterio')
|
|
||||||
match.record_win('cmpunk', 'pin')
|
|
||||||
self.assertEqual(match.points(), {'cmpunk': 7, 'reymysterio': 0})
|
self.assertEqual(match.points(), {'cmpunk': 7, 'reymysterio': 0})
|
||||||
|
|
||||||
# winning wwe belt
|
# winning wwe belt
|
||||||
match = Match.objects.create(event=self.wm29, title_at_stake=True)
|
match = self.event.add_match('cmpunk', 'reymysterio',
|
||||||
match.add_team('cmpunk', title='wwe')
|
winner='reymysterio', win_type='pin',
|
||||||
match.add_team('reymysterio')
|
title_at_stake=True)
|
||||||
match.record_win('reymysterio', 'pin')
|
|
||||||
self.assertEqual(match.points(), {'reymysterio': 22, 'cmpunk': 0})
|
self.assertEqual(match.points(), {'reymysterio': 22, 'cmpunk': 0})
|
||||||
|
|
||||||
# defending other belt is worth +3
|
# defending other belt is worth +3
|
||||||
match = Match.objects.create(event=self.wm29, title_at_stake=True)
|
match = self.event.add_match('christian', 'codyrhodes',
|
||||||
match.add_team('christian', title='ic')
|
winner='christian', win_type='pin',
|
||||||
match.add_team('codyrhodes')
|
title_at_stake=True)
|
||||||
match.record_win('christian', 'pin')
|
|
||||||
self.assertEqual(match.points(), {'christian': 5, 'codyrhodes': 0})
|
self.assertEqual(match.points(), {'christian': 5, 'codyrhodes': 0})
|
||||||
|
|
||||||
# winning other belt is worth +3
|
# winning other belt is worth +10
|
||||||
match = Match.objects.create(event=self.wm29, title_at_stake=True)
|
match = self.event.add_match('christian', 'codyrhodes',
|
||||||
match.add_team('christian', title='ic')
|
winner='codyrhodes', win_type='pin',
|
||||||
match.add_team('codyrhodes')
|
title_at_stake=True)
|
||||||
match.record_win('codyrhodes', 'pin')
|
|
||||||
self.assertEqual(match.points(), {'codyrhodes': 12, 'christian': 0})
|
self.assertEqual(match.points(), {'codyrhodes': 12, 'christian': 0})
|
||||||
|
|
||||||
# title non-defense (DQ/countout)
|
# title non-defense (DQ/countout)
|
||||||
match = Match.objects.create(event=self.wm29, title_at_stake=True)
|
match = self.event.add_match('christian', 'codyrhodes',
|
||||||
match.add_team('christian', title='ic')
|
winner='codyrhodes', win_type='DQ',
|
||||||
match.add_team('codyrhodes')
|
title_at_stake=True)
|
||||||
match.record_win('codyrhodes', 'DQ')
|
|
||||||
self.assertEqual(match.points(), {'codyrhodes': 1, 'christian': 1})
|
self.assertEqual(match.points(), {'codyrhodes': 1, 'christian': 1})
|
||||||
|
|
||||||
# +2 bonus for beating a champ in a non-title match
|
|
||||||
match = Match.objects.create(event=self.wm29)
|
|
||||||
match.add_team('cmpunk', title='wwe')
|
|
||||||
match.add_team('reymysterio')
|
|
||||||
match.record_win('reymysterio', 'pin')
|
|
||||||
self.assertEqual(match.points(), {'reymysterio': 4, 'cmpunk': 0})
|
|
||||||
|
|
||||||
# no bonus in a tag match
|
# no bonus in a tag match
|
||||||
match = Match.objects.create(event=self.wm29)
|
match = self.event.add_match(['cmpunk', 'christian'],
|
||||||
match.add_team('cmpunk', 'christian', title='wwe')
|
['reymysterio', 'codyrhodes'],
|
||||||
match.add_team('reymysterio', 'codyrhodes')
|
winner='reymysterio', win_type='pin')
|
||||||
match.record_win('reymysterio', 'pin')
|
|
||||||
self.assertEqual(match.points(), {'codyrhodes': 2, 'reymysterio': 3,
|
self.assertEqual(match.points(), {'codyrhodes': 2, 'reymysterio': 3,
|
||||||
'cmpunk': 0, 'christian': 0})
|
'cmpunk': 0, 'christian': 0})
|
||||||
|
|
||||||
# ...unless it is the tag title
|
# ...unless it is the tag title
|
||||||
match = Match.objects.create(event=self.wm29)
|
match = self.event.add_match(['kofikingston', 'rtruth'],
|
||||||
match.add_team('cmpunk', 'christian', title='tag')
|
['reymysterio', 'sin-cara'],
|
||||||
match.add_team('reymysterio', 'codyrhodes')
|
winner='reymysterio', win_type='pin')
|
||||||
match.record_win('reymysterio', 'pin')
|
self.assertEqual(match.points(), {'sin-cara': 4, 'reymysterio': 5,
|
||||||
self.assertEqual(match.points(), {'codyrhodes': 4, 'reymysterio': 5,
|
'kofikingston': 0, 'rtruth': 0})
|
||||||
'cmpunk': 0, 'christian': 0})
|
|
||||||
|
|
||||||
|
# test tag title changing hands
|
||||||
|
match = self.event.add_match(['kofikingston', 'rtruth'],
|
||||||
|
['reymysterio', 'sin-cara'],
|
||||||
|
winner='reymysterio', win_type='pin',
|
||||||
|
title_at_stake=True)
|
||||||
|
self.assertEqual(match.points(), {'sin-cara': 12, 'reymysterio': 13,
|
||||||
|
'kofikingston': 0, 'rtruth': 0})
|
||||||
|
|
||||||
|
|
||||||
class LeagueTest(TestCase):
|
class LeagueTest(TestCase):
|
||||||
@ -229,7 +209,7 @@ class LeagueTest(TestCase):
|
|||||||
win_type='pin')
|
win_type='pin')
|
||||||
match2 = event.add_match('markhenry', ['santinomarella', 'mickfoley'],
|
match2 = event.add_match('markhenry', ['santinomarella', 'mickfoley'],
|
||||||
winner='mickfoley', win_type='pin')
|
winner='mickfoley', win_type='pin')
|
||||||
Star.objects.filter(pk='codyrhodes').update(title='ic')
|
_give_belt('codyrhodes', 'ic')
|
||||||
match3 = event.add_match('sin-cara', 'codyrhodes', title_at_stake=True,
|
match3 = event.add_match('sin-cara', 'codyrhodes', title_at_stake=True,
|
||||||
winner='sin-cara', win_type='pin')
|
winner='sin-cara', win_type='pin')
|
||||||
self.league.score_event(event)
|
self.league.score_event(event)
|
||||||
|
Loading…
Reference in New Issue
Block a user