# Path: tests_python/util_tests.py
# class TestApp(TestCase):
# 
#     def setUp(self):
#         config = {
#             'SECRET_KEY': 'testing',
#             'SRP_USER_AGENT_EMAIL': 'testing@example.com',
#             'WTF_CSRF_ENABLED': False,
#         }
#         # Default to an ephemeral SQLite DB for testing unless given another
#         # database to connect to.
#         config['SQLALCHEMY_DATABASE_URI'] = env.get('DB', 'sqlite:///')
#         self.app = create_app(config)
#         db.create_all(app=self.app)
# 
#     def tearDown(self):
#         db.drop_all(app=self.app)
# 
# Path: tests_python/test_models.py
# class TestModels(TestLogin):
# 
#     def setUp(self):
#         super(TestModels, self).setUp()
#         with self.app.test_request_context():
#             div = Division('Testing Division')
#             mock_killmail = dict(
#                     id=12842852,
#                     ship_type='Erebus',
#                     corporation='Ever Flow',
#                     alliance='Northern Coalition.',
#                     killmail_url=('http://eve-kill.net/?a=kill_detail'
#                         '&kll_id=12842852'),
#                     base_payout=Decimal(73957900000),
#                     kill_timestamp=dt.datetime(2012, 3, 25, 0, 44, 0,
#                         tzinfo=utc),
#                     system='92D-OI',
#                     constellation='XHYS-O',
#                     region='Venal',
#                     pilot_id=133741,
#             )
#             Pilot(self.normal_user, 'eLusi0n', 133741)
#             Request(self.normal_user, 'Original details', div,
#                     mock_killmail.items())
#             Permission(div, PermissionType.review, self.admin_user)
#             Permission(div, PermissionType.pay, self.admin_user)
#             db.session.commit()
# 
#     @property
#     def request(self):
#         return Request.query.first()
# 
#     def add_action(self, type_):
#         action = Action(self.request, self.admin_user, type_=type_)
#         db.session.commit()
#         return action.id
# 
#     def add_modifier(self, value, absolute=True):
#         if absolute:
#             modifier = AbsoluteModifier(self.request, self.admin_user, None,
#                     Decimal(value))
#         else:
#             modifier = RelativeModifier(self.request, self.admin_user, None,
#                     Decimal(value))
#         db.session.add(modifier)
#         db.session.commit()
#         return modifier.id


from ..util_tests import TestApp
from ..test_models import TestModels
from evesrp import db
from evesrp.models import Request, Modifier, Action, ActionType
from evesrp.auth import PermissionType
from evesrp.auth.models import Entity, User, Group, Permission, Division,\
    PermissionType, APIKey, Note
            Permission(odd, PermissionType.submit, u1)
            Permission(even, PermissionType.submit, u2)
            Permission(odd, PermissionType.submit, u3)
            Permission(prime, PermissionType.submit, u2)
            Permission(prime, PermissionType.submit, u3)
            # Grant review for odd to group 1
            Permission(odd, PermissionType.review, g1)
            # Grant pay to user 4 for prime and to user 3 for even
            Permission(even, PermissionType.pay, u3)
            Permission(prime, PermissionType.pay, u4)
            # In summary:
            # User 1 can submit to odd, and review odd (through Group 1)
            # User 2 can submit to even and prime
            # User 3 can submit to odd and prime, review odd (through Group
            # 1), and pay out even
            # User 4 can pay out prime
            db.session.commit()

    def test_basic_has_permission(self):
        with self.app.test_request_context():
            # Get users
            u1 = User.query.get(1)
            u2 = User.query.get(2)
            u3 = User.query.get(3)
            u4 = User.query.get(4)
            # Actual tests
            self.assertTrue(u1.has_permission(PermissionType.submit))
            self.assertTrue(u1.has_permission(PermissionType.review))
            self.assertFalse(u1.has_permission(PermissionType.pay))


