def test_post_sends_request_to_tsuru(self, post): self.request_post.session = {'tsuru_token': 'tokentest'} Add.as_view()(self.request_post) self.assertEqual(1, post.call_count) post.assert_called_with( '%s/teams' % settings.TSURU_HOST, data='{"name": "test-team"}', headers={'authorization': self.request_post.session['tsuru_token']})
def test_post_sends_request_to_tsuru(self, post): self.request_post.session = {'tsuru_token': 'tokentest'} Add.as_view()(self.request_post) self.assertEqual(1, post.call_count) post.assert_called_with('%s/teams' % settings.TSURU_HOST, data='{"name": "test-team"}', headers={ 'authorization': self.request_post.session['tsuru_token'] })
def test_post_without_name_should_return_form_with_errors(self): request = self.factory.post('/team/', {'name': ''}) request.session = {"tsuru_token": "admin"} response = Add.as_view()(request) form = response.context_data.get('form') self.assertIn('name', form.errors) self.assertIn(u'This field is required.', form.errors.get('name'))
def setUp(self): self.factory = RequestFactory() self.request = self.factory.get('/') self.request.session = {"tsuru_token": "admin"} self.response = Add.as_view()(self.request) self.request_post = self.factory.post('/team/', {'name': 'test-team'}) self.request_post.session = {"tsuru_token": "admin"}
def setUp(self, get): get.return_value = Mock(status_code=200) self.factory = RequestFactory() self.request = self.factory.get('/') self.request.session = {"tsuru_token": "admin"} self.response = Add.as_view()(self.request) self.request_post = self.factory.post('/team/', {'name': 'test-team'}) self.request_post.session = {"tsuru_token": "admin"}
def test_post_with_invalid_name_should_return_500(self, post): post.return_value = Mock(status_code=500, content='Error') response = Add.as_view()(self.request_post) self.assertEqual('Error', response.context_data.get('errors'))
def test_valid_post_redirect_to_team_list(self, post): post.return_value = Mock(status_code=200) response = Add.as_view()(self.request_post) self.assertEqual(302, response.status_code) self.assertEqual(reverse('team-list'), response.items()[1][1])
def test_post_with_invalid_name_should_return_500(self, get, post): get.return_value = Mock(status_code=200) post.return_value = Mock(status_code=500, content='Error') response = Add.as_view()(self.request_post) self.assertEqual('Error', response.context_data.get('errors'))
def test_valid_post_redirect_to_team_list(self, get, post): get.return_value = Mock(status_code=200) post.return_value = Mock(status_code=200) response = Add.as_view()(self.request_post) self.assertEqual(302, response.status_code) self.assertEqual(reverse('team-list'), response.items()[1][1])