Repository: craiga/will-of-the-prophets

Issue:
Visiting /roll raises an error if no rolls exist
```
Environment:


Request Method: GET
Request URL: http://localhost:8000/roll/

Django Version: 2.2
Python Version: 3.7.3
Installed Applications:
['raven.contrib.django.raven_compat',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'sass_processor',
 'widget_tweaks',
 'tz_detect',
 'debug_toolbar',
 's3direct',
 'bootstrap',
 'will_of_the_prophets']
Installed Middleware:
('raven.contrib.django.middleware.DjangoRestFrameworkCompatMiddleware',
 'raven.contrib.django.middleware.SentryMiddleware',
 'whitenoise.middleware.WhiteNoiseMiddleware',
 'raven.contrib.django.raven_compat.middleware.Sentry404CatchMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'tz_detect.middleware.TimezoneMiddleware')



Traceback:

File "/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/views/generic/base.py" in view
  71.             return self.dispatch(request, *args, **kwargs)

File "/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/contrib/auth/mixins.py" in dispatch
  52.         return super().dispatch(request, *args, **kwargs)

File "/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/views/generic/base.py" in dispatch
  97.         return handler(request, *args, **kwargs)

File "/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/views/generic/edit.py" in get
  168.         return super().get(request, *args, **kwargs)

File "/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/views/generic/edit.py" in get
  133.         return self.render_to_response(self.get_context_data())

File "/Users/craiga/will_of_the_prophets/will_of_the_prophets/views.py" in get_context_data
  82.             board=board.Board(now=last_roll.embargo),

Exception Type: AttributeError at /roll/
Exception Value: 'NoneType' object has no attribute 'embargo'
```


Discussion:

Resolving patch:
diff --git a/will_of_the_prophets/views.py b/will_of_the_prophets/views.py
--- a/will_of_the_prophets/views.py
+++ b/will_of_the_prophets/views.py
@@ -76,10 +76,14 @@ class RollView(LoginRequiredMixin, CreateView):
 
     def get_context_data(self, **kwargs):
         last_roll = models.Roll.objects.order_by("-embargo").first()
+        last_roll_embargo = None
+        if last_roll:
+            last_roll_embargo = last_roll.embargo
+
         return super().get_context_data(
             **kwargs,
             last_roll=last_roll,
-            board=board.Board(now=last_roll.embargo),
+            board=board.Board(now=last_roll_embargo),
             special_square_types=models.SpecialSquareType.objects.all(),
         )
 


Test patch:
diff --git a/will_of_the_prophets/tests/test_authorization.py b/will_of_the_prophets/tests/test_authorization.py
--- a/will_of_the_prophets/tests/test_authorization.py
+++ b/will_of_the_prophets/tests/test_authorization.py
@@ -3,12 +3,6 @@
 # pylint: disable=redefined-outer-name, unused-argument
 
 import pytest
-from model_mommy import mommy
-
-
-@pytest.fixture
-def roll():
-    return mommy.make("Roll")
 
 
 @pytest.mark.django_db
@@ -21,7 +15,7 @@ def test_public(client, url):
 
 @pytest.mark.django_db
 @pytest.mark.parametrize("url", ["/roll/"])
-def test_requires_auth(client, admin_client, url, roll):
+def test_requires_auth(client, admin_client, url):
     """Test that pages require authorization."""
     response = client.get(url)
     assert response.status_code == 302