示例#1
0
 def test_invalid_post_should_return_error_message(self, get, post, error):
     get.return_value = Mock(status_code=200)
     post.return_value = Mock(status_code=500, text='Error')
     KeyAdd.as_view()(self.request_post)
     error.assert_called_with(self.request_post,
                              'Error',
                              fail_silently=True)
示例#2
0
 def test_post_without_key_should_not_send_request_to_tsuru(
         self, get, post):
     get.return_value = Mock(status_code=200)
     request = self.factory.post('/team/', {'key': ''})
     request.session = {}
     KeyAdd.as_view()(request)
     self.assertEqual(0, post.call_count)
示例#3
0
 def test_valid_postshould_return_message_expected(self, get, post,
                                                   success):
     get.return_value = Mock(status_code=200)
     post.return_value = Mock(status_code=200)
     KeyAdd.as_view()(self.request_post)
     success.assert_called_with(self.request_post,
                                "The key was successfully added",
                                fail_silently=True)
示例#4
0
 def test_post_with_name_should_send_request_post_to_tsuru(self, get, post, er):
     get.return_value = Mock(status_code=200)
     self.request_post.session = {'tsuru_token': 'tokentest'}
     KeyAdd.as_view()(self.request_post)
     self.assertEqual(1, post.call_count)
     post.assert_called_with(
         '%s/users/keys' % settings.TSURU_HOST,
         data='{"name": "mykey", "key": "test-key-qq"}',
         headers={'authorization':
                  self.request_post.session['tsuru_token']})
示例#5
0
 def test_post_with_name_should_send_request_post_to_tsuru(
         self, get, post, er):
     get.return_value = Mock(status_code=200)
     self.request_post.session = {'tsuru_token': 'tokentest'}
     KeyAdd.as_view()(self.request_post)
     self.assertEqual(1, post.call_count)
     post.assert_called_with('%s/users/keys' % settings.TSURU_HOST,
                             data='{"name": "mykey", "key": "test-key-qq"}',
                             headers={
                                 'authorization':
                                 self.request_post.session['tsuru_token']
                             })
示例#6
0
 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 = KeyAdd.as_view()(self.request)
     self.request_post = self.factory.post('/key/', {'key': 'test-key-qq', 'name': 'mykey'})
     self.request_post.session = {"tsuru_token": "admin"}
示例#7
0
 def test_post_without_key_should_return_form_with_errors(self, get, post):
     get.return_value = Mock(status_code=200)
     request = self.factory.post('/team/', {'key': ''})
     request.session = {"tsuru_token": "admin"}
     response = KeyAdd.as_view()(request)
     self.assertIn('form', response.context_data.keys())
     form = response.context_data.get('form')
     self.assertIsInstance(form, KeyForm)
     self.assertEqual(u'This field is required.', form.errors.get('key')[0])
示例#8
0
 def test_post_without_key_should_return_form_with_errors(self, get, post):
     get.return_value = Mock(status_code=200)
     request = self.factory.post('/team/', {'key': ''})
     request.session = {"tsuru_token": "admin"}
     response = KeyAdd.as_view()(request)
     self.assertIn('form', response.context_data.keys())
     form = response.context_data.get('form')
     self.assertIsInstance(form, KeyForm)
     self.assertEqual(u'This field is required.',
                      form.errors.get('key')[0])
示例#9
0
 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 = KeyAdd.as_view()(self.request)
     self.request_post = self.factory.post('/key/', {
         'key': 'test-key-qq',
         'name': 'mykey'
     })
     self.request_post.session = {"tsuru_token": "admin"}
示例#10
0
 def test_post_without_key_should_not_send_request_to_tsuru(self, get, post):
     get.return_value = Mock(status_code=200)
     request = self.factory.post('/team/', {'key': ''})
     request.session = {}
     KeyAdd.as_view()(request)
     self.assertEqual(0, post.call_count)
示例#11
0
 def test_post_with_error_should_redirects(self, get, post, er):
     get.return_value = Mock(status_code=200)
     post.return_value = Mock(status_code=500, content='Error')
     response = KeyAdd.as_view()(self.request_post)
     self.assertEqual(302, response.status_code)
     self.assertEqual(reverse('key'), response.items()[1][1])
示例#12
0
 def test_successfully_post_should_redirects(self, get, post, m):
     get.return_value = Mock(status_code=200)
     post.return_value = Mock(status_code=200)
     response = KeyAdd.as_view()(self.request_post)
     self.assertEqual(302, response.status_code)
     self.assertEqual(reverse('key'), response.items()[1][1])
示例#13
0
 def test_invalid_post_should_return_error_message(self, get, post, error):
     get.return_value = Mock(status_code=200)
     post.return_value = Mock(status_code=500, text='Error')
     KeyAdd.as_view()(self.request_post)
     error.assert_called_with(self.request_post, 'Error', fail_silently=True)
示例#14
0
 def test_valid_postshould_return_message_expected(self, get, post, success):
     get.return_value = Mock(status_code=200)
     post.return_value = Mock(status_code=200)
     KeyAdd.as_view()(self.request_post)
     success.assert_called_with(self.request_post, "The key was successfully added", fail_silently=True)
示例#15
0
 def test_post_with_error_should_redirects(self, get, post, er):
     get.return_value = Mock(status_code=200)
     post.return_value = Mock(status_code=500, content='Error')
     response = KeyAdd.as_view()(self.request_post)
     self.assertEqual(302, response.status_code)
     self.assertEqual(reverse('key'), response.items()[1][1])
示例#16
0
 def test_successfully_post_should_redirects(self, get, post, m):
     get.return_value = Mock(status_code=200)
     post.return_value = Mock(status_code=200)
     response = KeyAdd.as_view()(self.request_post)
     self.assertEqual(302, response.status_code)
     self.assertEqual(reverse('key'), response.items()[1][1])