Exemplo n.º 1
0
    def test_publish_offering(self):

        # Mock publish offering method
        views.publish_offering = MagicMock(name='publish_offering')
        publish_entry = views.PublishEntry(permitted_methods=('POST', ))

        offering = Offering.objects.create(
            name='test_offering',
            owner_organization=Organization.objects.get(
                name=self.user.username),
            owner_admin_user=self.user,
            version='1.0',
            state='uploaded',
            description_url='',
            resources=[],
            comments=[],
            tags=[],
            image_url='',
            related_images=[],
            offering_description={},
            notification_url='',
            creation_date='2013-06-03 10:00:00')

        # Call the view
        site = Site.objects.create(name='Test_site',
                                   domain='http://testsite.com')
        Context.objects.create(site=site)
        views.get_current_site = MagicMock()
        views.get_current_site.return_value = site

        response = publish_entry.create(self.request, 'test_user',
                                        'test_offering', '1.0')

        views.publish_offering.assert_called_once_with(self.user, offering,
                                                       self.data)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.get('Content-type'),
                         'application/json; charset=utf-8')
        body_response = json.loads(response.content)

        self.assertEqual(type(body_response), dict)
        self.assertEqual(body_response['message'], 'OK')
        self.assertEqual(body_response['result'], 'correct')
Exemplo n.º 2
0
    def test_publish_offering_not_found(self):

        # Mock publish offering method
        views.publish_offering = MagicMock(name='publish_offering')
        publish_entry = views.PublishEntry(permitted_methods=('POST', ))

        # Call the view
        response = publish_entry.create(self.request, 'test_user',
                                        'test_offering', '1.0')

        self.assertFalse(views.publish_offering.called)

        self.assertEqual(response.status_code, 404)
        self.assertEqual(response.get('Content-type'),
                         'application/json; charset=utf-8')
        body_response = json.loads(response.content)

        self.assertEqual(type(body_response), dict)
        self.assertEqual(body_response['message'], 'Offering not found')
        self.assertEqual(body_response['result'], 'error')
Exemplo n.º 3
0
    def test_publish_entry_not_owner(self):

        # Mock publish offering method
        views.publish_offering = MagicMock(name='publish_offering')
        publish_entry = views.PublishEntry(permitted_methods=('POST', ))
        org = Organization.objects.get(name=self.user.username)
        org.managers = []
        org.save()

        Offering.objects.create(name='test_offering',
                                owner_organization=org,
                                owner_admin_user=self.user,
                                version='1.0',
                                state='uploaded',
                                description_url='',
                                resources=[],
                                comments=[],
                                tags=[],
                                image_url='',
                                related_images=[],
                                offering_description={},
                                notification_url='',
                                creation_date='2013-06-03 10:00:00')
        Offering.is_owner = MagicMock()
        Offering.is_owner.return_value = False

        # Call the view
        response = publish_entry.create(self.request, 'test_user',
                                        'test_offering', '1.0')

        self.assertFalse(views.publish_offering.called)

        self.assertEqual(response.status_code, 403)
        self.assertEqual(response.get('Content-type'),
                         'application/json; charset=utf-8')
        body_response = json.loads(response.content)

        self.assertEqual(type(body_response), dict)
        self.assertEqual(body_response['message'], 'Forbidden')
        self.assertEqual(body_response['result'], 'error')
Exemplo n.º 4
0
    def test_publish_entry_bad_gateway(self):

        # Mock publish offering method
        views.publish_offering = MagicMock(name='publish_offering')
        views.publish_offering.side_effect = HTTPError('', 500, '', None, None)
        publish_entry = views.PublishEntry(permitted_methods=('POST', ))

        offering = Offering.objects.create(
            name='test_offering',
            owner_organization=Organization.objects.get(
                name=self.user.username),
            owner_admin_user=self.user,
            version='1.0',
            state='uploaded',
            description_url='',
            resources=[],
            comments=[],
            tags=[],
            image_url='',
            related_images=[],
            offering_description={},
            notification_url='',
            creation_date='2013-06-03 10:00:00')
        # Call the view
        response = publish_entry.create(self.request, 'test_user',
                                        'test_offering', '1.0')

        views.publish_offering.assert_called_once_with(self.user, offering,
                                                       self.data)

        self.assertEqual(response.status_code, 502)
        self.assertEqual(response.get('Content-type'),
                         'application/json; charset=utf-8')
        body_response = json.loads(response.content)

        self.assertEqual(type(body_response), dict)
        self.assertEqual(body_response['message'],
                         'The Marketplace has failed publishing the offering')
        self.assertEqual(body_response['result'], 'error')
Exemplo n.º 5
0
     r'^api/administration/organizations/(?P<org>[\w -]+)/users/?$',
     org_views.OrganizationUserCollection(permitted_methods=('GET',
                                                             'POST'))),
 url(r'^api/offering/offerings/?$',
     offering_views.OfferingCollection(permitted_methods=('GET', 'POST'))),
 url(r'^api/offering/offerings/latest/?$',
     offering_views.NewestCollection(permitted_methods=('GET', ))),
 url(r'^api/offering/offerings/toprated/?$',
     offering_views.TopRatedCollection(permitted_methods=('GET', ))),
 url(
     r'^api/offering/offerings/(?P<organization>[\w -]+)/(?P<name>[\w -]+)/(?P<version>[\d.]+)/?$',
     offering_views.OfferingEntry(permitted_methods=('GET', 'PUT',
                                                     'DELETE'))),
 url(
     r'^api/offering/offerings/(?P<organization>[\w -]+)/(?P<name>[\w -]+)/(?P<version>[\d.]+)/publish/?$',
     offering_views.PublishEntry(permitted_methods=('POST', ))),
 url(
     r'^api/offering/offerings/(?P<organization>[\w -]+)/(?P<name>[\w -]+)/(?P<version>[\d.]+)/bind/?$',
     offering_views.BindEntry(permitted_methods=('POST', ))),
 url(
     r'^api/offering/offerings/(?P<organization>[\w -]+)/(?P<name>[\w -]+)/(?P<version>[\d.]+)/review/?$',
     offering_views.ReviewCollection(permitted_methods=('POST', 'GET'))),
 url(
     r'^api/offering/offerings/(?P<organization>[\w -]+)/(?P<name>[\w -]+)/(?P<version>[\d.]+)/review/(?P<review>\w+)/?$',
     offering_views.ReviewEntry(permitted_methods=('PUT', 'DELETE'))),
 url(
     r'^api/offering/offerings/(?P<organization>[\w -]+)/(?P<name>[\w -]+)/(?P<version>[\d.]+)/review/(?P<review>\w+)/reply/?$',
     offering_views.ResponseEntry(permitted_methods=('PUT', 'DELETE'))),
 url(
     r'^api/offering/offerings/(?P<organization>[\w -]+)/(?P<name>[\w -]+)/(?P<version>[\d.]+)/tag/?$',
     tagging_views.TagCollection(permitted_methods=('GET', 'PUT'))),