Exemplo n.º 1
0
def test_record_pids(app, db, lang_type, lic_type):
    """Test record pid creation."""
    record = Vocabulary.create(
        {
            'id': 'eng',
            'title': {
                'en': 'English',
                'da': 'Engelsk'
            }
        },
        type=lang_type)
    Vocabulary.pid.create(record)
    assert record.type == lang_type
    assert record.pid.pid_value == 'eng'
    assert record.pid.pid_type == 'lng'
    assert Vocabulary.pid.resolve(('languages', 'eng'))

    record = Vocabulary.create(
        {
            'id': 'cc-by',
            'title': {
                'en': 'CC-BY',
                'da': 'CC-BY'
            }
        },
        type=lic_type)
    Vocabulary.pid.create(record)
    assert record.type == lic_type
    assert record.pid.pid_value == 'cc-by'
    assert record.pid.pid_type == 'lic'
    assert Vocabulary.pid.resolve(('licenses', 'cc-by'))
Exemplo n.º 2
0
def example_record(db, example_data, lang_type):
    """Example record."""
    record = Vocabulary.create(example_data, type=lang_type)
    Vocabulary.pid.create(record)
    record.commit()
    db.session.commit()
    return record
Exemplo n.º 3
0
def test_vocabulary_type(app, db):
    """Vocabulary creation."""
    vocabulary_type = VocabularyType(**{"name": "test-type"})
    db.session.add(vocabulary_type)
    db.session.commit()
    record = Vocabulary.create({},
                               metadata={
                                   "title": "test-item",
                                   "type": "test-type"
                               })
    assert record.metadata == {"title": "test-item", "type": "test-type"}
Exemplo n.º 4
0
def test_record_empty(app, db):
    """Test record creation."""
    # Empty record creation works, and injects a schema.
    record = Vocabulary.create({})
    db.session.commit()
    assert record.schema

    # JSONSchema validation works.
    pytest.raises(SchemaValidationError, Vocabulary.create,
                  {"metadata": {
                      "title": 1
                  }})
Exemplo n.º 5
0
def test_vocabulary_type(app, db):
    """Vocabulary creation."""
    vocabulary_type = VocabularyType(**{"name": "test-type"})
    db.session.add(vocabulary_type)
    db.session.commit()
    record = Vocabulary.create({},
                               metadata={
                                   "title": {
                                       "en": "test-item"
                                   },
                                   "type": "test-type"
                               })
    record.commit()
    db.session.commit()
    assert record.metadata == {
        "title": {
            "en": "test-item"
        },
        "type": "test-type",
    }
    assert record.pid.status == "R"
    assert record.id
Exemplo n.º 6
0
def test_record_schema_validation(app, db, lang_type):
    """Record schema validation."""
    # Good data
    record = Vocabulary.create(
        {
            'id': 'eng',
            'title': {
                'en': 'English',
                'da': 'Engelsk'
            },
            'description': {
                'en': 'English',
                'da': 'Engelsk'
            },
            'icon': 'en',
            'props': {
                'akey': 'a value'
            },
        },
        type=lang_type)
    assert record.schema

    # Bad data
    examples = [
        # title/descriptions are objects of key/string.
        {
            'id': 'en',
            'title': 'not a string'
        },
        {
            'id': 'en',
            'title': {
                'en': 123
            }
        },
        {
            'id': 'en',
            'description': 'not a string'
        },
        # icon must be strings
        {
            'id': 'en',
            'icon': 123
        },
        # props values must be strings
        {
            'id': 'en',
            'props': {
                'key': 123
            }
        },
        {
            'id': 'en',
            'props': {
                'key': {
                    'test': 'test'
                }
            }
        },
        # Additional properties false
        {
            'id': 'en',
            'metadata': {
                'title': 'test'
            }
        },
    ]

    for ex in examples:
        pytest.raises(SchemaValidationError, Vocabulary.create, ex)
Exemplo n.º 7
0
def test_record_via_field(app, db):
    """Record creation via field."""
    record = Vocabulary.create({}, metadata={"title": "test"})
    assert record.metadata == {"title": "test"}