mirror of
https://github.com/Without-Proper-Instructions/GoatCTF
synced 2025-10-08 07:40:46 +00:00
Adds admin and tests for Hint model.
This commit is contained in:
parent
63eee10236
commit
8a0c539143
@ -1,5 +1,5 @@
|
||||
from django.contrib import admin
|
||||
from core.models import Challenge, Team, Player, Solution
|
||||
from core.models import Challenge, Hint, Team, Player, Solution
|
||||
from core.forms import ChallengeAdminForm
|
||||
|
||||
|
||||
@ -7,7 +7,11 @@ class ChallengeAdmin(admin.ModelAdmin):
|
||||
fields = ['name', 'points', 'category', 'flag', 'description_markdown']
|
||||
form = ChallengeAdminForm
|
||||
|
||||
class HintAdmin(admin.ModelAdmin):
|
||||
fields = ['challenge', 'content_markdown', 'publish_date']
|
||||
|
||||
admin.site.register(Challenge, ChallengeAdmin)
|
||||
admin.site.register(Hint, HintAdmin)
|
||||
admin.site.register(Team)
|
||||
admin.site.register(Player)
|
||||
admin.site.register(Solution)
|
||||
|
@ -85,6 +85,7 @@ class Player(User):
|
||||
def has_gravatar(self):
|
||||
return has_gravatar(self.email)
|
||||
|
||||
|
||||
class Solution(models.Model):
|
||||
"""A solution is a record of a player's successful attempt of a challenge."""
|
||||
challenge = models.ForeignKey("Challenge")
|
||||
@ -116,14 +117,13 @@ class Hint(models.Model):
|
||||
"""
|
||||
challenge = models.ForeignKey("Challenge")
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
publish_date = models.DateTimeField(blank=True, null=False)
|
||||
publish_date = models.DateTimeField(auto_now_add=True, editable=True)
|
||||
content_markdown = models.TextField()
|
||||
content_html = models.TextField()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.content_html = markdown.markdown(self.content_markdown)
|
||||
if self.publish_date is None:
|
||||
self.publish_date = self.created_date
|
||||
|
||||
super(Hint, self).save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return "{challenge} ({date})".format(challenge=self.challenge, date=self.publish_date)
|
||||
|
32
goatctf/tests/test_hint.py
Normal file
32
goatctf/tests/test_hint.py
Normal file
@ -0,0 +1,32 @@
|
||||
import pytest
|
||||
from core.models import Challenge, Hint
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def challenge():
|
||||
c = Challenge(name="Get Crunk", category='be', points=100)
|
||||
c.save()
|
||||
return c
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_auto_populate_publish_date(challenge):
|
||||
hint = Hint(challenge=challenge, content_markdown='')
|
||||
hint.save()
|
||||
assert hint.publish_date is not None
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_markdown_compiles_on_save(challenge):
|
||||
hint = Hint(challenge=challenge)
|
||||
hint.content_markdown = """# Title
|
||||
## Subtitle
|
||||
|
||||
Paragraph
|
||||
|
||||
Another paragraph
|
||||
"""
|
||||
hint.save()
|
||||
assert hint.content_html == (
|
||||
"<h1>Title</h1>\n<h2>Subtitle</h2>\n<p>Paragraph</p>\n<p>Another "
|
||||
"paragraph</p>")
|
Loading…
x
Reference in New Issue
Block a user