-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from cloudblue/LITE-29259-create-credential-dat…
…a-model LITE-29259 Create credential data model
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from datetime import datetime | ||
|
||
import sqlalchemy as db | ||
|
||
from connect_bi_reporter.db import Model | ||
|
||
|
||
class Credential(Model): | ||
__tablename__ = "credential" | ||
|
||
PREFIX = 'CRED' | ||
|
||
id = db.Column(db.String(20), primary_key=True) | ||
name = db.Column(db.String(64), nullable=False) | ||
connection_string = db.Column(db.String(256), nullable=False) | ||
account_id = db.Column(db.String(20), nullable=False) | ||
created_at = db.Column(db.DateTime(), default=datetime.utcnow) | ||
created_by = db.Column(db.String(20)) | ||
updated_at = db.Column(db.DateTime(), onupdate=datetime.utcnow, default=datetime.utcnow) | ||
updated_by = db.Column(db.String(20)) |
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,36 @@ | ||
from datetime import datetime | ||
|
||
|
||
def test_create_credential(dbsession, credential_factory): | ||
credential_model = credential_factory._meta.model | ||
assert not dbsession.query(credential_model).all() | ||
credential = credential_model( | ||
name='My cred', | ||
account_id='PA-000-000', | ||
connection_string='core.windows.net', | ||
) | ||
dbsession.add_with_verbose(credential) | ||
dbsession.commit() | ||
dbsession.refresh(credential) | ||
assert credential.id.startswith(credential_model.PREFIX) | ||
assert credential.name == 'My cred' | ||
assert credential.connection_string == 'core.windows.net' | ||
assert isinstance(credential.created_at, datetime) | ||
|
||
|
||
def test_update_credential(dbsession, credential_factory): | ||
credential = credential_factory() | ||
assert credential.name.startswith('Credential') | ||
previous_update = credential.updated_at | ||
credential.name = 'New name' | ||
dbsession.add(credential) | ||
dbsession.commit() | ||
assert credential.name == 'New name' | ||
assert credential.updated_at != previous_update | ||
|
||
|
||
def test_delete_credential(dbsession, credential_factory): | ||
credential = credential_factory() | ||
assert dbsession.query(credential_factory._meta.model).count() == 1 | ||
dbsession.delete(credential) | ||
assert not dbsession.query(credential_factory._meta.model).all() |
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