Exemplo n.º 1
0
def example_data_label_guide(request, app, db):
    with app.app_context():
        print('\nSetting up example data for label guide use cases for {} {}'.
              format(id(db), db))

        l1 = m.Label(name={
            "en": "English and German",
            "de": "Englisch und Deutsch"
        },
                     description={
                         "en": "English description",
                         "de": "Deutsche Beschreibung"
                     },
                     logo={
                         'en': 'english_logo.png',
                         'de': 'german_logo.png'
                     })
        l2 = m.Label(name={"en": "English only"},
                     description={"en": "English description only"},
                     logo={'en': 'english_only_logo.png'})
        l3 = m.Label(name={"de": "Nur Deutsch"},
                     description={"de": "Nur eine deutsche Beschreibung"},
                     logo={'de': 'german_only_logo.png'})

        crit1 = m.Criterion(name={'en': 'Multilingual'})
        crit2 = m.Criterion(name={'en': 'Understandable'})
        crit3 = m.Criterion(name={'en': 'Ignorant'})

        l1_m_c1 = m.LabelMeetsCriterion(
            label=l1,
            criterion=crit1,
            explanation={
                "en": "The label is both English and German.",
                "de": "Das Label ist sowohl Deutsch, als auch Englisch."
            },
            score=100)
        l2_m_c2 = m.LabelMeetsCriterion(
            label=l2,
            criterion=crit2,
            explanation={
                "en":
                "The label is at least in English, so a lot of people will understand it."
            },
            score=50)
        l3_m_c3 = m.LabelMeetsCriterion(
            label=l3,
            criterion=crit3,
            explanation={"de": "Alles nur Deutsch."},
            score=100)

        l1.meets_criteria = [l1_m_c1]
        l2.meets_criteria = [l2_m_c2]
        l3.meets_criteria = [l3_m_c3]

        db.session.add_all([l1, l2, l3])
        db.session.commit()
Exemplo n.º 2
0
def test_retailer_model(db):
    retailer = m.Retailer(name='Rewe')
    m.Store(name='Billa', retailer=retailer)
    m.Store(name='Penny', retailer=retailer)
    m.Brand(name='Clever', retailer=retailer)
    m.Label(name={'en': 'BEPI'}, type='retailer', retailers=[retailer])

    criterion_1_assoc = m.RetailerMeetsCriterion(satisfied=False,
                                                 explanation='Nope.')
    criterion_1_assoc.criterion = m.Criterion(name={'en': 'Saves the world'},
                                              type='retailer')
    retailer.meets_criteria.append(criterion_1_assoc)

    criterion_2_assoc = m.RetailerMeetsCriterion(
        satisfied=True, explanation='At least a few of us...')
    criterion_2_assoc.criterion = m.Criterion(
        name={'en': 'Makes us all happy'}, type='retailer')
    retailer.meets_criteria.append(criterion_2_assoc)

    db.session.add(retailer)
    db.session.commit()

    assert retailer.id > 0
    assert len(retailer.stores) == 2
    assert len(retailer.brands) == 1
    assert len(retailer.meets_criteria) == 2
    assert len(retailer.labels) == 1
    assert retailer.name == 'Rewe'
    assert retailer.meets_criteria[0].satisfied is False
    assert retailer.meets_criteria[0].explanation == 'Nope.'
    assert retailer.meets_criteria[0].criterion.name['en'] == 'Saves the world'
    assert retailer.meets_criteria[0].criterion.type == 'retailer'
    assert retailer.labels[0].name['en'] == 'BEPI'
Exemplo n.º 3
0
def test_product_model(db):
    raw_palm_oil = m.Resource(name={'en': 'Palm oil'})
    palm_oil = m.Ingredient(
        resource=raw_palm_oil,
        percentage=90,
        weight=1,
    )
    raw_cocoa = m.Resource(name={'en': 'Cocoa'})
    peru = m.Origin(name={'en': 'Peru'})
    supplier = m.Supplier(name='Cocoa Trade Inc.')
    cocoa = m.Ingredient(
        resource=raw_cocoa,
        origin=peru,
        supplier=supplier,
        percentage=10,
        weight=2,
    )
    organic = m.Label(name={'en': 'EU organic'})
    billa = m.Store(name='Billa')
    brand = m.Brand(name='BestBio')
    producer = m.Producer(name='Raw Organic Cookie Factory')
    category = m.Category(name='Cookies')

    product = m.Product(name={'en': 'Raw organic vegan gluten-free cookies'},
                        gtin='99999999999999',
                        stores=[billa],
                        brand=brand,
                        producer=producer,
                        category=category,
                        details={
                            'en': {
                                'image': 'some url',
                                'weight': '300 g',
                                'price': '2,99',
                                'currency': 'Euro'
                            }
                        },
                        ingredients=[palm_oil, cocoa],
                        labels=[organic])

    db.session.add(product)
    db.session.commit()

    assert product.id > 0
    assert organic.products[0] == product
    assert raw_palm_oil.ingredients[0].product == product
    assert raw_cocoa.ingredients[
        0].product == product  # Read: Raw cocoa used as an ingredient
    assert raw_cocoa.ingredients[0].origin == peru
    assert raw_cocoa.ingredients[0].supplier == supplier
    assert raw_cocoa.ingredients[0].percentage == 10
    assert peru.ingredients[0].product == product  # Read: Ingredients from Peru
    assert supplier.ingredients[
        0].product == product  # Read: Ingredients from this supplier
    assert billa.products[0] == product
    assert brand.products[0] == product
    assert producer.products[0] == product
    assert category.products[0] == product
