Ejemplo n.º 1
0
 def test_non_existing_app_raises_404(self):
     request = self._get_request()
     with patch('us_ignite.apps.views.get_object_or_404',
                side_effect=Http404) as get_mock:
         views.app_edit(request, 'my-app')
         get_mock.assert_called_once_with(
             Application.active, slug__exact='my-app')
Ejemplo n.º 2
0
 def test_non_editable_app_raises_404(self):
     request = self._get_request()
     mock_app = Mock(spec=Application)()
     mock_app.is_editable_by.return_value = False
     with patch('us_ignite.apps.views.get_object_or_404',
                return_value=mock_app) as get_mock:
         views.app_edit(request, 'my-app')
         mock_app.is_editable_by.assert_called_once_with(request.user)
Ejemplo n.º 3
0
 def test_get_request_is_successful(self):
     owner = get_user('us-ignite')
     app = fixtures.get_application(
         slug='alpha', status=Application.PUBLISHED, owner=owner)
     request = self.factory.get('/app/alpha/')
     request.user = owner
     response = views.app_edit(request, 'alpha')
     eq_(sorted(response.context_data.keys()),
         ['form', 'image_formset', 'link_formset', 'object'])
     eq_(response.template_name, 'apps/object_edit.html')
Ejemplo n.º 4
0
 def test_post_request_is_successful(self):
     owner = get_user('us-ignite')
     app = fixtures.get_application(
         slug='beta', status=Application.PUBLISHED, owner=owner)
     payload = _get_message_payload(name='Updated')
     payload.update(_get_applinks_inline_payload(app.id))
     payload.update(_get_appimages_inline_payload(app.id))
     request = self.factory.post('/app/beta/', payload)
     request._messages = utils.TestMessagesBackend(request)
     request.user = owner
     response = views.app_edit(request, 'beta')
     eq_(response.status_code, 302)
     eq_(response['Location'], app.get_absolute_url())
     eq_(Application.objects.values('name').get(owner=owner),
         {'name': 'Updated'})
     eq_(ApplicationURL.objects.filter(application=app).count(), 0)
Ejemplo n.º 5
0
 def test_post_request_saves_urls(self):
     owner = get_user('us-ignite')
     app = fixtures.get_application(
         slug='beta', status=Application.PUBLISHED, owner=owner)
     payload = _get_message_payload()
     links = [
         {'name': 'github', 'url': 'http://github.com'},
         {'name': 'twitter', 'url': 'http://twitter.com'},
     ]
     payload.update(_get_applinks_inline_payload(app.id, data_list=links))
     payload.update(_get_appimages_inline_payload(app.id))
     request = self.factory.post('/app/beta/', payload)
     request._messages = utils.TestMessagesBackend(request)
     request.user = owner
     response = views.app_edit(request, 'beta')
     eq_(response.status_code, 302)
     eq_(response['Location'], app.get_absolute_url())
     eq_(ApplicationURL.objects.filter(application=app).count(), 2)
Ejemplo n.º 6
0
 def test_application_post_request_require_login(self):
     request = self.factory.post('/app/my-app/edit/', _get_message_payload())
     request.user = utils.get_anon_mock()
     response = views.app_edit(request)
     eq_(response['Location'], utils.get_login_url('/app/my-app/edit/'))
Ejemplo n.º 7
0
 def test_anon_get_request_require_login(self):
     request = self.factory.get('/app/my-app/edit/')
     request.user = utils.get_anon_mock()
     response = views.app_edit(request)
     eq_(response['Location'], utils.get_login_url('/app/my-app/edit/'))