예제 #1
0
def test_communities_load(db, communities_dump, featured_dump, logos_dir):
    """Load the communities JSON dump."""
    # Create a single user (with id=1) to meet the community's FK constraint.
    create_test_user('*****@*****.**', password='******')

    # Initialize communities bucket (requires a default Location)
    loc = Location(name='local', uri='file:///tmp', default=True)
    db.session.add(loc)
    db.session.commit()
    initialize_communities_bucket()

    # Load the communities
    for data in communities_dump:
        load_community.delay(data, logos_dir)

    # Check if community was loaded correctly
    assert Community.query.count() == 1
    c = Community.query.first()
    assert c.title == 'Invenio Community'
    assert c.id == 'invenio'

    # Check object metadata
    assert ObjectVersion.query.count() == 1  # Check if the logo was created
    assert ObjectVersion.query.first().key == 'invenio/logo.jpg'

    # Open the original logo from test data and check if checksums match
    with open(join(logos_dir, 'invenio.jpg'), 'rb') as fp:
        logo_checksum = hashlib.md5(fp.read()).hexdigest()
        assert ObjectVersion.query.first().file.checksum == \
            'md5:{0}'.format(logo_checksum)

    # Load the community featurings
    for data in featured_dump:
        load_featured.delay(data)

    # Make sure they are loaded correctly
    assert FeaturedCommunity.query.count() == 1
    fc = FeaturedCommunity.query.first()
    assert fc.community.id == c.id
def test_communities_load(db, communities_dump, featured_dump, logos_dir):
    """Load the communities JSON dump."""
    # Create a single user (with id=1) to meet the community's FK constraint.
    create_test_user('*****@*****.**', password='******')

    # Initialize communities bucket (requires a default Location)
    loc = Location(name='local', uri='file:///tmp', default=True)
    db.session.add(loc)
    db.session.commit()
    initialize_communities_bucket()

    # Load the communities
    for data in communities_dump:
        load_community.delay(data, logos_dir)

    # Check if community was loaded correctly
    assert Community.query.count() == 1
    c = Community.query.first()
    assert c.title == 'Invenio Community'
    assert c.id == 'invenio'

    # Check object metadata
    assert ObjectVersion.query.count() == 1  # Check if the logo was created
    assert ObjectVersion.query.first().key == 'invenio/logo.jpg'

    # Open the original logo from test data and check if checksums match
    with open(join(logos_dir, 'invenio.jpg'), 'rb') as fp:
        logo_checksum = hashlib.md5(fp.read()).hexdigest()
        assert ObjectVersion.query.first().file.checksum == \
            'md5:{0}'.format(logo_checksum)

    # Load the community featurings
    for data in featured_dump:
        load_featured.delay(data)

    # Make sure they are loaded correctly
    assert FeaturedCommunity.query.count() == 1
    fc = FeaturedCommunity.query.first()
    assert fc.community.id == c.id
예제 #3
0
def init():
    """Load basic data."""
    loadpages()
    loadlocation()
    loadoaisets()
    initialize_communities_bucket()
예제 #4
0
파일: cli.py 프로젝트: SamiHiltunen/zenodo
def init():
    """Load basic data."""
    loadpages()
    loadlocation()
    loadoaisets()
    initialize_communities_bucket()