コード例 #1
0
def example_data_origin(request, app, db):
    with app.app_context():
        print('\nSetting up origin example data for {} {}'.format(id(db), db))
        o1 = m.Origin(code='AT', name={'en': 'Austria', 'de': 'Oesterreich'})
        o2 = m.Origin(code='DE', name={'de': 'Deutschland'})
        o3 = m.Origin(code='GB', name={'en': 'Great Britain'})

        db.session.add_all([o1, o2, o3])
        db.session.commit()
コード例 #2
0
def test_origin_model(db):
    origin = m.Origin(name={'en': 'Indonesia'})

    db.session.add(origin)
    db.session.commit()

    assert origin.id > 0
コード例 #3
0
def test_score_model(db):
    resource = m.Resource(name={'en': 'pork fat'})
    origin = m.Origin(name={'en': 'austria'})
    supplier = m.Supplier(name='huber-bauer')
    supply_from_country = m.Supply(resource=resource, origin=origin)
    supply_from_supplier = m.Supply(resource=resource, supplier=supplier)
    hotspot = m.Hotspot(name={'en': 'animal rights'})
    country_score = m.Score(supply=supply_from_country,
                            hotspot=hotspot,
                            score=3,
                            explanation={'en': 'foo'})
    supplier_score = m.Score(supply=supply_from_supplier,
                             hotspot=hotspot,
                             score=3,
                             explanation={'en': 'foo'})

    db.session.add(country_score, supplier_score)
    db.session.commit()

    assert country_score.supply.resource == resource
    assert country_score.supply.origin == origin
    assert country_score.supply.supplier is None
    assert country_score.hotspot == hotspot
    assert country_score.score == 3
    assert resource.supplies[1].scores[0] == country_score

    assert supplier_score.supply.resource == resource
    assert supplier_score.supply.origin is None
    assert supplier_score.supply.supplier == supplier
    assert resource.supplies[0].scores[0] == supplier_score
コード例 #4
0
def example_data_scores(request, app, db):
    with app.app_context():
        print('\nSetting up score example data for {} {}'.format(id(db), db))
        hotspot = m.Hotspot(name={'en': 'Test Hotspot'})
        resource = m.Resource(name={'en': 'Test Resource'})
        origin = m.Origin(name={'en': 'Test Origin'})
        supplier = m.Supplier(name='Test Supplier')
        supply = m.Supply(resource=resource, origin=origin, supplier=supplier)
        supply2 = m.Supply(resource=resource, origin=origin, supplier=supplier)
        supply3 = m.Supply(resource=resource, origin=origin, supplier=supplier)
        score = m.Score(hotspot=hotspot,
                        supply=supply,
                        score=10,
                        explanation={'en': 'This explanation is in English.'})
        score2 = m.Score(
            hotspot=hotspot,
            supply=supply2,
            score=9,
            explanation={'de': 'Diese Erklaerung ist auf deutsch.'})
        score3 = m.Score(hotspot=hotspot,
                         supply=supply3,
                         score=100,
                         explanation={
                             'en': 'This explanation is multilingual!',
                             'de': 'Diese Erklaerung ist mehrsprachig!'
                         })

        db.session.add_all([score, score2, score3])
        db.session.commit()
コード例 #5
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
コード例 #6
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