Implement naive reverseOrder option for SWF's ListDomains endpoint
This commit is contained in:
parent
3e2c7dec83
commit
cb46eac513
@ -45,10 +45,14 @@ class SWFBackend(BaseBackend):
|
||||
if not isinstance(parameter, basestring):
|
||||
raise SWFSerializationException()
|
||||
|
||||
def list_domains(self, status):
|
||||
def list_domains(self, status, reverse_order=None):
|
||||
self._check_string(status)
|
||||
return [domain for domain in self.domains
|
||||
if domain.status == status]
|
||||
domains = [domain for domain in self.domains
|
||||
if domain.status == status]
|
||||
domains = sorted(domains, key=lambda domain: domain.name)
|
||||
if reverse_order:
|
||||
domains = reversed(domains)
|
||||
return domains
|
||||
|
||||
def register_domain(self, name, workflow_execution_retention_period_in_days,
|
||||
description=None):
|
||||
|
@ -51,11 +51,11 @@ class SWFResponse(BaseResponse):
|
||||
def _params(self):
|
||||
return json.loads(self.body)
|
||||
|
||||
# TODO: implement "reverseOrder" option
|
||||
# TODO: implement pagination
|
||||
def list_domains(self):
|
||||
status = self._params.get("registrationStatus")
|
||||
domains = self.swf_backend.list_domains(status)
|
||||
reverse_order = self._params.get("reverseOrder", None)
|
||||
domains = self.swf_backend.list_domains(status, reverse_order=reverse_order)
|
||||
template = self.response_template(LIST_DOMAINS_TEMPLATE)
|
||||
return template.render(domains=domains)
|
||||
|
||||
|
@ -12,7 +12,6 @@ from moto.swf.exceptions import (
|
||||
|
||||
|
||||
# RegisterDomain endpoint
|
||||
# ListDomain endpoint
|
||||
@mock_swf
|
||||
def test_register_domain():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
@ -57,6 +56,30 @@ def test_register_with_wrong_parameter_type():
|
||||
})
|
||||
|
||||
|
||||
# ListDomain endpoint
|
||||
@mock_swf
|
||||
def test_list_domains_order():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("b-test-domain", "60")
|
||||
conn.register_domain("a-test-domain", "60")
|
||||
conn.register_domain("c-test-domain", "60")
|
||||
|
||||
all_domains = conn.list_domains("REGISTERED")
|
||||
names = [domain["name"] for domain in all_domains["domainInfos"]]
|
||||
names.should.equal(["a-test-domain", "b-test-domain", "c-test-domain"])
|
||||
|
||||
@mock_swf
|
||||
def test_list_domains_reverse_order():
|
||||
conn = boto.connect_swf("the_key", "the_secret")
|
||||
conn.register_domain("b-test-domain", "60")
|
||||
conn.register_domain("a-test-domain", "60")
|
||||
conn.register_domain("c-test-domain", "60")
|
||||
|
||||
all_domains = conn.list_domains("REGISTERED", reverse_order=True)
|
||||
names = [domain["name"] for domain in all_domains["domainInfos"]]
|
||||
names.should.equal(["c-test-domain", "b-test-domain", "a-test-domain"])
|
||||
|
||||
|
||||
# DeprecateDomain endpoint
|
||||
@mock_swf
|
||||
def test_deprecate_domain():
|
||||
|
Loading…
Reference in New Issue
Block a user