Ejemplo n.º 1
0
    def test_basic_retrieving_pagination_purchased(self):

        pagination = {"skip": "1", "limit": "2"}
        user = User.objects.get(username="******")
        profile = UserProfile.objects.get(user=user)
        profile.offerings_purchased = [
            "11000aba8e05ac2115f022f9",
            "21000aba8e05ac2115f022ff",
            "31000aba8e05ac2115f022f0",
        ]
        org = Organization.objects.get(name="test_organization1")
        org.offerings_purchased = ["41000aba8e05ac2115f022f0", "51100aba8e05ac2115f022f0"]
        org.save()
        profile.current_organization = org
        profile.organizations.append({"organization": org.pk, "roles": ["customer", "provider"]})
        profile.save()

        offerings = offerings_management.get_offerings(
            user, filter_="purchased", state=[], pagination=pagination, sort="name"
        )

        self.assertEqual(len(offerings), 2)

        self.assertEqual(offerings[0]["name"], "test_offering4")
        self.assertEqual(offerings[1]["name"], "test_offering5")
Ejemplo n.º 2
0
    def test_basic_retrieving_pagination_purchased(self):

        pagination = {
            'skip': '1',
            'limit': '2'
        }
        user = User.objects.get(username='******')
        profile = UserProfile.objects.get(user=user)
        profile.offerings_purchased = ['11000aba8e05ac2115f022f9', '21000aba8e05ac2115f022ff', '31000aba8e05ac2115f022f0']
        org = Organization.objects.get(name='test_organization1')
        org.offerings_purchased = ['41000aba8e05ac2115f022f0', '51100aba8e05ac2115f022f0']
        org.save()
        profile.current_organization = org
        profile.organizations.append({
            'organization': org.pk,
            'roles': ['customer', 'provider']
        })
        profile.save()

        offerings = offerings_management.get_offerings(user, filter_='purchased', owned=True, pagination=pagination, sort='name')

        self.assertEqual(len(offerings), 2)

        self.assertEqual(offerings[0]['name'], 'test_offering4')
        self.assertEqual(offerings[1]['name'], 'test_offering5')
Ejemplo n.º 3
0
    def test_provider_offerings_retrieving(self, name, filter_, states, expected_offerings, side_effect=None):
        # Get user profile
        user = User.objects.get(username='******')

        # Call the side effect if needed
        if side_effect:
            side_effect(self, user)

        # Call the tested method
        offerings = offerings_management.get_offerings(user, filter_, states)
        self.assertEqual(len(offerings), len(expected_offerings))

        validated = 0

        # Check offering content
        for exp in expected_offerings:
            off = Offering.objects.get(pk=exp)

            for off_info in offerings:
                if off.name == off_info['name']:
                    self.assertEqual(off_info['name'], off.name)
                    self.assertEqual(off_info['version'], off.version)
                    self.assertEqual(off_info['state'], off.state)
                    self.assertEqual(off_info['owner_organization'], off.owner_organization.name)
                    self.assertEqual(off_info['owner_admin_user_id'], off.owner_admin_user.username)
                    self.assertEqual(off_info['description_url'], off.description_url)

                    if len(off.resources):
                        self.assertEquals(len(off.resources), len(off_info['resources']))

                    validated = validated + 1

        self.assertEquals(validated, len(expected_offerings))
Ejemplo n.º 4
0
    def test_provider_offerings_retrieving(self, name, filter_, states, expected_offerings, side_effect=None):
        # Get user profile
        user = User.objects.get(username="******")

        # Call the side effect if needed
        if side_effect:
            side_effect(self, user)

        # Call the tested method
        offerings = offerings_management.get_offerings(user, filter_, states)
        self.assertEqual(len(offerings), len(expected_offerings))

        validated = 0

        # Check offering content
        for exp in expected_offerings:
            off = Offering.objects.get(pk=exp)

            for off_info in offerings:
                if off.name == off_info["name"]:
                    self.assertEqual(off_info["name"], off.name)
                    self.assertEqual(off_info["version"], off.version)
                    self.assertEqual(off_info["state"], off.state)
                    self.assertEqual(off_info["owner_organization"], off.owner_organization.name)
                    self.assertEqual(off_info["owner_admin_user_id"], off.owner_admin_user.username)
                    self.assertEqual(off_info["description_url"], off.description_url)

                    if len(off.resources):
                        self.assertEquals(len(off.resources), len(off_info["resources"]))

                    validated = validated + 1

        self.assertEquals(validated, len(expected_offerings))
