Abstract away SWF *Type models logic into a GenericType class

This commit is contained in:
Jean-Baptiste Barth 2015-10-01 21:25:25 +02:00
commit 5c02fcd94b
3 changed files with 72 additions and 81 deletions

View file

@ -12,37 +12,6 @@ from moto.swf.exceptions import (
)
# Models
def test_short_dict_representation():
_type = ActivityType("test-activity", "v1.0")
_type.to_short_dict().should.equal({"name": "test-activity", "version": "v1.0"})
def test_medium_dict_representation():
_type = ActivityType("test-activity", "v1.0")
_type.to_medium_dict()["activityType"].should.equal(_type.to_short_dict())
_type.to_medium_dict()["status"].should.equal("REGISTERED")
_type.to_medium_dict().should.contain("creationDate")
_type.to_medium_dict().should_not.contain("deprecationDate")
_type.to_medium_dict().should_not.contain("description")
_type.description = "foo bar"
_type.to_medium_dict()["description"].should.equal("foo bar")
_type.status = "DEPRECATED"
_type.to_medium_dict().should.contain("deprecationDate")
def test_full_dict_representation():
_type = ActivityType("test-activity", "v1.0")
_type.to_full_dict()["typeInfo"].should.equal(_type.to_medium_dict())
_type.to_full_dict()["configuration"].should.equal({})
_type.task_list = "foo"
_type.to_full_dict()["configuration"]["defaultTaskList"].should.equal({"name":"foo"})
_type.default_task_heartbeat_timeout = "60"
_type.to_full_dict()["configuration"]["defaultTaskHeartbeatTimeout"].should.equal("60")
# RegisterActivityType endpoint
@mock_swf
def test_register_activity_type():

View file

@ -0,0 +1,46 @@
from sure import expect
from moto.swf.models import GenericType
class FooType(GenericType):
@property
def kind(self):
return "foo"
@property
def _configuration_keys(self):
return ["justAnExampleTimeout"]
def test_short_dict_representation():
_type = FooType("test-foo", "v1.0")
_type.to_short_dict().should.equal({"name": "test-foo", "version": "v1.0"})
def test_medium_dict_representation():
_type = FooType("test-foo", "v1.0")
_type.to_medium_dict()["fooType"].should.equal(_type.to_short_dict())
_type.to_medium_dict()["status"].should.equal("REGISTERED")
_type.to_medium_dict().should.contain("creationDate")
_type.to_medium_dict().should_not.contain("deprecationDate")
_type.to_medium_dict().should_not.contain("description")
_type.description = "foo bar"
_type.to_medium_dict()["description"].should.equal("foo bar")
_type.status = "DEPRECATED"
_type.to_medium_dict().should.contain("deprecationDate")
def test_full_dict_representation():
_type = FooType("test-foo", "v1.0")
_type.to_full_dict()["typeInfo"].should.equal(_type.to_medium_dict())
_type.to_full_dict()["configuration"].should.equal({})
_type.task_list = "foo"
_type.to_full_dict()["configuration"]["defaultTaskList"].should.equal({"name":"foo"})
_type.just_an_example_timeout = "60"
_type.to_full_dict()["configuration"]["justAnExampleTimeout"].should.equal("60")
_type.non_whitelisted_property = "34"
_type.to_full_dict()["configuration"].keys().should.equal(["defaultTaskList", "justAnExampleTimeout"])