def test_not_authenticated(self): """ If the current user isn't authenticated, render the home page with the correct stats. """ request = self.factory.get('/') request.user = Mock() request.user.is_authenticated.return_value = False # User count = 27 + 8 autogenerated via related factory # Click count = 64 # Link count = 3 + 5 autogenerated via related factory UserFactory.create_batch(27) for clicks in (4, 6, 9, 10): DataPointFactory.create(link_clicks=clicks, date=date(2014, 4, 26)) for clicks in (25, 5, 5): LinkFactory.create(aggregate_link_clicks=clicks) # Create a link with multiple datapoints to test for a faulty # join that would screw up the totals. link = LinkFactory.create() DataPointFactory.create(link_clicks=7, link=link, date=date(2014, 4, 26)) DataPointFactory.create(link_clicks=7, link=link, date=date(2014, 4, 27)) with patch('affiliates.base.views.render') as render: eq_(views.home(request), render.return_value) render.assert_called_with(request, 'base/home.html', { 'affiliate_count': 35, 'link_count': 8, 'click_count': 78 })
def test_authenticated(self): """ If the current user is authenticated, redirect to the dashboard. """ request = self.factory.get('/') request.user = Mock() request.user.is_authenticated.return_value = True response = views.home(request) self.assertRedirectsNoFollow(response, reverse('base.dashboard'))
def test_not_authenticated(self): """ If the current user isn't authenticated, render the home page. """ request = self.factory.get('/') request.user = Mock() request.user.is_authenticated.return_value = False with patch('affiliates.base.views.render') as render: eq_(views.home(request), render.return_value) render.assert_called_with(request, 'base/home.html')
def test_not_authenticated(self): """ If the current user isn't authenticated, render the home page with the correct stats. """ request = self.factory.get('/') request.user = Mock() request.user.is_authenticated.return_value = False # User count = 27 + 3 autogenerated via related factory # Link count = 3 autogenerated via related factory UserFactory.create_batch(27) LinkFactory.create_batch(3) with patch('affiliates.base.views.render') as render: with patch.object(Link.objects, 'total_link_clicks', return_value=64): eq_(views.home(request), render.return_value) render.assert_called_with(request, 'base/home.html', { 'affiliate_count': 30, 'link_count': 3, 'click_count': 64 })