Пример #1
0
    def test_basic_offering_update(self):
        data = {
            'offering_description': {
                'content_type': 'application/rdf+xml',
                'data': self._usdl
            }
        }
        offering = Offering.objects.get(pk="61000aba8e15ac2115f022f9")

        offerings_management.update_offering(offering, data)

        offering = Offering.objects.get(pk="61000aba8e15ac2115f022f9")
        usdl = offering.offering_description

        parser = USDLParser(json.dumps(usdl), 'application/json')

        usdl_content = parser.parse()

        self.assertEqual(len(usdl_content['services_included']), 1)
        service = usdl_content['services_included'][0]

        self.assertEqual(service['name'], 'Map viewer')
        self.assertEqual(service['vendor'], 'CoNWeT')

        self.assertEqual(usdl_content['pricing']['title'], 'Map viewer free use')
        self.assertEqual(len(usdl_content['pricing']['price_plans']), 1)

        plan = usdl_content['pricing']['price_plans'][0]
        self.assertEqual(plan['title'], 'Free use')
Пример #2
0
    def test_offering_update_from_url(self):

        data = {
            'description_url':  "http://examplerep/v1/test_usdl"
        }
        offering = Offering.objects.get(pk="61000aba8e15ac2115f022f9")

        offerings_management.update_offering(offering, data)

        offering = Offering.objects.get(pk="61000aba8e15ac2115f022f9")
        usdl = offering.offering_description

        parser = USDLParser(json.dumps(usdl), 'application/json')

        usdl_content = parser.parse()

        self.assertEqual(len(usdl_content['services_included']), 1)
        service = usdl_content['services_included'][0]

        self.assertEqual(service['name'], 'Map viewer')
        self.assertEqual(service['vendor'], 'CoNWeT')

        self.assertEqual(usdl_content['pricing']['title'], 'Map viewer free use')
        self.assertEqual(len(usdl_content['pricing']['price_plans']), 1)

        plan = usdl_content['pricing']['price_plans'][0]
        self.assertEqual(plan['title'], 'Free use')
Пример #3
0
    def test_parse_no_services(self):

        f = open('./wstore/store_commons/test/error_usdl2.ttl', 'rb')

        parser = USDLParser(f.read(), 'text/turtle')
        f.close()

        error = False
        msg = None
        try:
            parser.parse()
        except Exception, e:
            error = True
            msg = e.message
Пример #4
0
    def test_parse_no_services(self):

        f = open('./wstore/store_commons/test/error_usdl2.ttl', 'rb')

        parser = USDLParser(f.read(), 'text/turtle')
        f.close()

        error = False
        msg = None
        try:
            parser.parse()
        except Exception, e:
            error = True
            msg = e.message
Пример #5
0
    def test_basic_parse(self):

        f = open('./wstore/store_commons/test/basic_usdl.ttl', 'rb')

        parser = USDLParser(f.read(), 'text/turtle')
        f.close()

        parsed_info = parser.parse()

        self.assertEqual(parsed_info['pricing']['title'], 'test offering')
        self.assertEqual(len(parsed_info['services_included']), 1)
        self.assertEqual(parsed_info['services_included'][0]['name'], 'example service')
        self.assertEqual(parsed_info['services_included'][0]['short_description'], 'Short description')
        self.assertEqual(parsed_info['services_included'][0]['long_description'], 'Long description')
        self.assertEqual(parsed_info['services_included'][0]['version'], '1.0')
Пример #6
0
    def test_basic_parse(self):

        f = open('./wstore/store_commons/test/basic_usdl.ttl', 'rb')

        parser = USDLParser(f.read(), 'text/turtle')
        f.close()

        parsed_info = parser.parse()

        self.assertEqual(parsed_info['pricing']['title'], 'test offering')
        self.assertEqual(len(parsed_info['services_included']), 1)
        self.assertEqual(parsed_info['services_included'][0]['name'], 'example service')
        self.assertEqual(parsed_info['services_included'][0]['short_description'], 'Short description')
        self.assertEqual(parsed_info['services_included'][0]['long_description'], 'Long description')
        self.assertEqual(parsed_info['services_included'][0]['version'], '1.0')
