Last active
October 13, 2015 10:21
-
-
Save beck/5c417fd1672a497540d1 to your computer and use it in GitHub Desktop.
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
import unittest | |
from mock import patch, Mock | |
from django.shortcuts import render | |
class Dashboard(object): | |
"""This is the system under test.""" | |
@classmethod | |
def view(cls, request): | |
return render(request, 'dashboard.html') | |
class DashboardView_WhenTestedUsingStubs(unittest.TestCase): | |
@patch('__main__.render') | |
def setUp(self, render): | |
render.return_value = Mock(content='<html>dashboard') | |
self.response = Dashboard.view(request=Mock()) | |
def test_returns_a_response_with_a_rendered_dashboard(self): | |
self.assertEqual(self.response.content, '<html>dashboard') | |
class DashboardView_WhenTestedUsingMocks(unittest.TestCase): | |
@patch('__main__.render') | |
def setUp(self, render): | |
self.request = Mock() | |
self.render = render | |
Dashboard.view(self.request) | |
def test_renders_a_request_with_a_template(self): | |
self.render.assert_called_with(self.request, 'dashboard.html') | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like to have long conversations with myself on github. It is my power.