Skip to content

Commit

Permalink
Merge pull request #90 from amitCohen2/Notification
Browse files Browse the repository at this point in the history
Add Notification Entity
  • Loading branch information
yftacherzog authored May 31, 2023
2 parents 67cf51a + bd154ce commit 213d7ac
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 0 deletions.
13 changes: 13 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from player.models import BallGame, Player
from court.models import Court
from court_ball_game.models import CourtBallGame
from notification.models import Notification, NotificationType
from django.utils import timezone
from decimal import Decimal
import pytest

Expand All @@ -26,3 +28,14 @@ def court():
def court_ball_game(court):
court_ball_game = CourtBallGame.objects.create(court=court, ball_game=BallGame.Basketball)
return court_ball_game


@pytest.fixture
def notification(player):
return Notification.objects.create(
player=player,
sent_time=timezone.now(),
message='Test notification',
notification_type=NotificationType.WEBSITE,
is_read=False
)
1 change: 1 addition & 0 deletions meetballs/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
'player_rating.apps.PlayerRatingConfig',
'game_event_player.apps.GameEventPlayerConfig',
'court_ball_game.apps.CourtBallGameConfig',
'notification.apps.NotificationConfig',
]

MIDDLEWARE = [
Expand Down
Empty file added notification/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions notification/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.contrib import admin
from .models import Notification

admin.site.register(Notification)
6 changes: 6 additions & 0 deletions notification/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class NotificationConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'notification'
31 changes: 31 additions & 0 deletions notification/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 4.2 on 2023-05-31 08:04

from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

initial = True

dependencies = [
('player', '0002_static_players'),
]

operations = [
migrations.CreateModel(
name='Notification',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('sent_time', models.DateTimeField(default=django.utils.timezone.now)),
('message', models.TextField(blank=True, null=True)),
('notification_type', models.CharField(choices=[('website', 'Website'),
('game-event', 'Game-Event'),
('chat', 'Chat')],
default='website', max_length=100)),
('is_read', models.BooleanField(default=False)),
('player', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='player.player')),
],
),
]
Empty file.
28 changes: 28 additions & 0 deletions notification/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.db import models
from django.utils import timezone
from player.models import Player


class NotificationType(models.TextChoices):
WEBSITE = "website", "Website"
EVENT = "game-event", "Game-Event"
CHAT = "chat", "Chat"


class Notification(models.Model):
player = models.ForeignKey(Player, on_delete=models.CASCADE)
sent_time = models.DateTimeField(default=timezone.now)
message = models.TextField(null=True, blank=True)
notification_type = models.CharField(
max_length=100,
choices=NotificationType.choices,
default=NotificationType.WEBSITE,
)
is_read = models.BooleanField(default=False)

def __str__(self):
return f"{self.notification_type} - {self.message}"

def mark_notification_as_read(self):
self.is_read = True
self.save()
21 changes: 21 additions & 0 deletions notification/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest
from notification.models import Notification


@pytest.mark.django_db
class TestNotification:
def test_create_notification(self, notification):
assert isinstance(notification, Notification)

def test_persisted_notification_in_database(self, notification):
assert notification in Notification.objects.all()

def test_delete_notification_from_database(self, notification):
notification.delete()
with pytest.raises(Notification.DoesNotExist):
Notification.objects.get(pk=notification.pk)

def test_mark_as_read_notification(self, notification):
assert notification.is_read is False
notification.mark_notification_as_read()
assert notification.is_read is True
Empty file added notification/urls.py
Empty file.
Empty file added notification/views.py
Empty file.

0 comments on commit 213d7ac

Please sign in to comment.