Пример #7
0
    def test_parse_complete_offering(self):

        f = open('./wstore/store_commons/test/test_usdl1.ttl', 'rb')

        parser = USDLParser(f.read(), 'text/turtle')
        f.close()

        parsed_info = parser.parse()

        self.assertEqual(parsed_info['pricing']['title'], 'test offering')
        self.assertEqual(len(parsed_info['services_included']), 1)
        self.assertEqual(parsed_info['services_included'][0]['name'], 'example service')
        self.assertEqual(parsed_info['services_included'][0]['short_description'], 'Short description')
        self.assertEqual(parsed_info['services_included'][0]['long_description'], 'Long description')
        self.assertEqual(parsed_info['services_included'][0]['version'], '1.0')

        self.assertEqual(len(parsed_info['pricing']['price_plans']), 1)
        price_plan = parsed_info['pricing']['price_plans'][0]

        self.assertEqual(price_plan['title'], 'Example price plan')
        self.assertEqual(price_plan['description'], 'Price plan description')

        self.assertEqual(len(price_plan['price_components']), 2)

        for price_com in price_plan['price_components']:

            if price_com['title'] == 'Price component 1':
                self.assertEqual(price_com['title'], 'Price component 1')
                self.assertEqual(price_com['description'], 'price component 1 description')
                self.assertEqual(price_com['value'], '1.0')
                self.assertEqual(price_com['currency'], 'euros')
                self.assertEqual(price_com['unit'], 'single pay')
            else:
                self.assertEqual(price_com['title'], 'Price component 2')
                self.assertEqual(price_com['description'], 'price component 2 description')
                self.assertEqual(price_com['value'], '1.0')
                self.assertEqual(price_com['currency'], 'euros')
                self.assertEqual(price_com['unit'], 'single pay')

        self.assertEqual(len(price_plan['taxes']), 1)
        self.assertEqual(price_plan['taxes'][0]['title'], 'Example tax')
        self.assertEqual(price_plan['taxes'][0]['description'], 'example tax description')
        self.assertEqual(price_plan['taxes'][0]['value'], '1.0')
        self.assertEqual(price_plan['taxes'][0]['currency'], 'euros')
        self.assertEqual(price_plan['taxes'][0]['unit'], 'percent')
Пример #8
0
    def test_parse_complete_offering(self):

        f = open('./wstore/store_commons/test/test_usdl1.ttl', 'rb')

        parser = USDLParser(f.read(), 'text/turtle')
        f.close()

        parsed_info = parser.parse()

        self.assertEqual(parsed_info['pricing']['title'], 'test offering')
        self.assertEqual(len(parsed_info['services_included']), 1)
        self.assertEqual(parsed_info['services_included'][0]['name'], 'example service')
        self.assertEqual(parsed_info['services_included'][0]['short_description'], 'Short description')
        self.assertEqual(parsed_info['services_included'][0]['long_description'], 'Long description')
        self.assertEqual(parsed_info['services_included'][0]['version'], '1.0')

        self.assertEqual(len(parsed_info['pricing']['price_plans']), 1)
        price_plan = parsed_info['pricing']['price_plans'][0]

        self.assertEqual(price_plan['title'], 'Example price plan')
        self.assertEqual(price_plan['description'], 'Price plan description')

        self.assertEqual(len(price_plan['price_components']), 2)

        for price_com in price_plan['price_components']:

            if price_com['title'] == 'Price component 1':
                self.assertEqual(price_com['title'], 'Price component 1')
                self.assertEqual(price_com['description'], 'price component 1 description')
                self.assertEqual(price_com['value'], '1.0')
                self.assertEqual(price_com['currency'], 'euros')
                self.assertEqual(price_com['unit'], 'single pay')
            else:
                self.assertEqual(price_com['title'], 'Price component 2')
                self.assertEqual(price_com['description'], 'price component 2 description')
                self.assertEqual(price_com['value'], '1.0')
                self.assertEqual(price_com['currency'], 'euros')
                self.assertEqual(price_com['unit'], 'single pay')

        self.assertEqual(len(price_plan['taxes']), 1)
        self.assertEqual(price_plan['taxes'][0]['title'], 'Example tax')
        self.assertEqual(price_plan['taxes'][0]['description'], 'example tax description')
        self.assertEqual(price_plan['taxes'][0]['value'], '1.0')
        self.assertEqual(price_plan['taxes'][0]['currency'], 'euros')
        self.assertEqual(price_plan['taxes'][0]['unit'], 'percent')
