def test_criterion_model(db): criterion = m.Criterion(name={'en': 'Saves the world'}) criterion.details = { 'en': { 'question': 'Does the certificate/label save the world?', 'response_options': '0 - no, 1 - partly, 2 - totally!', 'explanation': '2 applies only if it really saves the world.', 'possible_scores': [-1, 0, 1, 2] # -1 means not applicable } } hotspot_assoc = m.CriterionImprovesHotspot(weight=2, explanation={'en': 'Obvious.'}) hotspot_assoc.hotspot = m.Hotspot(name={'en': 'Saving the world'}) criterion.improves_hotspots.append(hotspot_assoc) db.session.add(criterion) db.session.commit() assert criterion.id > 0 assert criterion.details['en']['possible_scores'][0] == -1 assert len(criterion.improves_hotspots) == 1 assert criterion.improves_hotspots[0].weight == 2 assert criterion.improves_hotspots[0].explanation['en'] == 'Obvious.' assert criterion.improves_hotspots[0].hotspot.name[ 'en'] == 'Saving the world'
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
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()
def test_hotspot_model(db): hotspot = m.Hotspot(name={'en': 'Saving the world'}, description={'en': 'Today’s agenda'}) db.session.add(hotspot) db.session.commit() assert hotspot.id > 0
def example_data_hotspots(request, app, db): with app.app_context(): print('\nSetting up hotspot example data for {} {}'.format(id(db), db)) h1 = m.Hotspot(name={ 'en': 'Multilingual hotspot', 'de': 'Mehrsprachiger hotspot' }, description={ 'en': 'This hotspot speaks 2 languages', 'de': 'Dieser hotspot spricht 2 sprachen' }) h2 = m.Hotspot(name={'en': 'English hotspot'}, description={'en': 'This hotspot speaks English'}) h3 = m.Hotspot(name={'de': 'Deutscher hotspot'}, description={'de': 'Dieser hotspot spricht deutsch'}) db.session.add_all([h1, h2, h3]) db.session.commit()
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()