Skip to content

Commit

Permalink
[ADD] Support for user types
Browse files Browse the repository at this point in the history
* Add support for user types via enum
  • Loading branch information
lasley committed Nov 9, 2016
1 parent d251216 commit a498bb2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
14 changes: 14 additions & 0 deletions carepoint/models/cph/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Copyright 2015-TODAY LasLabs Inc.
# License MIT (https://opensource.org/licenses/MIT).

import enum

from carepoint import Carepoint
from sqlalchemy import (Column,
Integer,
Expand All @@ -12,6 +14,14 @@
)


class EnumUserType(enum.Enum):
""" It provides PEP-0435 compliant Carepoint User Type Enumerable """

user = 'U'
group = 'G'
machine = 'M'


class User(Carepoint.BASE):
__tablename__ = 'csuser'
__dbname__ = 'cph'
Expand Down Expand Up @@ -57,3 +67,7 @@ class User(Carepoint.BASE):
ForeignKey('csuser.user_id'),
)
chg_date = Column(DateTime)

@property
def user_type(self):
return EnumUserType(self.user_type_cd)
16 changes: 15 additions & 1 deletion carepoint/tests/models/cph/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,28 @@
import unittest
from sqlalchemy.schema import Table
from carepoint.tests.db.db import DatabaseTest
from carepoint.models.cph.user import User
from carepoint.models.cph.user import EnumUserType, User


class TestModelsCphUser(DatabaseTest):

def new_record(self, type_cd='U'):
self.type_cd = type_cd
obj = User()
obj.user_type_cd = type_cd
return obj

def test_table_initialization(self, ):
self.assertIsInstance(User.__table__, Table)

def test_user_type(self):
""" It should return proper Enum for user type cd """
obj = self.new_record()
self.assertEqual(
obj.user_type,
EnumUserType(self.type_cd),
)


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup_vals = {
'name': 'carepoint',
'version': '0.1.7',
'version': '0.1.8',
'author': 'LasLabs Inc.',
'author_email': 'support@laslabs.com',
'description': 'This library will allow you to interact with CarePoint '
Expand Down

0 comments on commit a498bb2

Please sign in to comment.