Пример #9
0
    def test_parse_interaction_protocols(self):

        f = open('./wstore/store_commons/test/test_usdl4.ttl', 'rb')

        parser = USDLParser(f.read(), 'text/turtle')
        f.close()

        parsed_info = parser.parse()

        self.assertEqual(parsed_info['pricing']['title'], 'test offering')
        self.assertEqual(len(parsed_info['services_included']), 1)
        self.assertEqual(parsed_info['services_included'][0]['name'], 'Example service')
        self.assertEqual(parsed_info['services_included'][0]['short_description'], 'Short description')
        self.assertEqual(parsed_info['services_included'][0]['long_description'], 'Long description')

        interactions = parsed_info['services_included'][0]['interactions']

        self.assertEqual(len(interactions), 1)
        self.assertEqual(interactions[0]['title'], 'test protocol')
        self.assertEqual(interactions[0]['description'], 'test protocol description')
        self.assertEqual(interactions[0]['technical_interface'], 'http://technicalinterface.com')

        inter = interactions[0]['interactions']

        self.assertEqual(len(inter), 1)
        self.assertEqual(inter[0]['title'], 'test interaction')
        self.assertEqual(inter[0]['description'], 'test interaction description')
        self.assertEqual(inter[0]['interface_operation'], 'http://interfaceoperation.com')

        inputs = inter[0]['inputs']

        self.assertEqual(len(inputs), 1)
        self.assertEqual(inputs[0]['label'], 'test input')
        self.assertEqual(inputs[0]['description'], 'test input description')
        self.assertEqual(inputs[0]['interface_element'], 'http://interfaceelementinput.com')

        outputs = inter[0]['outputs']

        self.assertEqual(len(outputs), 1)
        self.assertEqual(outputs[0]['label'], 'test output')
        self.assertEqual(outputs[0]['description'], 'test output description')
        self.assertEqual(outputs[0]['interface_element'], 'http://interfaceelementoutput.com')
Пример #10
0
    def test_parse_interaction_protocols(self):

        f = open('./wstore/store_commons/test/test_usdl4.ttl', 'rb')

        parser = USDLParser(f.read(), 'text/turtle')
        f.close()

        parsed_info = parser.parse()

        self.assertEqual(parsed_info['pricing']['title'], 'test offering')
        self.assertEqual(len(parsed_info['services_included']), 1)
        self.assertEqual(parsed_info['services_included'][0]['name'], 'Example service')
        self.assertEqual(parsed_info['services_included'][0]['short_description'], 'Short description')
        self.assertEqual(parsed_info['services_included'][0]['long_description'], 'Long description')

        interactions = parsed_info['services_included'][0]['interactions']

        self.assertEqual(len(interactions), 1)
        self.assertEqual(interactions[0]['title'], 'test protocol')
        self.assertEqual(interactions[0]['description'], 'test protocol description')
        self.assertEqual(interactions[0]['technical_interface'], 'http://technicalinterface.com')

        inter = interactions[0]['interactions']

        self.assertEqual(len(inter), 1)
        self.assertEqual(inter[0]['title'], 'test interaction')
        self.assertEqual(inter[0]['description'], 'test interaction description')
        self.assertEqual(inter[0]['interface_operation'], 'http://interfaceoperation.com')

        inputs = inter[0]['inputs']

        self.assertEqual(len(inputs), 1)
        self.assertEqual(inputs[0]['label'], 'test input')
        self.assertEqual(inputs[0]['description'], 'test input description')
        self.assertEqual(inputs[0]['interface_element'], 'http://interfaceelementinput.com')

        outputs = inter[0]['outputs']

        self.assertEqual(len(outputs), 1)
        self.assertEqual(outputs[0]['label'], 'test output')
        self.assertEqual(outputs[0]['description'], 'test output description')
        self.assertEqual(outputs[0]['interface_element'], 'http://interfaceelementoutput.com')
