-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from amitCohen2/Notification
Add Notification Entity
- Loading branch information
Showing
11 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Empty file.