class IndexViewTest(TestCase): def setUp(self): self.obj = IndexView() self.obj.request = mock.Mock() self.obj.request.user = mommy.make('User') self.obj.request.session = {} def test_get_context_data_authenticated(self): """ Test for the authenticated, no exception route """ calendar_user = mommy.make(CalendarUser, user=self.obj.request.user) context = self.obj.get_context_data() now = datetime.datetime.now() self.assertEqual(context, { 'current_month': now.month, 'current_year': now.year, 'today': now.day, 'username': self.obj.request.user.username, 'timezone': DEFAULT_TIMEZONE, 'view': self.obj, }) def test_get_context_data_not_authenticated(self): """ Test for the unauthenticated route """ self.obj.request.user.is_authenticated = mock.MagicMock(return_value=False) context = self.obj.get_context_data() self.assertEqual(context, {'view': self.obj}) def test_get_context_data_no_object(self): """ Test for the authenticated, exception route """ context = self.obj.get_context_data() now = datetime.datetime.now() self.assertEqual(context, { 'current_month': now.month, 'current_year': now.year, 'today': now.day, 'username': self.obj.request.user.username, 'timezone': u'UTC', 'view': self.obj, })
def setUp(self): self.obj = IndexView() self.obj.request = mock.Mock() self.obj.request.user = mommy.make('User') self.obj.request.session = {}