Exemple #1
0
    def test_create_offering_already_existing(self):

        data = {
            'name': 'test_offering_fail',
            'version': '1.0',
            'repository': 'test_repository',
            'image': {
                'name': 'test_image.png',
                'data': self._image,
            },
            'related_images': [],
            'offering_description': {
                'content_type': 'application/rdf+xml',
                'data': self._usdl
            }
        }
        user = User.objects.get(username='******')
        profile = UserProfile.objects.get(user=user)
        org = Organization.objects.get(name='test_organization')
        profile.current_organization = org
        profile.organizations.append({
            'organization': org.pk,
            'roles': ['customer', 'provider']
        })
        profile.save()

        error = False
        msg = None

        try:
            offerings_management.create_offering(user, data)
        except Exception, e:
            error = True
            msg = e.message
Exemple #2
0
    def test_create_offering_usdl_url(self):

        data = {
            'name': 'test_offering',
            'version': '1.0',
            'repository': 'test_repository',
            'image': {
                'name': 'test_image.png',
                'data': self._image,
            },
            'related_images': [],
            'description_url': 'http://examplerep/v1/test_usdl'
        }

        user = User.objects.get(username='******')
        profile = UserProfile.objects.get(user=user)
        org = Organization.objects.get(name='test_organization')
        profile.current_organization = org
        profile.organizations.append({
            'organization': org.pk,
            'roles': ['customer', 'provider']
        })
        profile.save()

        offerings_management.create_offering(user, data)
        content = self._db.wstore_offering.find_one({"name": "test_offering"})

        self.assertEqual(content['name'], 'test_offering')
        self.assertEqual(content['version'], '1.0')
        self.assertEqual(content['state'], 'uploaded')
        self.assertEqual(content['image_url'], '/media/test_organization__test_offering__1.0/test_image.png')
        self.assertEqual(content['description_url'], 'http://examplerep/v1/test_usdl')
Exemple #3
0
    def test_create_offering_invalid_USDL(self):
        """
        Test the creating of an offering with an invalid USDL format
        """
        data = {
            'name': 'test_offering',
            'version': '1.0',
            'repository': 'test_repository',
            'image': {
                'name': 'test_image.png',
                'data': self._image,
            },
            'related_images': [],
            'offering_description': {
                'content_type': 'application/rdf+xml',
                'data': 'Invalid data'
            }
        }
        user = User.objects.get(username='******')
        profile = UserProfile.objects.get(user=user)
        org = Organization.objects.get(name='test_organization')
        profile.current_organization = org
        profile.organizations.append({
            'organization': org.pk,
            'roles': ['customer', 'provider']
        })
        profile.save()
        error = False
        try:
            offerings_management.create_offering(user, data)
        except:
            error = True

        self.assertTrue(error)
Exemple #4
0
    def test_create_offering_images(self):
        """
        Test the basic creation of an offering
        """
        # load screenshots

        path = os.path.join(settings.BASEDIR, 'wstore/test/')
        f = open(os.path.join(path, 'test_screen1.png'), 'rb')
        image1 = base64.b64encode(f.read())

        f = open(os.path.join(path, 'test_screen2.png'), 'rb')
        image2 = base64.b64encode(f.read())

        data = {
            'name': 'test_offering',
            'version': '1.0',
            'repository': 'test_repository',
            'image': {
                'name': 'test_image.png',
                'data': self._image,
            },
            'related_images': [{
                'name': 'test_screen1.png',
                'data': image1
            },
            {
                'name': 'test_screen2.png',
                'data': image2
            }],
            'offering_description': {
                'content_type': 'application/rdf+xml',
                'data': self._usdl
            }
        }
        user = User.objects.get(username='******')
        profile = UserProfile.objects.get(user=user)
        org = Organization.objects.get(name='test_organization')
        profile.current_organization = org
        profile.organizations.append({
            'organization': org.pk,
            'roles': ['customer', 'provider']
        })
        profile.save()

        offerings_management.create_offering(user, data)
        content = self._db.wstore_offering.find_one({"name": "test_offering"})

        self.assertEqual(content['name'], 'test_offering')
        self.assertEqual(content['version'], '1.0')
        self.assertEqual(content['state'], 'uploaded')
        self.assertEqual(content['image_url'], '/media/test_organization__test_offering__1.0/test_image.png')
        self.assertEqual(content['description_url'], 'http://testrepository/storeOfferingCollection/test_organization__test_offering__1.0')

        self.assertEqual(len(content['related_images']), 2)
        contains = '/media/test_organization__test_offering__1.0/test_screen1.png' in content['related_images']
        self.assertTrue(contains)
        contains = '/media/test_organization__test_offering__1.0/test_screen2.png' in content['related_images']
        self.assertTrue(contains)
