Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move ramstk_group to a package #991

Merged
merged 3 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/do_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
pip install \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple \
ramstk && echo "install_ok=1" >> $GITHUB_ENV
ramstk==${{ steps.relversion.outputs.rel_version }} && echo "install_ok=1" >> $GITHUB_ENV

- name: Publish to PyPi
if: ${{ env.install_ok == 1 }}
Expand All @@ -101,6 +101,7 @@ jobs:

- name: Upload wheel to Release
id: upload-wheel
if: ${{ env.install_ok == 1 }}
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ steps.cutrelease.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
Expand Down
6 changes: 6 additions & 0 deletions src/ramstk/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@
# Copyright since 2007 Doyle "weibullguy" Rowland doyle.rowland <AT> reliaqual <DOT> com
"""The RAMSTK database models package."""

# These need to be skipped by isort because they are imported by each of the record,
# table, and view models to follow.
from .basemodel import ( # isort:skip
RAMSTKBaseRecord, # isort:skip
RAMSTKBaseTable, # isort:skip
RAMSTKBaseView, # isort:skip
)

# These need to be skipped by isort because they are imported by each of the
# associated table models as well as the RAMSTKCommonDB.
from .commondb.category.record import RAMSTKCategoryRecord # isort:skip
from .commondb.condition.record import RAMSTKConditionRecord # isort:skip
from .commondb.failure_mode.record import RAMSTKFailureModeRecord # isort:skip
from .commondb.group.record import RAMSTKGroupRecord # isort:skip
from .commondb.site_info.record import RAMSTKSiteInfoRecord # isort:skip
from .commondb.subcategory.record import RAMSTKSubCategoryRecord # isort:skip
from .commondb.category.table import RAMSTKCategoryTable # isort:skip
Expand All @@ -24,6 +29,7 @@
from .commondb.condition.table import RAMSTKConditionTable
from .commondb.database import RAMSTKCommonDB
from .commondb.failure_mode.table import RAMSTKFailureModeTable
from .commondb.group.table import RAMSTKGroupTable
from .commondb.site_info.table import RAMSTKSiteInfoTable
from .commondb.subcategory.table import RAMSTKSubCategoryTable
from .programdb.action.record import RAMSTKActionRecord
Expand Down
1 change: 0 additions & 1 deletion src/ramstk/models/commondb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""The RAMSTK common database models package."""

# RAMSTK Local Imports
from .ramstkgroup import RAMSTKGroup
from .ramstkhazards import RAMSTKHazards
from .ramstkloadhistory import RAMSTKLoadHistory
from .ramstkmanufacturer import RAMSTKManufacturer
Expand Down
10 changes: 5 additions & 5 deletions src/ramstk/models/commondb/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
from ramstk.models import (
RAMSTKCategoryRecord,
RAMSTKFailureModeRecord,
RAMSTKGroupRecord,
RAMSTKSiteInfoRecord,
RAMSTKSubCategoryRecord,
)
from ramstk.models.commondb import (
RAMSTKRPN,
RAMSTKGroup,
RAMSTKHazards,
RAMSTKLoadHistory,
RAMSTKManufacturer,
Expand Down Expand Up @@ -327,8 +327,8 @@ def _do_load_affinity_groups(
:rtype: RAMSTKUserConfiguration
"""
for _record in (
self.common_dao.session.query(RAMSTKGroup)
.filter(RAMSTKGroup.group_type == "affinity")
self.common_dao.session.query(RAMSTKGroupRecord)
.filter(RAMSTKGroupRecord.group_type == "affinity")
.all()
):
_attributes = _record.get_attributes()
Expand Down Expand Up @@ -846,8 +846,8 @@ def _do_load_workgroups(
:rtype: RAMSTKUserConfiguration
"""
for _record in (
self.common_dao.session.query(RAMSTKGroup)
.filter(RAMSTKGroup.group_type == "workgroup")
self.common_dao.session.query(RAMSTKGroupRecord)
.filter(RAMSTKGroupRecord.group_type == "workgroup")
.all()
):
_attributes = _record.get_attributes()
Expand Down
2 changes: 1 addition & 1 deletion src/ramstk/models/commondb/database.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ from ramstk.db import BaseDatabase as BaseDatabase
from ramstk.db import do_create_program_db as do_create_program_db
from ramstk.models import RAMSTKCategoryRecord as RAMSTKCategoryRecord
from ramstk.models import RAMSTKFailureModeRecord as RAMSTKFailureModeRecord
from ramstk.models import RAMSTKGroupRecord as RAMSTKGroupRecord
from ramstk.models import RAMSTKSiteInfoRecord as RAMSTKSiteInfoRecord
from ramstk.models import RAMSTKSubCategoryRecord as RAMSTKSubCategoryRecord
from ramstk.models.commondb import RAMSTKRPN as RAMSTKRPN
from ramstk.models.commondb import RAMSTKGroup as RAMSTKGroup
from ramstk.models.commondb import RAMSTKHazards as RAMSTKHazards
from ramstk.models.commondb import RAMSTKLoadHistory as RAMSTKLoadHistory
from ramstk.models.commondb import RAMSTKManufacturer as RAMSTKManufacturer
Expand Down
8 changes: 8 additions & 0 deletions src/ramstk/models/commondb/group/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# pylint: disable=unused-import
# -*- coding: utf-8 -*-
#
# ramstk.models.commondb.group.__init__.py is part of The RAMSTK Project
#
# All rights reserved.
# Copyright since 2007 Doyle "weibullguy" Rowland doyle.rowland <AT> reliaqual <DOT> com
"""The RAMSTK Group model package."""
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
#
# ramstk.models.commondb.RAMSTKGroup.py is part of The RAMSTK Project
# ramstk.models.commondb.group.record.py is part of The RAMSTK Project
#
# All rights reserved.
# Copyright 2007 - 2017 Doyle Rowland doyle.rowland <AT> reliaqual <DOT> com
"""RAMSTKGroup Table Module."""
# Copyright since 2007 Doyle "weibullguy" Rowland doyle.rowland <AT> reliaqual <DOT> com
"""Group Record Model."""

# Third Party Imports
from sqlalchemy import Column, Integer, String
Expand All @@ -14,13 +14,16 @@
from ramstk.models import RAMSTKBaseRecord


class RAMSTKGroup(RAMSTK_BASE, RAMSTKBaseRecord):
class RAMSTKGroupRecord(RAMSTK_BASE, RAMSTKBaseRecord):
"""Class to represent the table ramstk_group in the RAMSTK Common database.

This table shares a Many-to-One relationship with ramstk_user.
"""

__defaults__ = {"description": "Group Description", "group_type": ""}
__defaults__ = {
"description": "Group Description",
"group_type": "",
}
__tablename__ = "ramstk_group"
__table_args__ = {"extend_existing": True}

Expand All @@ -44,10 +47,8 @@ def get_attributes(self):
:return: {workgroup_id, description, group_type} pairs
:rtype: dict
"""
_attributes = {
return {
"group_id": self.group_id,
"description": self.description,
"group_type": self.group_type,
}

return _attributes
57 changes: 57 additions & 0 deletions src/ramstk/models/commondb/group/table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
#
# ramstk.models.commondb.group.table.py is part of The RAMSTK Project
#
# All rights reserved.
# Copyright since 2007 Doyle "weibullguy" Rowland doyle.rowland <AT> reliaqual <DOT> com
"""Group Table Model."""

# Standard Library Imports
from typing import Type

# RAMSTK Package Imports
from ramstk.models import RAMSTKBaseTable, RAMSTKGroupRecord


class RAMSTKGroupTable(RAMSTKBaseTable):
"""Contain the attributes and methods of the Option data manager."""

# Define private dict class attributes.

# Define private list class attributes.

# Define private scalar class attributes.
_db_id_colname = "fld_group_id"
_db_tablename = "ramstk_group"
_deprecated = False
_select_msg = "request_get_group"
_tag = "group"

# Define public dict class attributes.

# Define public list class attributes.

# Define public scalar class attributes.

def __init__(self, **kwargs) -> None:
"""Initialize a Options data manager instance."""
RAMSTKBaseTable.__init__(self, **kwargs)

# Initialize private dictionary attributes.

# Initialize private list attributes.
self._lst_id_columns = [
"group_id",
]

# Initialize private scalar attributes.
self._record: Type[RAMSTKGroupRecord] = RAMSTKGroupRecord

# Initialize public dictionary attributes.

# Initialize public list attributes.

# Initialize public scalar attributes.
self.pkey = "group_id"

# Subscribe to PyPubSub messages.
44 changes: 44 additions & 0 deletions tests/models/commondb/group/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Standard Library Imports
from datetime import date, timedelta

# Third Party Imports
import pytest
from mocks import MockDAO

# RAMSTK Package Imports
from ramstk.models import RAMSTKGroupRecord


@pytest.fixture
def mock_common_dao(monkeypatch):
_group_1 = RAMSTKGroupRecord()
_group_1.group_id = 1
_group_1.group_type = "work"
_group_1.description = "Engineering, RMS"

DAO = MockDAO()
DAO.table = [
_group_1,
]

yield DAO


@pytest.fixture(scope="function")
def test_attributes():
yield {
"group_id": 1,
"group_type": "work",
"description": "Engineering, RMS",
}


@pytest.fixture(scope="function")
def test_recordmodel(mock_common_dao):
"""Get a record model instance for each test function."""
dut = mock_common_dao.do_select_all(RAMSTKGroupRecord, _all=False)

yield dut

# Delete the device under test.
del dut
Loading