Ejemplo n.º 5
0
    def test_retrieving_pagination_invalid_start(self):
        pagination = {
            'skip': '-4',
            'limit': '2'
        }

        user = User.objects.get(username='******')

        error = False
        msg = None

        try:
            offerings_management.get_offerings(user, filter_='all', owned=True, pagination=pagination)
        except Exception, e:
            error = True
            msg = e.message
Ejemplo n.º 6
0
    def test_get_provider_uploaded_offerings(self):

        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()

        offerings = offerings_management.get_offerings(user, 'uploaded', owned=True)
        self.assertEqual(len(offerings), 2)

        for off in offerings:
            if off['name'] == 'test_offering1':
                self.assertEqual(off['name'], 'test_offering1')
                self.assertEqual(off['version'], '1.0')
                self.assertEqual(off['state'], 'uploaded')
                self.assertEqual(off['owner_organization'], 'test_organization')
                self.assertEqual(off['owner_admin_user_id'], 'test_user')
                self.assertEqual(off['description_url'], 'http://testrepository/storeOfferingsCollection/test_organization__test_offering1__1.0')
            else:
                self.assertEqual(off['name'], 'test_offering2')
                self.assertEqual(off['version'], '1.1')
                self.assertEqual(off['state'], 'uploaded')
                self.assertEqual(off['owner_organization'], 'test_organization')
                self.assertEqual(off['owner_admin_user_id'], 'test_user')
                self.assertEqual(off['description_url'], 'http://testrepository/storeOfferingsCollection/test_organization__test_offering2__1.1')
Ejemplo n.º 7
0
    def test_get_all_provider_offerings(self):
        user = User.objects.get(username='******')
        user_org = Organization.objects.get(name=user.username)

        for off in Offering.objects.all():
            off.owner_organization = user_org
            off.save()

        offerings = offerings_management.get_offerings(user, 'all', owned=True)
        self.assertEqual(len(offerings), 3)

        # Check published offering
        for off in offerings:
            if off['name'] == 'test_offering3':
                self.assertEqual(off['name'], 'test_offering3')
                self.assertEqual(off['version'], '1.0')
                self.assertEqual(off['state'], 'published')
                self.assertEqual(off['owner_organization'], 'test_user')
                self.assertEqual(off['owner_admin_user_id'], 'test_user')
                self.assertEqual(off['description_url'], 'http://testrepository/storeOfferingsCollection/test_organization__test_offering3__1.0')

                self.assertEqual(len(off['resources']), 1)
                resource = off['resources'][0]

                self.assertEqual(resource['name'], 'test_resource')
                self.assertEqual(resource['description'], 'Example resource')
Ejemplo n.º 8
0
    def test_basic_retrieving_pagination_purchased(self):

        pagination = {
            'skip': '1',
            'limit': '2'
        }
        user = User.objects.get(username='******')
        profile = UserProfile.objects.get(user=user)
        profile.offerings_purchased = ['11000aba8e05ac2115f022f9', '21000aba8e05ac2115f022ff', '31000aba8e05ac2115f022f0']
        org = Organization.objects.get(name='test_organization1')
        org.offerings_purchased = ['41000aba8e05ac2115f022f0', '51100aba8e05ac2115f022f0']
        org.save()
        profile.current_organization = org
        profile.organizations.append({
            'organization': org.pk,
            'roles': ['customer', 'provider']
        })
        profile.save()

        offerings = offerings_management.get_offerings(user, filter_='purchased', state=[], pagination=pagination, sort='name')

        self.assertEqual(len(offerings), 2)

        self.assertEqual(offerings[0]['name'], 'test_offering4')
        self.assertEqual(offerings[1]['name'], 'test_offering5')
Ejemplo n.º 9
0
    def test_basic_retrieving_pagination(self):

        pagination = {
            'skip': '1',
            'limit': '3'
        }

        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()
        offerings = offerings_management.get_offerings(user, filter_='all', owned=True, pagination=pagination)

        self.assertEqual(len(offerings), 3)

        self.assertEqual(offerings[0]['name'], 'test_offering1')
        self.assertEqual(offerings[1]['name'], 'test_offering2')
        self.assertEqual(offerings[2]['name'], 'test_offering3')

        pagination = {
            'skip': '4',
            'limit': '5'
        }

        offerings = offerings_management.get_offerings(user, filter_='all', owned=True, pagination=pagination)

        self.assertEqual(len(offerings), 5)

        self.assertEqual(offerings[0]['name'], 'test_offering4')
        self.assertEqual(offerings[1]['name'], 'test_offering5')
        self.assertEqual(offerings[2]['name'], 'test_offering6')
        self.assertEqual(offerings[3]['name'], 'test_offering7')
        self.assertEqual(offerings[4]['name'], 'test_offering8')
Ejemplo n.º 10
0
    def test_get_customer_purchased_offerings(self):

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

        offerings = offerings_management.get_offerings(user, 'purchased', owned=True)

        self.assertEqual(len(offerings), 2)
        for off in offerings:
            if off['name'] == 'test_offering1':
                self.assertEqual(off['name'], 'test_offering1')
                self.assertEqual(off['version'], '1.0')
                self.assertEqual(off['state'], 'purchased')
                self.assertEqual(off['owner_organization'], 'test_organization')
                self.assertEqual(off['owner_admin_user_id'], 'test_user')
                self.assertEqual(off['description_url'], 'http://testrepository/storeOfferingsCollection/test_organization__test_offering1__1.0')
                self.assertEqual(len(off['bill']), 1)
                self.assertEqual(off['bill'][0], '/media/bills/61005aba8e05ac2115f022f0.pdf')
                components = off['offering_description']['pricing']['price_plans'][0]['price_components']
                self.assertEqual(components[0]['title'], 'price component 1')
                self.assertEqual(components[0]['renovation_date'], '1990-02-05 17:06:46')
                self.assertEqual(components[1]['title'], 'price component 2')
                self.assertEqual(components[1]['renovation_date'], '1990-02-05 17:06:46')
            else:

                self.assertEqual(off['name'], 'test_offering2')
                self.assertEqual(off['version'], '1.1')
                self.assertEqual(off['state'], 'purchased')
                self.assertEqual(off['owner_organization'], 'test_organization')
                self.assertEqual(off['owner_admin_user_id'], 'test_user')
                self.assertEqual(off['description_url'], 'http://testrepository/storeOfferingsCollection/test_organization__test_offering2__1.1')
                self.assertEqual(len(off['bill']), 1)
                self.assertEqual(off['bill'][0], '/media/bills/61006aba8e05ac2115f022f0.pdf')
                components = off['offering_description']['pricing']['price_plans'][0]['price_components']
                self.assertEqual(components[0]['title'], 'price component 1')
                self.assertEqual(components[0]['renovation_date'], '1990-02-05 17:06:46')
                self.assertEqual(components[1]['title'], 'price component 2')
                self.assertEqual(components[1]['renovation_date'], '1990-02-05 17:06:46')
