Skip to content

Commit

Permalink
Modify game event template
Browse files Browse the repository at this point in the history
Implement logic in join event
  • Loading branch information
amitkaplansky committed Jun 2, 2023
1 parent 56a4b60 commit 818cffc
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 168 deletions.
22 changes: 21 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,29 @@ def game_event(court, court_ball_game):
level_of_game=5,
min_number_of_players=3,
max_number_of_players=5,
court=court, ball_game="Basketball")
court=court, ball_game=BallGame.Basketball)


@pytest.fixture
def game_event_player(game_event, player):
return GameEventPlayer.objects.create(game_event=game_event, player=player, ball_responsible=False)


@pytest.fixture
def five_players():
players = []
for i in range(1,6):
players.append(Player.create(
username=f'Player{i}',
password='password',
birth_date='1990-01-01',
favorite_ball_game=BallGame.Basketball))
return players

@pytest.fixture
def five_game_event_players(game_event, five_players):
players = []
for i in range(5):
players.append(GameEventPlayer.objects.create(game_event=game_event,
player=five_players[i], ball_responsible=False))
return players
133 changes: 75 additions & 58 deletions game_event/templates/game_event/game-event.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,89 @@
{% block content %}
{% load static %}
<!DOCTYPE html>

<html>
<head>

<head>
<title>Game Event</title>
<link rel="stylesheet" type="text/css" href="{% static 'css/game-event.css' %}">
<script>
setTimeout(function() {
location.reload();
}, 5000);
window.addEventListener('DOMContentLoaded', (event) => {
setTimeout(() => {
var messageElements = document.getElementsByClassName('message-container');
while (messageElements.length > 0) {
var messageElement = messageElements[0];
messageElement.remove();
}
}, 4000);
});
</script>
</head>
<body>

</head>

<body>
{% if time %}
<h1>Event Details</h1>
<p>Time: {{ time }}</p>
<p>Level: {{ level_of_game }}</p>
<p>Min Players: {{ min_number_of_players }}</p>
<p>Max Players: {{ max_number_of_players }}</p>
<p>Court: {{ court }} {{ neighborhood }}</p>
<p>Game: {{ ball_game }}</p>
<h2>Players:</h2>
<h1>Event Details</h1>
<p>Time: {{ time }}</p>
<p>Level: {{ level_of_game }}</p>
<p>Min Players: {{ min_number_of_players }}</p>
<p>Max Players: {{ max_number_of_players }}</p>
<p>Court: {{ court }} {{ neighborhood }}</p>
<p>Game: {{ ball_game }}</p>
<h2>Players:</h2>
<div class="table-container">
<table class="nice-table">
<thead>
<tr>
<th> </th>
<th>Name</th>
<th>Brings Ball</th>
</tr>
<th> </th>
<th>Name</th>
<th>Brings Ball</th>
</tr>
</thead>
<tbody>
{% for player in event_players %}
<tr>
<td>
<img src="{% static 'images/favicon.ico' %}" alt="Ball Image" class="ball-image">
</td>
<td>{{ player.first_name }} {{ player.last_name }}</td>
<td>
{% if player.brings_ball == True %}
Yes
{% else %}
No
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div>
{% if in_event %}
<a href="/game-events/remove-from-event/{{ id }}/"
class="round-button"
onclick="window.open(this.href, 'Remove Event', 'width=400,height=250,left='+((screen.width-400)/2)+',top='+((screen.height-515)/2)); return false;">
Remove Event
</a>
{% else %}
<a href="/game-events/join-event/{{ id }}/"
class="round-button"
onclick="window.open(this.href, 'Join Event', 'width=400,height=250,left='+((screen.width-400)/2)+',top='+((screen.height-515)/2)); return false;">
Join Event
</a>
{% endif %}
</div>
{% else %}
<div>
<h1> Event Does not exist. </h1>
</div>
{% endif %}
</body>
<tbody>
{% for player in event_players %}
<tr>
<td>
<img src="{% static 'images/favicon.ico' %}" alt="Ball Image" class="ball-image">
</td>
<td>{{ player.first_name }} {{ player.last_name }}</td>
<td>
{% if player.brings_ball == True %}
Yes
{% else %}
No
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="button-container">
{% if in_event %}
<a href="/game-events/remove-from-event/{{ id }}" class="round-button remove-event-button">
Remove Event
</a>
{% else %}
<a href="/game-events/join-event/{{ id }}/" class="round-button join-event-button">
Join Event
</a>
{% endif %}
</div>

{% for message in messages %}
<div class="message-container {% if message.tags %}{{ message.tags }}{% endif %}">
{{ message }}
</div>
{% endfor %}
</div>
{% else %}
<div>
<h1> Event Does not exist. </h1>
</div>
{% endif %}

</body>

