Skip to content

Instantly share code, notes, and snippets.

@wooyek
Created September 16, 2016 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wooyek/635b4d6fbd6cc23c61f1df288cece58e to your computer and use it in GitHub Desktop.
Save wooyek/635b4d6fbd6cc23c61f1df288cece58e to your computer and use it in GitHub Desktop.
Django interview task
# Make this test pass.
# Make sure the get method is tested and leave the assertions as they are.
from django.contrib import messages
from django.contrib.messages import constants
from django.http import HttpRequest
from django.http import HttpResponse
from django.test import SimpleTestCase
from django.views import View
class SomeMessagingView(View):
def get(self, request, *args, **kwargs):
messages.info(self.request, "Lore imspum.")
return HttpResponse("")
class SomeViewTests(SimpleTestCase):
def test(self):
request = HttpRequest()
view = SomeMessagingView(request=request)
response = view.get(request)
self.assertEqual(200, response.status_code)
self.assertTrue(request._messages.add.called)
request._messages.add.assert_called_once_with(constants.INFO, "Lore imspum.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment