def test_valid_form_call_basket(self): """If the form is valid, call basket with the proper arguments.""" request = self.factory.post('/', { 'email': '*****@*****.**', 'country': 'us', 'format': 'text', 'privacy_policy_agree': True }) response = views.newsletter_subscribe(request) eq_(response.status_code, 200) self.subscribe.assert_called_with('*****@*****.**', 'affiliates', format='text', country='us', source_url=ANY)
def test_basket_error_log(self): """If basket throws an exception, log it and return a 500.""" self.subscribe.side_effect = basket.BasketException request = self.factory.post('/', { 'email': '*****@*****.**', 'country': 'us', 'format': 'text', 'privacy_policy_agree': True }) with patch('affiliates.base.views.log') as mock_log: response = views.newsletter_subscribe(request) eq_(response.status_code, 500) self.subscribe.assert_called_with('*****@*****.**', 'affiliates', format='text', country='us', source_url=ANY) ok_(mock_log.error.called)
def test_invalid_form_returns_success(self): """Test that even if the form is invalid, return a 200 OK.""" request = self.factory.post('/', {'country': 'does.not.exist'}) response = views.newsletter_subscribe(request) eq_(response.status_code, 200) ok_(not self.subscribe.called)