Ejemplo n.º 11
0
    def read(self, request):
        logger.debug("OfferingCollection.read()")
        try:
            # Read the query string in order to know the filter and the page
            filter_ = request.GET.get('filter', 'published')
            user = request.user
            action = request.GET.get('action', None)
            sort = request.GET.get('sort', None)

            # Check sorting values
            if sort != None:
                if sort != 'date' and sort != 'popularity' and sort != 'name':
                    return build_response(request, 400, 'Invalid sorting')

            pagination = {
                'skip': request.GET.get('start', None),
                'limit': request.GET.get('limit', None)
            }

            if action != 'count':
                if pagination['skip'] and pagination['limit']:
                    if filter_ == 'provided':
                        result = get_offerings(user, request.GET.get('state'), owned=True, pagination=pagination, sort=sort)

                    elif filter_ == 'published':
                        result = get_offerings(user, pagination=pagination, sort=sort)

                    elif filter_ == 'purchased':
                        result = get_offerings(user, 'purchased', owned=True, pagination=pagination, sort=sort)
                else:
                    if filter_ == 'provided':
                        result = get_offerings(user, request.GET.get('state'), owned=True, sort=sort)

                    elif filter_ == 'published':
                        result = get_offerings(user, sort=sort)

                    elif filter_ == 'purchased':
                        result = get_offerings(user, 'purchased', owned=True, sort=sort)

            else:
                if filter_ == 'provided':
                    result = count_offerings(user, request.GET.get('state'), owned=True)

                elif filter_ == 'published':
                    result = count_offerings(user)

                elif filter_ == 'purchased':
                    result = count_offerings(user, 'purchased', owned=True)

        except Exception as e:
            return build_response(request, 400, unicode(e))

        mime_type = 'application/JSON; charset=UTF-8'
        return HttpResponse(json.dumps(result), status=200, mimetype=mime_type)
Ejemplo n.º 12
0
    def read(self, request):
        try:
            # Read the query string in order to know the filter and the page
            filter_ = request.GET.get('filter', 'published')
            user = request.user
            action = request.GET.get('action', None)
            sort = request.GET.get('sort', None)

            state = request.GET.get('state', None)
            start = request.GET.get('start', None)
            limit = request.GET.get('limit', None)

            if state:
                if state == 'ALL':
                    state = ['uploaded', 'published', 'deleted']
                else:
                    state = state.split(',')

            # Check sorting values
            if sort is not None:
                if sort != 'date' and sort != 'popularity' and sort != 'name':
                    return build_response(request, 400, 'Invalid query string: Invalid sorting')

            # Build pagination
            pagination = None
            if start and limit:
                pagination = {
                    'skip': start,
                    'limit': limit
                }

            if action != 'count':
                result = get_offerings(user, filter_, state, pagination=pagination, sort=sort)
            else:
                result = count_offerings(user, filter_, state)

        except Exception as e:
            return build_response(request, 400, unicode(e))

        mime_type = 'application/JSON; charset=UTF-8'
        return HttpResponse(json.dumps(result), status=200, mimetype=mime_type)
Ejemplo n.º 13
0
    def test_retrieving_pagination_half_page(self):

        pagination = {
            'skip': '8',
            'limit': '10'
        }

        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()
        offerings = offerings_management.get_offerings(user, filter_='all', owned=True, pagination=pagination, sort='name')

        self.assertEqual(len(offerings), 3)

        self.assertEqual(offerings[0]['name'], 'test_offering7')
        self.assertEqual(offerings[1]['name'], 'test_offering8')
        self.assertEqual(offerings[2]['name'], 'test_offering9')
Ejemplo n.º 14
0
    def test_purchased_offerings_retrieving(self, name, filter_, states, expected_offerings):

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

        offerings = offerings_management.get_offerings(user, filter_, states)
        self.assertEqual(len(offerings), len(expected_offerings))

        validated = 0

        # Check offering content
        for exp, state in expected_offerings:
            off = Offering.objects.get(pk=exp)

            for off_info in offerings:
                if off.name == off_info['name']:
                    self.assertEqual(off_info['name'], off.name)
                    self.assertEqual(off_info['version'], off.version)
                    self.assertEqual(off_info['state'], state)
                    self.assertEqual(off_info['owner_organization'], off.owner_organization.name)
                    self.assertEqual(off_info['owner_admin_user_id'], off.owner_admin_user.username)
                    self.assertEqual(off_info['description_url'], off.description_url)

                    if len(off.resources):
                        self.assertEquals(len(off.resources), len(off_info['resources']))

                    validated = validated + 1

        self.assertEquals(validated, len(expected_offerings))