Пример #11
0
    def test_parse_complete_service(self):

        f = open('./wstore/store_commons/test/test_usdl2.ttl', 'rb')

        parser = USDLParser(f.read(), 'text/turtle')
        f.close()

        parsed_info = parser.parse()

        self.assertEqual(parsed_info['pricing']['title'], 'test offering')
        self.assertEqual(len(parsed_info['services_included']), 1)
        self.assertEqual(parsed_info['services_included'][0]['name'], 'example service')
        self.assertEqual(parsed_info['services_included'][0]['short_description'], 'Short description')
        self.assertEqual(parsed_info['services_included'][0]['long_description'], 'Long description')
        self.assertEqual(parsed_info['services_included'][0]['version'], '1.0')

        legal = parsed_info['services_included'][0]['legal']
        self.assertEqual(len(legal), 1)
        self.assertEqual(legal[0]['label'], 'example legal')
        self.assertEqual(legal[0]['description'], 'example legal description')

        self.assertEqual(len(legal[0]['clauses']), 2)

        for clause in legal[0]['clauses']:

            if clause['name'] == 'example clause 1':
                self.assertEqual(clause['name'], 'example clause 1')
                self.assertEqual(clause['text'], 'example text 1')
            else:
                self.assertEqual(clause['name'], 'example clause 2')
                self.assertEqual(clause['text'], 'example text 2')

        sla = parsed_info['services_included'][0]['sla']
        self.assertEqual(len(sla), 1)
        self.assertEqual(sla[0]['name'], 'example service level')
        self.assertEqual(len(sla[0]['slaExpresions']), 1)
        self.assertEqual(sla[0]['slaExpresions'][0]['description'], 'example service level description')
        variables = sla[0]['slaExpresions'][0]['variables']
        self.assertEqual(len(variables), 1)
        self.assertEqual(variables[0]['label'], 'Example variable')
        self.assertEqual(variables[0]['value'], 'example value')
        self.assertEqual(variables[0]['unit'], 'example unit')
Пример #12
0
    def test_parse_complete_service(self):

        f = open('./wstore/store_commons/test/test_usdl2.ttl', 'rb')

        parser = USDLParser(f.read(), 'text/turtle')
        f.close()

        parsed_info = parser.parse()

        self.assertEqual(parsed_info['pricing']['title'], 'test offering')
        self.assertEqual(len(parsed_info['services_included']), 1)
        self.assertEqual(parsed_info['services_included'][0]['name'], 'example service')
        self.assertEqual(parsed_info['services_included'][0]['short_description'], 'Short description')
        self.assertEqual(parsed_info['services_included'][0]['long_description'], 'Long description')
        self.assertEqual(parsed_info['services_included'][0]['version'], '1.0')

        legal = parsed_info['services_included'][0]['legal']
        self.assertEqual(len(legal), 1)
        self.assertEqual(legal[0]['label'], 'example legal')
        self.assertEqual(legal[0]['description'], 'example legal description')

        self.assertEqual(len(legal[0]['clauses']), 2)

        for clause in legal[0]['clauses']:

            if clause['name'] == 'example clause 1':
                self.assertEqual(clause['name'], 'example clause 1')
                self.assertEqual(clause['text'], 'example text 1')
            else:
                self.assertEqual(clause['name'], 'example clause 2')
                self.assertEqual(clause['text'], 'example text 2')

        sla = parsed_info['services_included'][0]['sla']
        self.assertEqual(len(sla), 1)
        self.assertEqual(sla[0]['name'], 'example service level')
        self.assertEqual(len(sla[0]['slaExpresions']), 1)
        self.assertEqual(sla[0]['slaExpresions'][0]['description'], 'example service level description')
        variables = sla[0]['slaExpresions'][0]['variables']
        self.assertEqual(len(variables), 1)
        self.assertEqual(variables[0]['label'], 'Example variable')
        self.assertEqual(variables[0]['value'], 'example value')
        self.assertEqual(variables[0]['unit'], 'example unit')
Пример #13
0
    def test_parse_invalid_format(self):

        f = open('./wstore/store_commons/test/basic_usdl.ttl', 'rb')

        error = False
        msg = None
        try:
            parser = USDLParser(f.read(), 'text/fail')
        except Exception, e:
            error = True
            msg = e.message
