def test_should_validate_data_from_post(self):
     data = {'email': '', 'password': '', 'same_password_again': ''}
     request = self.factory.post('/signup', data)
     response = Signup().post(request)
     form = response.context_data['signup_form']
     self.assertIn(u'This field is required.', form.errors['email'])
     self.assertIn(u'This field is required.', form.errors['password'])
     self.assertIn(u'This field is required.',
                   form.errors['same_password_again'])
 def test_return_msg_on_success(self, get, post):
     get.return_value = Mock(status_code=200)
     data = {'email': '*****@*****.**', 'password': '******',
             'same_password_again': 'abc123'}
     request = self.factory.post('/signup', data)
     post.return_value = Mock(status_code=201)
     response = Signup.as_view()(request)
     expected = 'User "{0}" successfully created!'.format(data["email"])
     self.assertEqual(expected, response.context_data["message"])
 def test_post_sends_to_tsuru_with_args_expected(self, get, post):
     get.return_value = Mock(status_code=200)
     data = {'email': '*****@*****.**', 'password': '******',
             'same_password_again': 'abc123'}
     request = self.factory.post('/signup', data)
     Signup().post(request)
     self.assertEqual(1, post.call_count)
     post.assert_called_with(
         '%s/users' % settings.TSURU_HOST,
         data='{"password": "******", "email": "*****@*****.**"}')
 def setUp(self):
     self.factory = RequestFactory()
     self.request = self.factory.get('/')
     self.response = Signup().get(self.request)
     self.response_mock = Mock()