Ejemplo n.º 15
0
    def test_retrieving_pagination(self, name, pagination, expected_offerings, sort=None, err_type=None, err_msg=None):

        # Build user info
        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 = offerings_management.get_offerings(
                user, filter_="provided", state=["uploaded", "published", "deleted"], pagination=pagination, sort=sort
            )
        except Exception as e:
            error = e

        if not err_type:
            self.assertEquals(error, None)
            self._check_offerings(offerings, expected_offerings)
        else:
            self.assertTrue(isinstance(error, err_type))
            self.assertEquals(unicode(error), err_msg)
Ejemplo n.º 16
0
    def test_get_all_provider_offerings_org(self):
        user = User.objects.get(username='******')
        user_org = Organization.objects.get(name=user.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()

        off1 = Offering.objects.get(name='test_offering1')
        off1.owner_organization = user_org
        off1.save()

        off2 = Offering.objects.get(name='test_offering2')
        off2.owner_organization = user_org
        off2.save()

        offerings = offerings_management.get_offerings(user, 'all', owned=True)
        self.assertEqual(len(offerings), 1)

        # Check published offering
        self.assertEqual(offerings[0]['name'], 'test_offering3')
        self.assertEqual(offerings[0]['version'], '1.0')
        self.assertEqual(offerings[0]['state'], 'published')
        self.assertEqual(offerings[0]['owner_organization'], 'test_organization')
        self.assertEqual(offerings[0]['owner_admin_user_id'], 'test_user')
        self.assertEqual(offerings[0]['description_url'], 'http://testrepository/storeOfferingsCollection/test_organization__test_offering3__1.0')

        self.assertEqual(len(offerings[0]['resources']), 1)
        resource = offerings[0]['resources'][0]

        self.assertEqual(resource['name'], 'test_resource')
        self.assertEqual(resource['description'], 'Example resource')
Ejemplo n.º 17
0
    def test_purchased_offerings_retrieving(self, name, filter_, states, expected_offerings):

        user = User.objects.get(username="******")
        profile = UserProfile.objects.get(user=user)
        profile.offerings_purchased = ["11000aba8e05ac2115f022f9"]
        org = Organization.objects.get(name="test_organization1")
        org.offerings_purchased = ["21000aba8e05ac2115f022ff", "11000aba8e05ac2115f022f9"]
        org.save()
        profile.current_organization = org
        profile.organizations.append({"organization": org.pk, "roles": ["customer", "provider"]})
        profile.save()

        offerings = offerings_management.get_offerings(user, filter_, states)
        self.assertEqual(len(offerings), len(expected_offerings))

        validated = 0

        # Check offering content
        for exp, state in expected_offerings:
            off = Offering.objects.get(pk=exp)

            for off_info in offerings:
                if off.name == off_info["name"]:
                    self.assertEqual(off_info["name"], off.name)
                    self.assertEqual(off_info["version"], off.version)
                    self.assertEqual(off_info["state"], state)
                    self.assertEqual(off_info["owner_organization"], off.owner_organization.name)
                    self.assertEqual(off_info["owner_admin_user_id"], off.owner_admin_user.username)
                    self.assertEqual(off_info["description_url"], off.description_url)

                    if len(off.resources):
                        self.assertEquals(len(off.resources), len(off_info["resources"]))

                    validated = validated + 1

        self.assertEquals(validated, len(expected_offerings))
Ejemplo n.º 18
0
    def test_retrieving_pagination(self, name, pagination, expected_offerings, sort=None, err_type=None, err_msg=None):

        # Build user info
        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 = offerings_management.get_offerings(user, filter_='provided', state=['uploaded', 'published', 'deleted'], pagination=pagination, sort=sort)
        except Exception as e:
            error = e

        if not err_type:
            self.assertEquals(error, None)
            self._check_offerings(offerings, expected_offerings)
        else:
            self.assertTrue(isinstance(error, err_type))
            self.assertEquals(unicode(error), err_msg)