Exemplo n.º 4
0
def test_label_model_duplicate_name(db):
    label = m.Label(
        name={'en': 'A unique name'},
        description={'en': 'A cool label.'},
        logo={'en': 'some url'},
        countries=[m.LabelCountry(code='GB'),
                   m.LabelCountry(code='AT')])
    label2 = m.Label(
        name={'en': 'A unique name'},
        description={'en': 'A cool label.'},
        logo={'en': 'some url'},
        countries=[m.LabelCountry(code='GB'),
                   m.LabelCountry(code='AT')])

    db.session.add(label)
    db.session.add(label2)

    with raises(IntegrityError):
        db.session.commit()
Exemplo n.º 5
0
def test_label_model_no_name(db):
    label = m.Label(
        description={'en': 'A cool label.'},
        logo={'en': 'some url'},
        countries=[m.LabelCountry(code='GB'),
                   m.LabelCountry(code='AT')])

    db.session.add(label)

    with raises(IntegrityError):
        db.session.commit()
Exemplo n.º 6
0
def test_label_model(db):
    label = m.Label(
        name={
            'en': 'EU organic',
            'de': 'EU Bio'
        },
        description={
            'en': 'A cool label.',
            'de': 'Ein cooles Label'
        },
        logo={'en': 'some url'},
        countries=[m.LabelCountry(code='GB'),
                   m.LabelCountry(code='AT')])

    criterion_1_assoc = m.LabelMeetsCriterion(score=1,
                                              explanation={'en': 'Nope.'})
    criterion_1_assoc.criterion = m.Criterion(name={'en': 'Saves the world'})
    label.meets_criteria.append(criterion_1_assoc)

    criterion_2_assoc = m.LabelMeetsCriterion(
        score=2, explanation={'en': 'At least a few of us…'})
    criterion_2_assoc.criterion = m.Criterion(
        name={'en': 'Makes us all happy'})
    label.meets_criteria.append(criterion_2_assoc)

    resource_1 = m.Resource(name={'en': 'cocoa'})
    resource_2 = m.Resource(name={'en': 'palm oil'})
    label.resources = [resource_1, resource_2]

    product = m.Product(name={'en': 'Organic vegan gluten-free cookies'})
    label.products.append(product)

    db.session.add(label)
    db.session.commit()

    assert label.id > 0
    assert product.id > 0
    assert len(label.meets_criteria) == 2
    assert len(label.resources) == 2
    assert label.name['en'] == 'EU organic'
    assert label.name['de'] == 'EU Bio'
    assert label.products[0].name['en'] == 'Organic vegan gluten-free cookies'
    assert label.meets_criteria[0].score is 1
    assert label.meets_criteria[0].explanation['en'] == 'Nope.'
    assert label.meets_criteria[0].criterion.name['en'] == 'Saves the world'
    assert label.resources[0].name['en'] == 'cocoa'
    assert label.countries[0].code == 'AT'
    assert product.labels[0] == label
    assert resource_2.labels[0] == label
Exemplo n.º 7
0
def example_data_labels(request, app, db):
    with app.app_context():
        print('\nSetting up label example data for {} {}'.format(id(db), db))
        r1 = m.Resource(name={'en': 'Testresource #1'})
        r2 = m.Resource(name={'en': 'Testresource #2'})
        lbl_country = m.LabelCountry(code='TL')
        hotspot = m.Hotspot(
            name={'en': 'Quality Assurance'},
            description={
                'en':
                'To achieve a better world, we need good code.' +
                'And good code needs good QA.'
            })
        crit_hs = m.CriterionImprovesHotspot(
            weight=100,
            explanation={'en': 'What better QA than solid test data?'},
            hotspot=hotspot)
        crit = m.Criterion(type='label',
                           name={'en': 'The test improvement criterion'},
                           improves_hotspots=[crit_hs])
        crit_cat = m.CriterionCategory(name={'en': 'Test Data'},
                                       criteria=[crit])
        lbl = m.Label(
            name={'en': 'Testlabel'},
            type='product',
            description={'en': 'For exceptional testing.'},
            logo={
                'en': 'beautiful_logo.png',
                'de': 'horrible_logo.png'
            },
            resources=[r1, r2],
            countries=[lbl_country],
        )
        lbl_criterion = m.LabelMeetsCriterion(
            label=lbl,
            criterion=crit,
            score=100,
            explanation={
                'en': 'Does the label improve testing for all of us?'
            })

        db.session.add(lbl)
        db.session.add(lbl_criterion)
        db.session.add(crit_cat)
        db.session.commit()
Exemplo n.º 8
0
def test_resource_model(db):
    resource = m.Resource(name={'en': 'Cocoa'})
    origin = m.Origin(name={'en': 'Ghana'})
    label = m.Label(name={'en': 'Fairtrade'})
    supplier = m.Supplier(name='XY')
    product = m.Product(name={'en': 'Chocolate'}, labels=[label])
    ingredient = m.Ingredient(
        resource=resource,
        supplier=supplier,
        origin=origin,
        product=product,
        weight=1,
    )
    supply = m.Supply(resource=resource, supplier=supplier)

    resource.ingredients.append(ingredient)
    resource.supplies.append(supply)
    resource.labels.append(label)

    db.session.add(resource)
    db.session.commit()

    assert resource.id > 0
    assert resource.name['en'] == 'Cocoa'
    assert resource.labels[0] == label
    assert product.labels[0] in resource.labels
    assert resource.ingredients[
        0].origin == origin  # Read: Resource used as an ingredient
    assert resource.ingredients[0].supplier == supplier
    assert resource.supplies[0].supplier == supplier
    assert origin.ingredients[
        0].resource == resource  # Read: Ingredients from this origin
    assert product.ingredients[0].resource == resource
    assert supplier.ingredients[
        0].resource == resource  # Read: Ingredients from this supplier
    assert supplier.supplies[
        0].resource == resource  # Read: Supplies from this supplier