Пример #14
0
    def test_parse_no_offering(self):

        f = open('./wstore/store_commons/test/error_usdl1.ttl', 'rb')

        error = False
        msg = None
        try:
            parser = USDLParser(f.read(), 'text/turtle')
        except Exception, e:
            error = True
            msg = e.message
Пример #15
0
    def test_parse_some_services(self):

        f = open('./wstore/store_commons/test/test_usdl3.ttl', 'rb')

        parser = USDLParser(f.read(), 'text/turtle')
        f.close()
        parsed_info = parser.parse()

        self.assertEqual(parsed_info['pricing']['title'], 'test offering')
        self.assertEqual(len(parsed_info['services_included']), 2)

        for serv in parsed_info['services_included']:

            if serv['name'] == 'Example service 1':
                self.assertEqual(serv['name'], 'Example service 1')
                self.assertEqual(serv['short_description'], 'Short description 1')
                self.assertEqual(serv['long_description'], 'Long description 1')
                self.assertEqual(serv['version'], '1.0')
            else:
                self.assertEqual(serv['name'], 'Example service 2')
                self.assertEqual(serv['short_description'], 'Short description 2')
                self.assertEqual(serv['long_description'], 'Long description 2')
                self.assertEqual(serv['version'], '1.0')
Пример #16
0
    def test_parse_some_services(self):

        f = open('./wstore/store_commons/test/test_usdl3.ttl', 'rb')

        parser = USDLParser(f.read(), 'text/turtle')
        f.close()
        parsed_info = parser.parse()

        self.assertEqual(parsed_info['pricing']['title'], 'test offering')
        self.assertEqual(len(parsed_info['services_included']), 2)

        for serv in parsed_info['services_included']:

            if serv['name'] == 'Example service 1':
                self.assertEqual(serv['name'], 'Example service 1')
                self.assertEqual(serv['short_description'], 'Short description 1')
                self.assertEqual(serv['long_description'], 'Long description 1')
                self.assertEqual(serv['version'], '1.0')
            else:
                self.assertEqual(serv['name'], 'Example service 2')
                self.assertEqual(serv['short_description'], 'Short description 2')
                self.assertEqual(serv['long_description'], 'Long description 2')
                self.assertEqual(serv['version'], '1.0')
Пример #17
0
def get_offering_info(offering, user):

    user_profile = UserProfile.objects.get(user=user)

    # Check if the user has purchased the offering
    state = offering.state

    # Check if the current organization is the user organization
    if user_profile.is_user_org():

        if offering.pk in user_profile.offerings_purchased:
            state = 'purchased'
            purchase = Purchase.objects.get(offering=offering, customer=user, organization_owned=False)

        if offering.pk in user_profile.rated_offerings:
            state = 'rated'

    else:
        if offering.pk in user_profile.current_organization.offerings_purchased:
            state = 'purchased'
            purchase = Purchase.objects.get(offering=offering, owner_organization=user_profile.current_organization)

        if user_profile.current_organization.has_rated_offering(user, offering):
            state = 'rated'

    # Load offering data
    result = {
        'name': offering.name,
        'owner_organization': offering.owner_organization.name,
        'owner_admin_user_id': offering.owner_admin_user.username,
        'version': offering.version,
        'state': state,
        'description_url': offering.description_url,
        'rating': "{:.2f}".format(offering.rating),
        'comments': offering.comments,
        'tags': offering.tags,
        'image_url': offering.image_url,
        'related_images': offering.related_images,
        'creation_date': str(offering.creation_date),
        'publication_date': str(offering.publication_date),
        'open': offering.open,
        'resources': []
    }

    # Load resources
    for res in offering.resources:
        resource = Resource.objects.get(pk=res)
        res_info = {
            'name': resource.name,
            'version': resource.version,
            'description': resource.description,
            'content_type': resource.content_type,
            'open': resource.open
        }

        if (state == 'purchased' or state == 'rated' or offering.open):
            if resource.resource_path != '':
                res_info['link'] = resource.resource_path
            elif resource.download_link != '':
                res_info['link'] = resource.download_link

        result['resources'].append(res_info)

    if settings.OILAUTH:
        result['applications'] = offering.applications

    # Load applications
    # Load offering description
    parser = USDLParser(json.dumps(offering.offering_description), 'application/json')
    result['offering_description'] = parser.parse()

    if not offering.open and (state == 'purchased' or state == 'rated'):
        result['bill'] = purchase.bill

        # If the offering has been purchased the parsed pricing model is replaced
        # With the pricing model of the contract in order to included the extra info
        # needed such as renovation dates etc.

        pricing_model = purchase.contract.pricing_model

        if 'subscription' in pricing_model:
            result['offering_description']['pricing']['price_plans'][0]['price_components'] = []
            # Cast renovation date to string in order to avoid serialization problems

            for subs in pricing_model['subscription']:
                subs['renovation_date'] = str(subs['renovation_date'])
                result['offering_description']['pricing']['price_plans'][0]['price_components'].append(subs)

            if 'single_payment' in pricing_model:
                result['offering_description']['pricing']['price_plans'][0]['price_components'].extend(pricing_model['single_payment'])

            if 'pay_per_use' in pricing_model:
                result['offering_description']['pricing']['price_plans'][0]['price_components'].extend(pricing_model['pay_per_use'])

    return result
