def test_post_with_valid_app_and_command(self, post): content = "command runned" post.return_value = Mock(status_code=200, content=content) response = Run().post(self.request_post) self.assertEqual("command runned", response.context_data.get('message')) self.assertIn('form', response.context_data.keys()) self.assertIsInstance(response.context_data.get('form'), RunForm)
def test_post_with_app_and_command_sends_post(self, post): self.request_post.session = {'tsuru_token': 'tokentest'} Run().post(self.request_post) self.assertEqual(1, post.call_count) post.assert_called_with( '%s/apps/app-test/run' % settings.TSURU_HOST, data=u'command-test', headers={'authorization': self.request_post.session['tsuru_token']})
def setUp(self): self.factory = RequestFactory() self.request = self.factory.get('/') self.response = Run().get(self.request) self.request_post = self.factory.post( '/', {'app': 'app-test', 'command': 'command-test'}) self.request_post.session = {} self.response_mock = Mock()
def test_post_without_app_should_return_form_with_errors(self, post): request = self.factory.post('/', {'app': '', 'command': 'command-test'}) request.session = {} response = Run().post(request) self.assertIn('form', response.context_data.keys()) form = response.context_data.get('form') self.assertTrue(isinstance(form, RunForm)) self.assertEqual(u'This field is required.', form.errors.get('app')[0])
def test_post_without_app_should_return_form_with_errors(self, get, post): content = (u"""[{"name":"appbla"}, {"name":"appble"}]""") m = Mock(status_code=200, content=content) m.json.return_value = json.loads(content) get.return_value = m request = self.factory.post('/', { 'app': '', 'command': 'command-test' }) request.session = {} response = Run().post(request) self.assertIn('form', response.context_data.keys()) form = response.context_data.get('form') self.assertIsInstance(form, RunForm) self.assertEqual(u'This field is required.', form.errors.get('app')[0])
def setUp(self, get): self.factory = RequestFactory() self.request = self.factory.get('/') self.request.session = {} content = u'[{"name": "appbla"}, {"name": "appble"}]' m = Mock(status_code=200, content=content) m.json.return_value = json.loads(content) get.return_value = m self.response = Run().get(self.request) self.request_post = self.factory.post('/', { 'app': 'app-test', 'command': 'command-test' }) self.request_post.session = {} self.response_mock = Mock()
def test_post_without_app_should_not_send_request_to_tsuru(self, post): request = self.factory.post('/', {'app': '', 'command': 'comand-test'}) request.session = {} Run().post(request) self.assertEqual(0, post.call_count)
def test_post_with_invalid_app_or_command(self, post): post.return_value = Mock(status_code=500, content='Error') response = Run().post(self.request_post) self.assertIn('form', response.context_data.keys()) self.assertIsInstance(response.context_data.get('form'), RunForm)
def test_post_with_invalid_app_or_command_error_in_context(self, post): post.return_value = Mock(status_code=500, content='Error') response = Run().post(self.request_post) self.assertEqual('Error', response.context_data.get('errors'))
class TextPlainView(TemplateView): def render_to_response(self, context, **kwargs): return super(TextPlainView, self).render_to_response( context, content_type='text/plain', **kwargs) urlpatterns = patterns('', url(r'^robots\.txt$', TextPlainView.as_view(template_name='robots.txt')), url(r'^favicon\.ico$', RedirectView.as_view(url='/static/img/favicon.ico')), url(r'^$', Login.as_view(), name='login'), url(r'^login$', Login.as_view(), name='login'), url(r'^logout$', Logout.as_view(), name='logout'), url(r'^team/$', Team.as_view(), name='team'), url(r'^key/$', Key.as_view(), name='token'), url(r'^signup$', Signup.as_view(), name='signup'), url(r'^apps/$', ListApp.as_view(), name='list-app'), url(r'^apps/create/$', CreateApp.as_view(), name='create-app'), url(r'^app/run/$', Run.as_view(), name='run'), url(r'^app/(?P<app_name>[\w-]+)/$', AppDetail.as_view(), name='detail-app'), url(r'^app/(?P<name>[\w-]+)/remove/$', RemoveApp.as_view(), name='remove_app'), url(r'^app/(?P<app_name>[\w-]+)/log/$', AppLog.as_view(), name='app_log'), url(r'^app/(?P<app_name>[\w-]+)/env/$', AppEnv.as_view(), name='get-env'), url(r'^app/(?P<app_name>[\w-]+)/teams/$', AppTeams.as_view(), name='app-teams'), url(r'^app/(?P<app_name>[\w-]+)/team/add/$', AppAddTeam.as_view(), name='app-add-team'), url(r'^envs/$', "auth.views.env_vars", name='envs'), ) urlpatterns += staticfiles_urlpatterns()