</html>
{%endblock%}
{%endblock%}
1 change: 1 addition & 0 deletions game_event/templates/game_event/join-event.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<html>
<head>
<link rel="stylesheet" type="text/css" href="{% static 'css/game-event.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'css/game-events.css' %}">
</head>
<body>
{% if event_exists %}
Expand Down
64 changes: 0 additions & 64 deletions game_event/templates/game_event/result.html

This file was deleted.

42 changes: 30 additions & 12 deletions game_event/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from datetime import timedelta
import pytest
from django.db import IntegrityError
from django.http import HttpResponseRedirect

TEST_ID = 2
TEST_TIME = timezone.now()
Expand Down Expand Up @@ -198,7 +199,7 @@ def test_success_loading_site_join_game_event(self, client, saved_game_event, pl
client.force_login(player.user)
game_event_id = saved_game_event.id
url = reverse('join_event', args=[game_event_id])
response = client.get(url)
response = client.get(url, follow=True)
assert response.status_code == 200

def test_fail_loading_site_join_game_event(self, client, player):
Expand All @@ -211,32 +212,32 @@ def test_success_loading_site_remove_game_event(self, client, saved_game_event,
client.force_login(saved_game_event_player.player.user)
game_event_id = saved_game_event.id
url = reverse('remove_from_event', args=[game_event_id])
response = client.get(url)
response = client.get(url, follow=True)
assert response.status_code == 200

def test_fail_loading_site_remove_game_event_from_player(self, client, player):
client.force_login(player.user)
response = client.get('/game-events/remove-from-event/-1/')
response = client.get('/game-events/remove-from-event/-1/', follow=True)
assert response.status_code == 200
assert b"Can not remove from event, Event Does not Exist! " in response.content
assert b"Event Does not exist." in response.content

def test_fail_loading_remove_from_event_after_deleting_the_game_event(self, client, saved_game_event,
saved_game_event_player):
client.force_login(saved_game_event_player.player.user)
game_event_id = saved_game_event.id
url = reverse('remove_from_event', args=[game_event_id])
response = client.get(url)
response = client.get(url, follow=True)
assert response.status_code == 200
saved_game_event.delete()
response = client.get(url)
response = client.get(url, follow=True)
assert response.status_code == 200
assert b"Can not remove from event, Event Does not Exist! " in response.content
assert b"Event Does not exist." in response.content

def test_remove_player_from_event(self, client, saved_game_event, saved_game_event_player):
client.force_login(saved_game_event_player.player.user)
game_event_id = saved_game_event.id
url = reverse('remove_from_event', args=[game_event_id])
response = client.get(url)
response = client.get(url, follow=True)
assert response.status_code == 200
with pytest.raises(ObjectDoesNotExist):
GameEventPlayer.objects.get(game_event=saved_game_event, player=saved_game_event_player.player)
Expand All @@ -252,7 +253,7 @@ def test_add_player_to_event(self, client, saved_game_event, player):
client.force_login(player.user)
game_event_id = saved_game_event.id
url = reverse('process_answer_game_event', args=[game_event_id])
response = client.post(url, {'answer': 'yes'})
response = client.post(url, {'answer': 'yes'}, follow=True)
assert response.status_code == 200
assert response.context['in_event']
assert GameEventPlayer.objects.filter(game_event=saved_game_event, player=player).exists()
Expand All @@ -261,7 +262,24 @@ def test_fail_add_player_to_event_already_in_it(self, client, saved_game_event,
client.force_login(player.user)
game_event_id = saved_game_event.id
url = reverse('process_answer_game_event', args=[game_event_id])
response = client.post(url, {'answer': 'yes'})
response = client.post(url, {'answer': 'yes'}, follow=True)
assert response.status_code == 200
response = client.post(url, {'answer': 'yes'}, follow=True)
assert response.status_code == 200
assert b"Already in event!" in response.content

def test_player_can_not_join_full_event(self, client, five_game_event_players, player, game_event):
client.force_login(player.user)
url = reverse('process_answer_game_event', args=[game_event.id])
response = client.post(url, {'answer': 'yes'}, follow=True)
assert response.status_code == 200
assert b"The event is full! can not join" in response.content

def test_event_time_constraint(self, client, saved_game_event, saved_game_event_player, court, court_ball_game):
client.force_login(saved_game_event_player.player.user)
event = GameEvent.create(time=saved_game_event.time + timedelta(hours=2), level_of_game=0, min_number_of_players=2,
max_number_of_players=5, court=court, ball_game=BallGame.Basketball)
url = reverse('process_answer_game_event', args=[event.id])
response = client.post(url, {'answer': 'yes'}, follow=True)
assert response.status_code == 200
with pytest.raises(IntegrityError):
response = client.post(url, {'answer': 'yes'})
assert b"You have scheduling conflicts. Resolve them before joining the event" in response.content
Loading

0 comments on commit 818cffc

Please sign in to comment.