Пример #18
0
    def _create_purchase_contract(self):
        # Generate the pricing model structure
        offering = self._purchase.offering
        parser = USDLParser(json.dumps(offering.offering_description), 'application/json')
        parsed_usdl = parser.parse()

        usdl_pricing = {}
        # Search and validate the corresponding price plan
        if len(parsed_usdl['pricing']['price_plans']) > 0:
            if len(parsed_usdl['pricing']['price_plans']) == 1:
                usdl_pricing = parsed_usdl['pricing']['price_plans'][0]
            else:
                # A plan must have been specified
                if not self._plan:
                    raise Exception('The price plan label is required to identify the plan')

                # Search the plan
                found = False
                for plan in parsed_usdl['pricing']['price_plans']:
                    if plan['label'].lower() == self._plan.lower():
                        usdl_pricing = plan
                        found = True
                        break

                # Validate the specified plan
                if not found:
                    raise Exception('The specified plan does not exist')

        price_model = {}

        currency_loaded = False
        if 'price_components' in usdl_pricing:

            for comp in usdl_pricing['price_components']:

                # Check if the price component defines a price function
                if 'price_function' in comp:
                    # Price functions always define pay-per-use models
                    if not 'pay_per_use' in price_model:
                        price_model['pay_per_use'] = []

                    price_model['pay_per_use'].append(comp)
                    continue

                # Check price component unit
                try:
                    unit = Unit.objects.get(name=comp['unit'])
                except:
                    raise(Exception, 'Unsupported unit in price plan model')

                # The price component defines a single payment
                if unit.defined_model == 'single payment':
                    if not 'single_payment' in price_model:
                        price_model['single_payment'] = []

                    price_model['single_payment'].append(comp)

                # The price component defines a subscription
                elif unit.defined_model == 'subscription':
                    if not 'subscription' in price_model:
                        price_model['subscription'] = []

                    price_model['subscription'].append(comp)

                # The price component defines a pay per use
                elif unit.defined_model == 'pay per use':
                    if not 'pay_per_use' in price_model:
                        price_model['pay_per_use'] = []

                    price_model['pay_per_use'].append(comp)

                # Save the general currency of the offering
                if not currency_loaded:
                    price_model['general_currency'] = comp['currency']
                    currency_loaded = True

        if 'deductions' in usdl_pricing:

            for deduct in usdl_pricing['deductions']:

                if not 'deductions' in price_model:
                    price_model['deductions'] = []

                if not 'price_function' in deduct:
                    unit = Unit.objects.get(name=deduct['unit'])

                    # Deductions only can define use based discounts
                    if unit.defined_model != 'pay per use':
                        raise Exception('Invalid deduction')

                    if not currency_loaded:
                        price_model['general_currency'] = deduct['currency']
                        currency_loaded = True

                price_model['deductions'].append(deduct)

        # If not price components or all price components define a
        # function without currency, load default currency
        if not 'general_currency' in price_model:
            cnt = WStore_context.objects.all()[0]
            price_model['general_currency'] = cnt.allowed_currencies['default']

        # Create the contract entry
        Contract.objects.create(
            pricing_model=price_model,
            charges=[],
            applied_sdrs=[],
            purchase=self._purchase
        )
        self._price_model = price_model