Skip to content

Commit

Permalink
Pre-hunt teams are deleted when empty, fixes #65
Browse files Browse the repository at this point in the history
  • Loading branch information
dlareau committed Oct 5, 2018
1 parent 046e637 commit 8a79f11
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 20 deletions.
37 changes: 37 additions & 0 deletions huntserver/fixtures/basic_hunt.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,34 @@
"model": "huntserver.hunt",
"pk": 3
},
{
"fields": {
"team_size": 3,
"end_date": "1000-07-03T05:00:00Z",
"hunt_name": "Example Hunt 4",
"is_current_hunt": false,
"location": "Location 4",
"template": "{% extends \"hunt_base.html\" %}\r\n{% block title %}Puzzles 4{% endblock title %}\r\n\r\n{% block content %}\r\nExample Template 3\r\n{% endblock content %}",
"hunt_number": 4,
"start_date": "1000-07-02T05:00:00Z"
},
"model": "huntserver.hunt",
"pk": 4
},
{
"fields": {
"team_size": 3,
"end_date": "1000-12-03T05:00:00Z",
"hunt_name": "Example Hunt 5",
"is_current_hunt": false,
"location": "Location 5",
"template": "{% extends \"hunt_base.html\" %}\r\n{% block title %}Puzzles 5{% endblock title %}\r\n\r\n{% block content %}\r\nExample Template 3\r\n{% endblock content %}",
"hunt_number": 5,
"start_date": "1000-12-02T05:00:00Z"
},
"model": "huntserver.hunt",
"pk": 5
},


{
Expand Down Expand Up @@ -530,6 +558,15 @@
},


{
"fields": {
"file": "foo"
},
"model": "huntserver.huntassetfile",
"pk": 1
},


{
"fields": {
"puzzle": 5,
Expand Down
4 changes: 3 additions & 1 deletion huntserver/info_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ def registration(request):
request.user.person.teams.add(team)
elif(request.POST["form_type"] == "leave_team"):
request.user.person.teams.remove(team)
if(team.person_set.count() == 0 and team.hunt.is_locked):
team.delete()
team = None
elif(request.POST["form_type"] == "new_location" and team is not None):
# TODO: add success message
team.location = request.POST.get("team_location")
team.save()
elif(request.POST["form_type"] == "new_name" and team is not None):
elif(request.POST["form_type"] == "new_name" and team is not None and team.hunt.is_locked):
# TODO: add success message
team.team_name = request.POST.get("team_name")
team.save()
Expand Down
30 changes: 14 additions & 16 deletions huntserver/templates/previous_hunts.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@

</p>
{% for hunt in hunts reversed %}
<p>
<h4>
<a href="{% url 'huntserver:hunt' hunt.hunt_number %}">
{{hunt.hunt_name}} ({{hunt.season}} '{{ hunt.start_date|date:"y" }})
</a>
</h4>
<ul>
<li>
{{ hunt.start_date|date:" m/d/y " }}
{{ hunt.start_date|time:"P" }} -
{{ hunt.end_date|time:"P" }}
</li>
<li>{{hunt.puzzle_set.all|length}} Puzzles</li>
<li>{{hunt.real_teams|length}} Teams</li>
</ul>
</p>
<h4>
<a href="{% url 'huntserver:hunt' hunt.hunt_number %}">
{{hunt.hunt_name}} ({{hunt.season}} '{{ hunt.start_date|date:"y" }})
</a>
</h4>
<ul>
<li>
{{ hunt.start_date|date:" m/d/y " }}
{{ hunt.start_date|time:"P" }} -
{{ hunt.end_date|time:"P" }}
</li>
<li>{{hunt.puzzle_set.all|length}} Puzzles</li>
<li>{{hunt.real_teams|length}} Teams</li>
</ul>
{% endfor %}
<h4> Ornithology Hunt (Fall '14) </h4>
<ul>
Expand Down
32 changes: 29 additions & 3 deletions huntserver/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.contrib.auth.models import User, AnonymousUser
from django.utils import timezone
from django.core.exceptions import ValidationError
from datetime import datetime, timedelta

#python manage.py dumpdata --indent=4 --exclude=contenttypes --exclude=sessions --exclude=admin --exclude=auth.permission

Expand Down Expand Up @@ -174,17 +175,26 @@ def test_registration_post_join(self):

def test_registration_post_leave(self):
"Test the registration page's leave team functionality"
login(self, 'user4')
login(self, 'user5')
post_context = {"form_type":"leave_team"}
response = self.client.post(reverse('huntserver:registration'), post_context)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['error'], "")
hunt = models.Hunt.objects.get(is_current_hunt=True)
self.assertEqual(len(response.context['user'].person.teams.filter(hunt=hunt)), 0)
self.assertEqual(len(models.Team.objects.get(team_name="Team2-2").person_set.all()), 1)
self.assertEqual(len(models.Team.objects.get(team_name="Team2-3").person_set.all()), 2)
login(self, 'user4')
hunt.start_date = hunt.start_date + timedelta(days=10000)
hunt.end_date = hunt.end_date + timedelta(days=10000)
hunt.save()
post_context = {"form_type":"leave_team"}
response = self.client.post(reverse('huntserver:registration'), post_context)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['error'], "")
self.assertEqual(len(response.context['user'].person.teams.filter(hunt=hunt)), 0)

def test_registration_post_change_location(self):
"Test the registration page's leave team functionality"
"Test the registration page's new location functionality"
login(self, 'user4')
post_context = {"form_type":"new_location", "team_location": "location2.0"}
response = self.client.post(reverse('huntserver:registration'), post_context)
Expand All @@ -194,6 +204,20 @@ def test_registration_post_change_location(self):
self.assertEqual(response.context['registered_team'], team)
self.assertEqual(team.location, post_context['team_location'])

def test_registration_post_change_name(self):
"Test the registration page's new team name functionality"
login(self, 'user4')
post_context = {"form_type":"new_name", "team_name": "name 2.0"}
hunt = models.Hunt.objects.get(is_current_hunt=True)
hunt.start_date = hunt.start_date + timedelta(days=10000)
hunt.end_date = hunt.end_date + timedelta(days=10000)
hunt.save()
response = self.client.post(reverse('huntserver:registration'), post_context)
self.assertEqual(response.status_code, 200)
team = response.context['user'].person.teams.filter(hunt=hunt)[0]
self.assertEqual(response.context['registered_team'], team)
self.assertEqual(team.team_name, post_context['team_name'])

def test_registration_post_invalid_data(self):
"Test the registration page with invalid post data"
login(self, 'user6')
Expand Down Expand Up @@ -627,6 +651,8 @@ def test_admin_pages(self):
self.assertEqual(response.status_code, 200)
response = self.client.get(reverse('admin:huntserver_hunt_change', args=(1,)))
self.assertEqual(response.status_code, 200)
response = self.client.get(reverse('admin:huntserver_huntassetfile_change', args=(1,)))
self.assertEqual(response.status_code, 200)

"""
admin.py
Expand Down

0 comments on commit 8a79f11

Please sign in to comment.