-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* **New:** Added
AuthenticationLog
class to hold user login/logou…
…t info. * **New:** Added ``stalker.testing`` module to simplify testing setup.
- Loading branch information
Showing
12 changed files
with
714 additions
and
54 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
46 changes: 46 additions & 0 deletions
46
alembic/versions/f16651477e64_added_authenticationlog_class.py
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,46 @@ | ||
"""Added AuthenticationLog class | ||
Revision ID: f16651477e64 | ||
Revises: 255ee1f9c7b3 | ||
Create Date: 2016-11-15 00:22:16.438000 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'f16651477e64' | ||
down_revision = '255ee1f9c7b3' | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
|
||
def upgrade(): | ||
op.create_table( | ||
'AuthenticationLogs', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('uid', sa.Integer(), nullable=False), | ||
sa.Column( | ||
'action', | ||
sa.Enum('login', 'logout', name='ActionNames'), | ||
nullable=False | ||
), | ||
sa.Column('date', sa.DateTime(), nullable=False), | ||
sa.ForeignKeyConstraint(['id'], ['SimpleEntities.id'], ), | ||
sa.ForeignKeyConstraint(['uid'], ['Users.id'], ), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.drop_column(u'Users', 'last_login') | ||
|
||
|
||
def downgrade(): | ||
op.add_column( | ||
u'Users', | ||
sa.Column( | ||
'last_login', | ||
postgresql.TIMESTAMP(), | ||
autoincrement=False, | ||
nullable=True | ||
) | ||
) | ||
op.drop_table('AuthenticationLogs') |
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
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,69 @@ | ||
# -*- coding: utf-8 -*- | ||
# Stalker a Production Asset Management System | ||
# Copyright (C) 2009-2016 Erkan Ozgur Yilmaz | ||
# | ||
# This file is part of Stalker. | ||
# | ||
# This library is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation; | ||
# version 2.1 of the License. | ||
# | ||
# This library is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public | ||
# License along with this library; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
"""Helper classes for testing | ||
""" | ||
|
||
import unittest | ||
|
||
|
||
class UnitTestBase(unittest.TestCase): | ||
"""the base for Stalker Pyramid Views unit tests | ||
""" | ||
|
||
config = { | ||
'sqlalchemy.url': | ||
'postgresql://stalker_admin:stalker@localhost/stalker_test', | ||
'sqlalchemy.echo': False | ||
} | ||
|
||
def setUp(self): | ||
"""setup test | ||
""" | ||
import datetime | ||
from stalker import defaults | ||
defaults.timing_resolution = datetime.timedelta(hours=1) | ||
|
||
# init database | ||
from stalker import db | ||
db.setup(self.config) | ||
db.init() | ||
|
||
def tearDown(self): | ||
"""clean up the test | ||
""" | ||
import datetime | ||
from stalker import db, defaults | ||
from stalker.db.declarative import Base | ||
|
||
# clean up test database | ||
connection = db.DBSession.connection() | ||
engine = connection.engine | ||
connection.close() | ||
Base.metadata.drop_all(engine) | ||
db.DBSession.remove() | ||
|
||
defaults.timing_resolution = datetime.timedelta(hours=1) | ||
|
||
@property | ||
def admin(self): | ||
"""returns the admin user | ||
""" | ||
from stalker import User | ||
return User.query.filter(User.login == 'admin').first() |
Oops, something went wrong.