Exemple #5
0
    def test_offering_creation(self, offering_data, expected_data, data_filler=None, err_type=None, err_msg=None):

        if data_filler:
            data = data_filler(self, offering_data)
        else:
            data = offering_data

        user = User.objects.get(username='******')
        org = Organization.objects.get(name='test_organization')
        user.userprofile.current_organization = org
        user.userprofile.organizations.append({
            'organization': org.pk,
            'roles': ['customer', 'provider']
        })
        user.userprofile.save()

        error = None
        try:
            offerings_management.create_offering(user, data)
        except Exception as e:
            error = e

        if not err_type:
            self.assertEquals(error, None)
            # Check offering contents
            content = self._db.wstore_offering.find_one({
                "name": offering_data['name'],
                "version": offering_data["version"]
            })
            self.assertEqual(content['name'], offering_data['name'])
            self.assertEqual(content['version'], offering_data['version'])
            self.assertEqual(content['state'], 'uploaded')
            self.assertEqual(content['image_url'], expected_data['image'])
            self.assertEqual(content['description_url'], None)

            if 'screenshots' in expected_data:
                self.assertEquals(content['related_images'], expected_data['screenshots'])

            if 'applications' in offering_data:
                self.assertEquals(content['applications'], offering_data['applications'])

            if 'resources' in offering_data:
                off = Offering.objects.get(name=offering_data['name'], version=offering_data['version'])
                offerings_management.bind_resources.assert_called_once_with(off, offering_data['resources'], user)

            if 'notification_url' in offering_data:
                self.assertEquals(content['notification_url'], expected_data['notification_url'])
        else:
            self.assertEquals(unicode(error), err_msg)
            self.assertTrue(isinstance(error, err_type))
Exemple #6
0
    def create(self, request):

        # Obtains the user profile of the user
        user = request.user

        # Get the provider roles in the current organization
        roles = user.userprofile.get_current_roles()

        # Checks the provider role
        if 'provider' in roles:
            try:
                json_data = json.loads(unicode(request.raw_post_data, 'utf-8'))
                create_offering(user, json_data)
            except HTTPError:
                return build_response(request, 502, 'Bad Gateway')
            except Exception, e:
                return build_response(request, 400, unicode(e))
Exemple #7
0
    def test_offering_creation(self, offering_data, expected_data, data_filler=None, err_type=None, err_msg=None):

        if data_filler:
            data = data_filler(self, offering_data)
        else:
            data = offering_data

        user = User.objects.get(username="******")
        org = Organization.objects.get(name="test_organization")
        user.userprofile.current_organization = org
        user.userprofile.organizations.append({"organization": org.pk, "roles": ["customer", "provider"]})
        user.userprofile.save()

        error = None
        try:
            offerings_management.create_offering(user, data)
        except Exception as e:
            error = e

        if not err_type:
            self.assertEquals(error, None)
            # Check offering contents
            content = self._db.wstore_offering.find_one(
                {"name": offering_data["name"], "version": offering_data["version"]}
            )
            self.assertEqual(content["name"], offering_data["name"])
            self.assertEqual(content["version"], offering_data["version"])
            self.assertEqual(content["state"], "uploaded")
            self.assertEqual(content["image_url"], expected_data["image"])
            self.assertEqual(content["description_url"], None)

            if "screenshots" in expected_data:
                self.assertEquals(content["related_images"], expected_data["screenshots"])

            if "applications" in offering_data:
                self.assertEquals(content["applications"], offering_data["applications"])

            if "resources" in offering_data:
                off = Offering.objects.get(name=offering_data["name"], version=offering_data["version"])
                offerings_management.bind_resources.assert_called_once_with(off, offering_data["resources"], user)

            if "notification_url" in offering_data:
                self.assertEquals(content["notification_url"], expected_data["notification_url"])
        else:
            self.assertEquals(unicode(error), err_msg)
            self.assertTrue(isinstance(error, err_type))
Exemple #8
0
    def create(self, request):
        logger.debug("OfferingCollection.create()")
        # Obtains the user profile of the user
        user = request.user

        # Get the provider roles in the current organization
        roles = user.userprofile.get_current_roles()

        # Checks the provider role
        # TODO: little bit dubious to just iterate over roles
        if 'provider' in roles:
            try:
                json_data = json.loads(unicode(request.raw_post_data, 'utf-8'))
                create_offering(user, json_data)
            except HTTPError:
                return build_response(request, 502, 'Bad Gateway')
            except Exception, e:
                return build_response(request, 400, unicode(e))
Exemple #9
0
    def create(self, request):

        # Obtains the user profile of the user
        user = request.user

        # Get the provider roles in the current organization
        roles = user.userprofile.get_current_roles()

        # Checks the provider role
        if 'provider' in roles:
            try:
                json_data = json.loads(unicode(request.raw_post_data, 'utf-8'))
                create_offering(user, json_data)
            except RepositoryError as e:
                return build_response(request, 502, unicode(e))
            except ConflictError as e:
                return build_response(request, 409, unicode(e))
            except Exception, e:
                return build_response(request, 400, unicode(e))
Exemple #10
0
    def test_create_basic_offering(self):
        """
        Test the basic creation of an offering
        """
        data = {
            'name': 'test_offering',
            'version': '1.0',
            'repository': 'test_repository',
            'image': {
                'name': 'test_image.png',
                'data': self._image,
            },
            'related_images': [],
            'offering_description': {
                'content_type': 'application/rdf+xml',
                'data': self._usdl
            }
        }
        user = User.objects.get(username='******')
        profile = UserProfile.objects.get(user=user)
        org = Organization.objects.get(name='test_organization')
        profile.current_organization = org
        profile.organizations.append({
            'organization': org.pk,
            'roles': ['customer', 'provider']
        })
        profile.save()

        offerings_management.create_offering(user, data)
        content = self._db.wstore_offering.find_one({"name": "test_offering"})

        self.assertEqual(content['name'], 'test_offering')
        self.assertEqual(content['version'], '1.0')
        self.assertEqual(content['state'], 'uploaded')
        self.assertEqual(content['image_url'], '/media/test_organization__test_offering__1.0/test_image.png')
        self.assertEqual(content['description_url'], 'http://testrepository/storeOfferingCollection/test_organization__test_offering__1.0')