forked from myemma/EmmaPython
-
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 myemma#14 from myemma/feature/add-automation-resource
Adds support for new Automation models and Workflow Resource
- Loading branch information
Showing
5 changed files
with
213 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
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 @@ | ||
"""Automation models""" | ||
|
||
from emma.model import BaseApiModel, str_fields_to_datetime_alt | ||
|
||
|
||
class Workflow(BaseApiModel): | ||
""" | ||
Encapsulates operations for a :class:`Workflow` | ||
:param account: The Account which owns this Workflow | ||
:type account: :class:`Account` | ||
:param raw: The raw values of this :class:`Workflow` | ||
:type raw: :class:`dict` | ||
Usage:: | ||
>>> from emma.model.account import Account | ||
>>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180") | ||
>>> auto = acct.workflows[123] | ||
>>> auto | ||
<Workflow> | ||
""" | ||
def __init__(self, account, raw=None): | ||
self.account = account | ||
super(Workflow, self).__init__(raw) | ||
|
||
# def __repr__(self): | ||
# return '<Workflow: {}>'.format(self.workflow_id) | ||
|
||
def _parse_raw(self, raw): | ||
raw.update( | ||
str_fields_to_datetime_alt( | ||
['created_at', 'updated_at'], raw | ||
) | ||
) | ||
return raw |
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 | ||
import unittest | ||
|
||
from emma.model import SERIALIZED_DATETIME_ALT_FORMAT | ||
from emma import exceptions as ex | ||
from emma.model.account import Account | ||
from emma.model.automation import Workflow | ||
|
||
from tests.model import MockAdapter | ||
|
||
|
||
class WorkflowTest(unittest.TestCase): | ||
""" | ||
Tests for the Workflow model | ||
""" | ||
|
||
def setUp(self): | ||
""" | ||
Set up tasks for our tests | ||
""" | ||
Account.default_adapter = MockAdapter | ||
self.workflow = Workflow( | ||
Account(account_id="100", public_key="xxx", private_key="yyy"), | ||
{ | ||
'workflow_id': '22048a49-9533-4014-ae03-2af3598ed9a7', | ||
'status': 'active', | ||
'name': 'Test', | ||
'created_at': datetime.now().strftime(SERIALIZED_DATETIME_ALT_FORMAT), | ||
'updated_at': datetime.now().strftime(SERIALIZED_DATETIME_ALT_FORMAT), | ||
} | ||
) | ||
|
||
def test_can_represent_workflow(self): | ||
self.assertEquals( | ||
u"<Workflow" + repr(self.workflow._dict) + u">", | ||
repr(self.workflow)) |