# Path: tests_python/util_tests.py
# class TestApp(TestCase):
# 
#     def setUp(self):
#         config = {
#             'SECRET_KEY': 'testing',
#             'SRP_USER_AGENT_EMAIL': 'testing@example.com',
#             'WTF_CSRF_ENABLED': False,
#         }
#         # Default to an ephemeral SQLite DB for testing unless given another
#         # database to connect to.
#         config['SQLALCHEMY_DATABASE_URI'] = env.get('DB', 'sqlite:///')
#         self.app = create_app(config)
#         db.create_all(app=self.app)
# 
#     def tearDown(self):
#         db.drop_all(app=self.app)
# 
# Path: tests_python/test_models.py
# class TestModels(TestLogin):
# 
#     def setUp(self):
#         super(TestModels, self).setUp()
#         with self.app.test_request_context():
#             div = Division('Testing Division')
#             mock_killmail = dict(
#                     id=12842852,
#                     ship_type='Erebus',
#                     corporation='Ever Flow',
#                     alliance='Northern Coalition.',
#                     killmail_url=('http://eve-kill.net/?a=kill_detail'
#                         '&kll_id=12842852'),
#                     base_payout=Decimal(73957900000),
#                     kill_timestamp=dt.datetime(2012, 3, 25, 0, 44, 0,
#                         tzinfo=utc),
#                     system='92D-OI',
#                     constellation='XHYS-O',
#                     region='Venal',
#                     pilot_id=133741,
#             )
#             Pilot(self.normal_user, 'eLusi0n', 133741)
#             Request(self.normal_user, 'Original details', div,
#                     mock_killmail.items())
#             Permission(div, PermissionType.review, self.admin_user)
#             Permission(div, PermissionType.pay, self.admin_user)
#             db.session.commit()
# 
#     @property
#     def request(self):
#         return Request.query.first()
# 
#     def add_action(self, type_):
#         action = Action(self.request, self.admin_user, type_=type_)
#         db.session.commit()
#         return action.id
# 
#     def add_modifier(self, value, absolute=True):
#         if absolute:
#             modifier = AbsoluteModifier(self.request, self.admin_user, None,
#                     Decimal(value))
#         else:
#             modifier = RelativeModifier(self.request, self.admin_user, None,
#                     Decimal(value))
#         db.session.add(modifier)
#         db.session.commit()
#         return modifier.id


# Path: tests_python/auth/test_models.py
from ..util_tests import TestApp
from ..test_models import TestModels
from evesrp import db
from evesrp.models import Request, Modifier, Action, ActionType
from evesrp.auth import PermissionType
from evesrp.auth.models import Entity, User, Group, Permission, Division,\
    PermissionType, APIKey, Note

            Permission(odd, PermissionType.submit, u1)
            Permission(even, PermissionType.submit, u2)
            Permission(odd, PermissionType.submit, u3)
            Permission(prime, PermissionType.submit, u2)
            Permission(prime, PermissionType.submit, u3)
            # Grant review for odd to group 1
            Permission(odd, PermissionType.review, g1)
            # Grant pay to user 4 for prime and to user 3 for even
            Permission(even, PermissionType.pay, u3)
            Permission(prime, PermissionType.pay, u4)
            # In summary:
            # User 1 can submit to odd, and review odd (through Group 1)
            # User 2 can submit to even and prime
            # User 3 can submit to odd and prime, review odd (through Group
            # 1), and pay out even
            # User 4 can pay out prime
            db.session.commit()

    def test_basic_has_permission(self):
        with self.app.test_request_context():
            # Get users
            u1 = User.query.get(1)
            u2 = User.query.get(2)
            u3 = User.query.get(3)
            u4 = User.query.get(4)
            # Actual tests
            self.assertTrue(u1.has_permission(PermissionType.submit))
            self.assertTrue(u1.has_permission(PermissionType.review))
            self.assertFalse(u1.has_permission(PermissionType.pay))


            self.assertTrue(u2.has_permission(PermissionType.submit))