Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
177 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of REANA. | ||
# Copyright (C) 2017, 2018 CERN. | ||
# | ||
# REANA is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""Pytest configuration for REANA-DB.""" | ||
|
||
import pytest | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.orm import scoped_session, sessionmaker | ||
from sqlalchemy_utils import create_database, database_exists, drop_database | ||
|
||
from reana_db.models import Base | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def db(): | ||
"""Flask application fixture.""" | ||
test_db_engine = create_engine('sqlite:///testdb.db') | ||
if not database_exists(test_db_engine.url): | ||
create_database(test_db_engine.url) | ||
Base.metadata.create_all(bind=test_db_engine) | ||
yield test_db_engine | ||
drop_database(test_db_engine.url) | ||
|
||
|
||
@pytest.fixture() | ||
def session(db): | ||
"""Create a SQL Alchemy session. | ||
Scope: function | ||
This fixture offers a SQLAlchemy session which has been created from the | ||
``db_engine`` fixture. | ||
.. code-block:: python | ||
from reana_db.models import Workflow | ||
def test_create_workflow(session): | ||
workflow = Workflow(...) | ||
session.add(workflow) | ||
session.commit() | ||
""" | ||
Session = scoped_session(sessionmaker(autocommit=False, | ||
autoflush=False, | ||
bind=db)) | ||
Base.query = Session.query_property() | ||
from reana_db.database import Session as _Session | ||
_Session.configure(bind=db) | ||
yield Session | ||
Session.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of REANA. | ||
# Copyright (C) 2019 CERN. | ||
# | ||
# REANA is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""REANA-DB models tests.""" | ||
|
||
from uuid import uuid4 | ||
|
||
import pytest | ||
|
||
from reana_db.models import Workflow | ||
|
||
|
||
def test_workflow_run_number_assignment(db, session): | ||
"""Test workflow run number assignment.""" | ||
workflow_name = 'workflow' | ||
owner_id = str(uuid4()) | ||
first_workflow = Workflow( | ||
id_=str(uuid4()), | ||
name=workflow_name, | ||
owner_id=owner_id, | ||
reana_specification=[], | ||
type_='serial', | ||
logs='', | ||
) | ||
session.add(first_workflow) | ||
session.commit() | ||
assert first_workflow.run_number == 1 | ||
second_workflow = Workflow( | ||
id_=str(uuid4()), | ||
name=workflow_name, | ||
owner_id=owner_id, | ||
reana_specification=[], | ||
type_='serial', | ||
logs='', | ||
) | ||
session.add(second_workflow) | ||
session.commit() | ||
assert second_workflow.run_number == 2 | ||
first_workflow_restart = Workflow( | ||
id_=str(uuid4()), | ||
name=workflow_name, | ||
owner_id=owner_id, | ||
reana_specification=[], | ||
type_='serial', | ||
logs='', | ||
restart=True, | ||
run_number=first_workflow.run_number, | ||
) | ||
session.add(first_workflow_restart) | ||
session.commit() | ||
assert first_workflow_restart.run_number == 1.1 | ||
first_workflow_second_restart = Workflow( | ||
id_=str(uuid4()), | ||
name=workflow_name, | ||
owner_id=owner_id, | ||
reana_specification=[], | ||
type_='serial', | ||
logs='', | ||
restart=True, | ||
run_number=first_workflow_restart.run_number, | ||
) | ||
session.add(first_workflow_second_restart) | ||
session.commit() | ||
assert first_workflow_second_restart.run_number == 1.2 |