def test_handle_form__invalid(self): """ The handle form method should instantiate a TierChangeForm and, if it's invalid, not save it. """ tier = self.create_tier() self.create_tier_info(tier) view = TierChangeView() with mock.patch.object(TierChangeForm, 'is_valid', return_value=False) as is_valid: with mock.patch.object(TierChangeForm, 'save') as save: view.handle_form({'key': 'value'}) self.assertTrue(is_valid.called) self.assertFalse(save.called)
def test_post(self): """ The post method should pass the POST data to the handle_form method, then return the result of the finished() method. """ view = TierChangeView() request = self.factory.post('/', {'tier': 'tier1', 'key': 'value'}) return_value = object() with mock.patch.object(view, 'handle_form') as handle_form: with mock.patch.object(view, 'finished', return_value=return_value) as finished: response = view.post(request) handle_form.assert_called_with(request.POST) finished.assert_called_with() self.assertEqual(response, return_value)
def test_get(self): """ The get method should pass the GET data to the handle_form method, then return the result of the finished() method. """ view = TierChangeView() data = {'key': 'value', 'token': 'token'} request = self.factory.get('/', data) return_value = object() with mock.patch.object(view, 'handle_form') as handle_form: with mock.patch.object(view, 'finished', return_value=return_value) as finished: response = view.get(request) handle_form.assert_called_with(request.GET) finished.assert_called_with() self.assertEqual(response, return_value)
AuthorFormSet, VideoFormSet) from mirocommunity_saas.admin.views import (index, TierView, TierChangeView, DowngradeConfirmationView) # Tier urls urlpatterns = patterns( '', url(r'^$', index, name='localtv_admin_index'), url(r'^upgrade/$', require_site_admin(TierView.as_view()), name='localtv_admin_tier'), url(r'^upgrade/confirm_downgrade/$', require_site_admin(DowngradeConfirmationView.as_view()), name='localtv_admin_tier_confirm'), url(r'^upgrade/complete/$', require_site_admin(TierChangeView.as_view()), name='localtv_admin_tier_change'), url(r'^paypal/', include('paypal.standard.ipn.urls')), ) # Moderation overrides urlpatterns += patterns( 'mirocommunity_saas.admin.approve_reject_views', url(r'^actions/approve_video/$', 'approve_video', name='localtv_admin_approve_video'), url(r'^actions/feature_video/$', 'feature_video', name='localtv_admin_feature_video'), url(r'^actions/approve_all/$', 'approve_all',
AuthorFormSet, VideoFormSet) from mirocommunity_saas.admin.views import (index, TierView, TierChangeView, DowngradeConfirmationView) # Tier urls urlpatterns = patterns('', url(r'^$', index, name='localtv_admin_index'), url(r'^upgrade/$', require_site_admin(TierView.as_view()), name='localtv_admin_tier'), url(r'^upgrade/confirm_downgrade/$', require_site_admin(DowngradeConfirmationView.as_view()), name='localtv_admin_tier_confirm'), url(r'^upgrade/complete/$', require_site_admin(TierChangeView.as_view()), name='localtv_admin_tier_change'), url(r'^paypal/', include('paypal.standard.ipn.urls')), ) # Moderation overrides urlpatterns += patterns('mirocommunity_saas.admin.approve_reject_views', url(r'^actions/approve_video/$', 'approve_video', name='localtv_admin_approve_video'), url(r'^actions/feature_video/$', 'feature_video', name='localtv_admin_feature_video'), url(r'^actions/approve_all/$', 'approve_all', name='localtv_admin_approve_all'), ) # Live search overrides
def test_finished(self): """The finished method should return a redirect to the tier index.""" response = TierChangeView().finished() self.assertRedirects(response, '/admin/upgrade/', '')