Exemplo n.º 1
0
    def create(self, name,
               status=REGISTERED,
               description=None,
               retention_period=30,
               *args, **kwargs):
        """Creates a new remote domain and returns the Domain model instance

        :param      name: Name of the domain to register (unique)
        :type       name: string

        :param      retention_period: Domain's workflow executions records retention in days
        :type       retention_period: Integer

        :param      status: Specifies the registration status of the
                            workflow types to list. Valid values are:
                            * ``swf.constants.REGISTERED``
                            * ``swf.constants.DEPRECATED``
        :type       status: string

        :param      description: Textual description of the domain
        :type       description: string
        """

        domain = Domain(
            name,
            status=status,
            description=description,
            retention_period=retention_period
        )
        domain.save()

        return domain
Exemplo n.º 2
0
    def create(self,
               name,
               status=REGISTERED,
               description=None,
               retention_period=30,
               *args,
               **kwargs):
        """Creates a new remote domain and returns the Domain model instance

        :param      name: Name of the domain to register (unique)
        :type       name: string

        :param      retention_period: Domain's workflow executions records retention in days
        :type       retention_period: Integer

        :param      status: Specifies the registration status of the
                            workflow types to list. Valid values are:
                            * ``swf.constants.REGISTERED``
                            * ``swf.constants.DEPRECATED``
        :type       status: string

        :param      description: Textual description of the domain
        :type       description: string
        """

        domain = Domain(name,
                        status=status,
                        description=description,
                        retention_period=retention_period)
        domain.save()

        return domain
    def test_domain__diff_with_different_domain(self):
        with patch.object(Layer1, "describe_domain", mock_describe_domain):
            domain = Domain("different-domain", status=DEPRECATED, description="blabla")
            diffs = domain._diff()

            self.assertIsNotNone(diffs)
            self.assertEqual(len(diffs), 4)

            self.assertTrue(hasattr(diffs[0], "attr"))
            self.assertTrue(hasattr(diffs[0], "local"))
            self.assertTrue(hasattr(diffs[0], "upstream"))
Exemplo n.º 4
0
    def test_domain__diff_with_different_domain(self):
        with patch.object(
            Layer1, "describe_domain", mock_describe_domain,
        ):
            domain = Domain("different-domain", status=DEPRECATED, description="blabla")
            diffs = domain._diff()

            self.assertIsNotNone(diffs)
            self.assertEqual(len(diffs), 4)

            self.assertTrue(hasattr(diffs[0], "attr"))
            self.assertTrue(hasattr(diffs[0], "local"))
            self.assertTrue(hasattr(diffs[0], "upstream"))
    def test_domain__diff_with_identical_domain(self):
        with patch.object(Layer1, "describe_domain", mock_describe_domain):
            mocked = mock_describe_domain()
            domain = Domain(
                mocked["domainInfo"]["name"],
                status=mocked["domainInfo"]["status"],
                description=mocked["domainInfo"]["description"],
                retention_period=mocked["configuration"]["workflowExecutionRetentionPeriodInDays"],
            )

            diffs = domain._diff()

            self.assertEqual(len(diffs), 0)
Exemplo n.º 6
0
    def test_domain__diff_with_identical_domain(self):
        with patch.object(
                Layer1,
                'describe_domain',
                mock_describe_domain,
        ):
            mocked = mock_describe_domain()
            domain = Domain(mocked['domainInfo']['name'],
                            status=mocked['domainInfo']['status'],
                            description=mocked['domainInfo']['description'],
                            retention_period=mocked['configuration']
                            ['workflowExecutionRetentionPeriodInDays'])

            diffs = domain._diff()

            self.assertEqual(len(diffs), 0)
Exemplo n.º 7
0
    def test_domain__diff_with_identical_domain(self):
        with patch.object(
            Layer1,
            'describe_domain',
            mock_describe_domain,
        ):
            mocked = mock_describe_domain()
            domain = Domain(
                mocked['domainInfo']['name'],
                status=mocked['domainInfo']['status'],
                description=mocked['domainInfo']['description'],
                retention_period=mocked['configuration']['workflowExecutionRetentionPeriodInDays']
            )

            diffs = domain._diff()

            self.assertEqual(len(diffs), 0)
Exemplo n.º 8
0
    def test_domain__diff_with_identical_domain(self):
        with patch.object(
            Layer1, "describe_domain", mock_describe_domain,
        ):
            mocked = mock_describe_domain()
            domain = Domain(
                mocked["domainInfo"]["name"],
                status=mocked["domainInfo"]["status"],
                description=mocked["domainInfo"]["description"],
                retention_period=mocked["configuration"][
                    "workflowExecutionRetentionPeriodInDays"
                ],
            )

            diffs = domain._diff()

            self.assertEqual(len(diffs), 0)
Exemplo n.º 9
0
 def setUp(self):
     self.domain = Domain("TestDomain")
     self.wt = WorkflowType(self.domain, "TestType", "1.0")
     self.we = WorkflowExecution(
         self.domain,
         self.wt,
         "TestType-0.1-TestDomain"
     )
Exemplo n.º 10
0
    def test_domain_changes_with_different_domain(self):
        with patch.object(
                Layer1,
                'describe_domain',
                mock_describe_domain,
        ):
            domain = Domain("different-domain",
                            status=DEPRECATED,
                            description="blabla")
            diffs = domain.changes

            self.assertIsNotNone(diffs)
            self.assertEqual(len(diffs), 4)

            self.assertTrue(hasattr(diffs[0], 'attr'))
            self.assertTrue(hasattr(diffs[0], 'local'))
            self.assertTrue(hasattr(diffs[0], 'upstream'))
Exemplo n.º 11
0
    def get(self, name, *args, **kwargs):
        """Fetches the Domain with `name`

        :param      name:  name of the domain to fetch
        :type       name: string

        A typical Amazon response looks like:

        .. code-block:: json

            {
                "configuration": {
                    "workflowExecutionRetentionPeriodInDays": "7",
                },
                "domainInfo": {
                    "status": "REGISTERED",
                    "name": "CrawlTest",
                }
            }
        """
        try:
            response = self.connection.describe_domain(name)
        except SWFResponseError as e:
            # If resource does not exist, amazon throws 400 with
            # UnknownResourceFault exception
            if e.error_code == "UnknownResourceFault":
                raise DoesNotExistError("No such domain: %s" % name)
            elif e.error_code == "UnrecognizedClientException":
                raise InvalidCredentialsError("Invalid aws credentials supplied")
            # Any other errors should raise
            raise ResponseError(e.body["message"])

        domain_info = response["domainInfo"]
        domain_config = response["configuration"]

        return Domain(
            domain_info["name"],
            status=domain_info["status"],
            retention_period=domain_config["workflowExecutionRetentionPeriodInDays"],
            connection=self.connection,
        )
Exemplo n.º 12
0
    def all(self, registration_status=REGISTERED, *args, **kwargs):
        """Retrieves every domains

        :param      registration_status: domain registration status to match,
                                         Valid values are:
                                         * ``swf.constants.REGISTERED``
                                         * ``swf.constants.DEPRECATED``

        :type       registration_status: string

        A typical Amazon response looks like:

        .. code-block:: json

            {
                "domainInfos": [
                    {
                        "name": "Crawl"
                        "status": "REGISTERED",
                        "description": "",
                    },
                ]
            }
        """

        def get_domains():
            response = {"nextPageToken": None}
            while "nextPageToken" in response:
                response = self.connection.list_domains(
                    registration_status, next_page_token=response["nextPageToken"]
                )

                for domain_info in response["domainInfos"]:
                    yield domain_info

        return [
            Domain(d["name"], d["status"], d.get("description")) for d in get_domains()
        ]
Exemplo n.º 13
0
 def setUp(self):
     self.domain = Domain("TestDomain")
     self.atq = ActivityTypeQuerySet(self.domain)
Exemplo n.º 14
0
 def test_domain_is_synced_over_non_existent_domain(self):
     with patch.object(Layer1, 'describe_domain', mock_describe_domain):
         domain = Domain("non-existent-domain")
         self.assertFalse(domain.is_synced)
Exemplo n.º 15
0
 def setUp(self):
     self.domain = Domain("TestDomain")
     self.wtq = WorkflowTypeQuerySet(self.domain)
Exemplo n.º 16
0
 def setUp(self):
     self.domain = Domain("TestDomain")
     self.bw = BaseWorkflowQuerySet(self.domain)
Exemplo n.º 17
0
 def setUp(self):
     self.domain = Domain("TestDomain")
     self.wt = WorkflowType(self.domain, "TestType", "0.1")
     self.weq = WorkflowExecutionQuerySet(self.domain)
Exemplo n.º 18
0
 def setUp(self):
     self.domain = Domain("test-domain")
     self.wt = WorkflowType(self.domain, "TestType", "1.0")
Exemplo n.º 19
0
class TestDomain(unittest.TestCase):
    def setUp(self):
        self.domain = Domain("testdomain")
        self.qs = DomainQuerySet(self)

        self.mocked_workflow_type_qs = Mock(spec=WorkflowTypeQuerySet)
        self.mocked_workflow_type_qs.all.return_value = []

    def tearDown(self):
        pass

    @patch.object(Layer1, "__init__", MiniMock(aws_access_key_id="test", aws_secret_access_key="test"))
    def test_domain_inits_connection(self):
        self.assertTrue(hasattr(self.domain, "connection"))
        self.assertTrue(hasattr(self.domain.connection, "aws_access_key_id"))
        self.assertTrue(hasattr(self.domain.connection, "aws_secret_access_key"))

    def test_domain__diff_with_different_domain(self):
        with patch.object(Layer1, "describe_domain", mock_describe_domain):
            domain = Domain("different-domain", status=DEPRECATED, description="blabla")
            diffs = domain._diff()

            self.assertIsNotNone(diffs)
            self.assertEqual(len(diffs), 4)

            self.assertTrue(hasattr(diffs[0], "attr"))
            self.assertTrue(hasattr(diffs[0], "local"))
            self.assertTrue(hasattr(diffs[0], "upstream"))

    def test_domain__diff_with_identical_domain(self):
        with patch.object(Layer1, "describe_domain", mock_describe_domain):
            mocked = mock_describe_domain()
            domain = Domain(
                mocked["domainInfo"]["name"],
                status=mocked["domainInfo"]["status"],
                description=mocked["domainInfo"]["description"],
                retention_period=mocked["configuration"]["workflowExecutionRetentionPeriodInDays"],
            )

            diffs = domain._diff()

            self.assertEqual(len(diffs), 0)

    def test_domain_exists_with_existing_domain(self):
        with patch.object(self.domain.connection, "describe_domain"):
            self.assertTrue(self.domain.exists)

    def test_domain_exists_with_non_existent_domain(self):
        with patch.object(self.domain.connection, "describe_domain") as mock:
            mock.side_effect = SWFResponseError(
                400,
                "Bad Request",
                {
                    "message": "Unknown domain: does not exist",
                    "__type": "com.amazonaws.swf.base.model#UnknownResourceFault",
                },
                "UnknownResourceFault",
            )

            self.assertFalse(self.domain.exists)

    def test_domain_exists_with_whatever_error(self):
        with patch.object(self.domain.connection, "describe_domain") as mock:
            with self.assertRaises(ResponseError):
                mock.side_effect = SWFResponseError(
                    400, "mocking exception", {"__type": "WhateverError", "message": "Whatever"}
                )
                self.domain.exists

    def test_domain_is_synced_with_unsynced_domain(self):
        pass

    def test_domain_is_synced_with_synced_domain(self):
        pass

    def test_domain_is_synced_over_non_existent_domain(self):
        with patch.object(Layer1, "describe_domain", mock_describe_domain):
            domain = Domain("non-existent-domain")
            self.assertFalse(domain.is_synced)

    def test_domain_changes_with_different_domain(self):
        with patch.object(Layer1, "describe_domain", mock_describe_domain):
            domain = Domain("different-domain", status=DEPRECATED, description="blabla")
            diffs = domain.changes

            self.assertIsNotNone(diffs)
            self.assertEqual(len(diffs), 4)

            self.assertTrue(hasattr(diffs[0], "attr"))
            self.assertTrue(hasattr(diffs[0], "local"))
            self.assertTrue(hasattr(diffs[0], "upstream"))

    def test_domain_changes_with_identical_domain(self):
        with patch.object(Layer1, "describe_domain", mock_describe_domain):
            mocked = mock_describe_domain()
            domain = Domain(
                mocked["domainInfo"]["name"],
                status=mocked["domainInfo"]["status"],
                description=mocked["domainInfo"]["description"],
                retention_period=mocked["configuration"]["workflowExecutionRetentionPeriodInDays"],
            )

            diffs = domain.changes

            self.assertEqual(len(diffs), 0)

    def test_domain_save_valid_domain(self):
        with patch.object(self.domain.connection, "register_domain") as mock:
            self.domain.save()

    def test_domain_save_already_existing_domain(self):
        with patch.object(self.domain.connection, "register_domain") as mock:
            with self.assertRaises(AlreadyExistsError):
                mock.side_effect = SWFDomainAlreadyExistsError(400, "mocking exception")
                self.domain.save()

    def test_domain_delete_existing_domain(self):
        with patch.object(self.domain.connection, "deprecate_domain"):
            self.domain.delete()

    def test_domain_delete_non_existent_domain(self):
        with patch.object(self.domain.connection, "deprecate_domain") as mock:
            with self.assertRaises(DomainDoesNotExist):
                mock.side_effect = SWFResponseError(
                    400,
                    "Bad Request",
                    {
                        "message": "Unknown domain: does not exist",
                        "__type": "com.amazonaws.swf.base.model#UnknownResourceFault",
                    },
                    "UnknownResourceFault",
                )
                self.domain.delete()

    def test_domain_workflows_without_existent_workflows(self):
        with patch.object(WorkflowTypeQuerySet, "all") as all_method:
            all_method.return_value = []
            self.assertEquals(self.domain.workflows(), [])
Exemplo n.º 20
0
    def setUp(self):
        self.domain = Domain("testdomain")
        self.qs = DomainQuerySet(self)

        self.mocked_workflow_type_qs = Mock(spec=WorkflowTypeQuerySet)
        self.mocked_workflow_type_qs.all.return_value = []
Exemplo n.º 21
0
class TestDomain(unittest.TestCase):
    def setUp(self):
        self.domain = Domain("testdomain")
        self.qs = DomainQuerySet(self)

        self.mocked_workflow_type_qs = Mock(spec=WorkflowTypeQuerySet)
        self.mocked_workflow_type_qs.all.return_value = []

    def tearDown(self):
        pass

    @patch.object(Layer1, '__init__',
                  MiniMock(aws_access_key_id='test',
                           aws_secret_access_key='test'))
    def test_domain_inits_connection(self):
        self.assertTrue(hasattr(self.domain, 'connection'))
        self.assertTrue(hasattr(self.domain.connection, 'aws_access_key_id'))
        self.assertTrue(
            hasattr(self.domain.connection, 'aws_secret_access_key'))

    def test_domain__diff_with_different_domain(self):
        with patch.object(
                Layer1,
                'describe_domain',
                mock_describe_domain,
        ):
            domain = Domain("different-domain",
                            status=DEPRECATED,
                            description="blabla")
            diffs = domain._diff()

            self.assertIsNotNone(diffs)
            self.assertEqual(len(diffs), 4)

            self.assertTrue(hasattr(diffs[0], 'attr'))
            self.assertTrue(hasattr(diffs[0], 'local'))
            self.assertTrue(hasattr(diffs[0], 'upstream'))

    def test_domain__diff_with_identical_domain(self):
        with patch.object(
                Layer1,
                'describe_domain',
                mock_describe_domain,
        ):
            mocked = mock_describe_domain()
            domain = Domain(mocked['domainInfo']['name'],
                            status=mocked['domainInfo']['status'],
                            description=mocked['domainInfo']['description'],
                            retention_period=mocked['configuration']
                            ['workflowExecutionRetentionPeriodInDays'])

            diffs = domain._diff()

            self.assertEqual(len(diffs), 0)

    def test_domain_exists_with_existing_domain(self):
        with patch.object(self.domain.connection, 'describe_domain'):
            self.assertTrue(self.domain.exists)

    def test_domain_exists_with_non_existent_domain(self):
        with patch.object(self.domain.connection, 'describe_domain') as mock:
            mock.side_effect = SWFResponseError(
                400,
                "Bad Request",
                {
                    'message': 'Unknown domain: does not exist',
                    '__type':
                    'com.amazonaws.swf.base.model#UnknownResourceFault'
                },
                'UnknownResourceFault',
            )

            self.assertFalse(self.domain.exists)

    def test_domain_exists_with_whatever_error(self):
        with patch.object(self.domain.connection, 'describe_domain') as mock:
            with self.assertRaises(ResponseError):
                mock.side_effect = SWFResponseError(400, "mocking exception", {
                    '__type': 'WhateverError',
                    'message': 'Whatever'
                })
                dummy = self.domain.exists

    def test_domain_is_synced_with_unsynced_domain(self):
        pass

    def test_domain_is_synced_with_synced_domain(self):
        pass

    def test_domain_is_synced_over_non_existent_domain(self):
        with patch.object(Layer1, 'describe_domain', mock_describe_domain):
            domain = Domain("non-existent-domain")
            self.assertFalse(domain.is_synced)

    def test_domain_changes_with_different_domain(self):
        with patch.object(
                Layer1,
                'describe_domain',
                mock_describe_domain,
        ):
            domain = Domain("different-domain",
                            status=DEPRECATED,
                            description="blabla")
            diffs = domain.changes

            self.assertIsNotNone(diffs)
            self.assertEqual(len(diffs), 4)

            self.assertTrue(hasattr(diffs[0], 'attr'))
            self.assertTrue(hasattr(diffs[0], 'local'))
            self.assertTrue(hasattr(diffs[0], 'upstream'))

    def test_domain_changes_with_identical_domain(self):
        with patch.object(
                Layer1,
                'describe_domain',
                mock_describe_domain,
        ):
            mocked = mock_describe_domain()
            domain = Domain(mocked['domainInfo']['name'],
                            status=mocked['domainInfo']['status'],
                            description=mocked['domainInfo']['description'],
                            retention_period=mocked['configuration']
                            ['workflowExecutionRetentionPeriodInDays'])

            diffs = domain.changes

            self.assertEqual(len(diffs), 0)

    def test_domain_save_valid_domain(self):
        with patch.object(self.domain.connection, 'register_domain'):
            self.domain.save()

    def test_domain_save_already_existing_domain(self):
        with patch.object(self.domain.connection, 'register_domain') as mock:
            with self.assertRaises(AlreadyExistsError):
                mock.side_effect = SWFDomainAlreadyExistsError(
                    400, "mocking exception")
                self.domain.save()

    def test_domain_delete_existing_domain(self):
        with patch.object(self.domain.connection, 'deprecate_domain'):
            self.domain.delete()

    def test_domain_delete_non_existent_domain(self):
        with patch.object(self.domain.connection, 'deprecate_domain') as mock:
            with self.assertRaises(DomainDoesNotExist):
                mock.side_effect = SWFResponseError(
                    400,
                    "Bad Request",
                    {
                        'message':
                        'Unknown domain: does not exist',
                        '__type':
                        'com.amazonaws.swf.base.model#UnknownResourceFault'
                    },
                    'UnknownResourceFault',
                )
                self.domain.delete()

    def test_domain_workflows_without_existent_workflows(self):
        with patch.object(WorkflowTypeQuerySet, 'all') as all_method:
            all_method.return_value = []
            self.assertEqual(self.domain.workflows(), [])
Exemplo n.º 22
0
    def setUp(self):
        self.domain = Domain("testdomain")
        self.qs = DomainQuerySet(self)

        self.mocked_workflow_type_qs = Mock(spec=WorkflowTypeQuerySet)
        self.mocked_workflow_type_qs.all.return_value = []
Exemplo n.º 23
0
class TestDomain(unittest2.TestCase):
    def setUp(self):
        self.domain = Domain("testdomain")
        self.qs = DomainQuerySet(self)

        self.mocked_workflow_type_qs = Mock(spec=WorkflowTypeQuerySet)
        self.mocked_workflow_type_qs.all.return_value = []

    def tearDown(self):
        pass

    @patch.object(
        Layer1,
        '__init__',
        MiniMock(
            aws_access_key_id='test',
            aws_secret_access_key='test'
        )
    )
    def test_domain_inits_connection(self):
        self.assertTrue(hasattr(self.domain, 'connection'))
        self.assertTrue(hasattr(self.domain.connection, 'aws_access_key_id'))
        self.assertTrue(hasattr(self.domain.connection, 'aws_secret_access_key'))

    def test_domain__diff_with_different_domain(self):
        with patch.object(
            Layer1,
            'describe_domain',
            mock_describe_domain,
        ):
            domain = Domain(
                "different-domain",
                status=DEPRECATED,
                description="blabla"
            )
            diffs = domain._diff()

            self.assertIsNotNone(diffs)
            self.assertEqual(len(diffs), 4)

            self.assertTrue(hasattr(diffs[0], 'attr'))
            self.assertTrue(hasattr(diffs[0], 'local'))
            self.assertTrue(hasattr(diffs[0], 'upstream'))

    def test_domain__diff_with_identical_domain(self):
        with patch.object(
            Layer1,
            'describe_domain',
            mock_describe_domain,
        ):
            mocked = mock_describe_domain()
            domain = Domain(
                mocked['domainInfo']['name'],
                status=mocked['domainInfo']['status'],
                description=mocked['domainInfo']['description'],
                retention_period=mocked['configuration']['workflowExecutionRetentionPeriodInDays']
            )

            diffs = domain._diff()

            self.assertEqual(len(diffs), 0)

    def test_domain_exists_with_existing_domain(self):
        with patch.object(self.domain.connection, 'describe_domain'):
            self.assertTrue(self.domain.exists)

    def test_domain_exists_with_non_existent_domain(self):
        with patch.object(self.domain.connection, 'describe_domain') as mock:
            mock.side_effect = SWFResponseError(
                400,
                "Bad Request",
                {'message': 'Unknown domain: does not exist',
                 '__type': 'com.amazonaws.swf.base.model#UnknownResourceFault'},
                'UnknownResourceFault',
            )

            self.assertFalse(self.domain.exists)

    def test_domain_exists_with_whatever_error(self):
        with patch.object(self.domain.connection, 'describe_domain') as mock:
            with self.assertRaises(ResponseError):
                mock.side_effect = SWFResponseError(
                        400,
                        "mocking exception",
                        {
                            '__type': 'WhateverError',
                            'message': 'Whatever'
                        }
                )
                self.domain.exists

    def test_domain_is_synced_with_unsynced_domain(self):
        pass

    def test_domain_is_synced_with_synced_domain(self):
        pass

    def test_domain_is_synced_over_non_existent_domain(self):
        with patch.object(
            Layer1,
            'describe_domain',
            mock_describe_domain
        ):
            domain = Domain("non-existent-domain")
            self.assertFalse(domain.is_synced)

    def test_domain_changes_with_different_domain(self):
        with patch.object(
            Layer1,
            'describe_domain',
            mock_describe_domain,
        ):
            domain = Domain(
                "different-domain",
                status=DEPRECATED,
                description="blabla"
            )
            diffs = domain.changes

            self.assertIsNotNone(diffs)
            self.assertEqual(len(diffs), 4)

            self.assertTrue(hasattr(diffs[0], 'attr'))
            self.assertTrue(hasattr(diffs[0], 'local'))
            self.assertTrue(hasattr(diffs[0], 'upstream'))

    def test_domain_changes_with_identical_domain(self):
        with patch.object(
            Layer1,
            'describe_domain',
            mock_describe_domain,
        ):
            mocked = mock_describe_domain()
            domain = Domain(
                mocked['domainInfo']['name'],
                status=mocked['domainInfo']['status'],
                description=mocked['domainInfo']['description'],
                retention_period=mocked['configuration']['workflowExecutionRetentionPeriodInDays']
            )

            diffs = domain.changes

            self.assertEqual(len(diffs), 0)

    def test_domain_save_valid_domain(self):
        with patch.object(self.domain.connection, 'register_domain') as mock:
            self.domain.save()

    def test_domain_save_already_existing_domain(self):
        with patch.object(self.domain.connection, 'register_domain') as mock:
            with self.assertRaises(AlreadyExistsError):
                mock.side_effect = SWFDomainAlreadyExistsError(400, "mocking exception")
                self.domain.save()

    def test_domain_delete_existing_domain(self):
        with patch.object(self.domain.connection, 'deprecate_domain'):
            self.domain.delete()

    def test_domain_delete_non_existent_domain(self):
        with patch.object(self.domain.connection, 'deprecate_domain') as mock:
            with self.assertRaises(DomainDoesNotExist):
                mock.side_effect = SWFResponseError(
                    400,
                    "Bad Request",
                    {'message': 'Unknown domain: does not exist',
                     '__type': 'com.amazonaws.swf.base.model#UnknownResourceFault'},
                    'UnknownResourceFault',
                )
                self.domain.delete()

    def test_domain_workflows_without_existent_workflows(self):
        with patch.object(WorkflowTypeQuerySet, 'all') as all_method:
            all_method.return_value = []
            self.assertEquals(self.domain.workflows(), [])
Exemplo n.º 24
0
 def setUp(self):
     self.domain = Domain("test-domain")
     self.qs = DomainQuerySet()
Exemplo n.º 25
0
class TestDomain(unittest.TestCase):
    def setUp(self):
        self.domain = Domain("testdomain")
        self.qs = DomainQuerySet(self)

        self.mocked_workflow_type_qs = Mock(spec=WorkflowTypeQuerySet)
        self.mocked_workflow_type_qs.all.return_value = []

    def tearDown(self):
        pass

    @patch.object(
        Layer1,
        "__init__",
        MiniMock(aws_access_key_id="test", aws_secret_access_key="test"),
    )
    def test_domain_inits_connection(self):
        self.assertTrue(hasattr(self.domain, "connection"))
        self.assertTrue(hasattr(self.domain.connection, "aws_access_key_id"))
        self.assertTrue(hasattr(self.domain.connection, "aws_secret_access_key"))

    def test_domain__diff_with_different_domain(self):
        with patch.object(
            Layer1, "describe_domain", mock_describe_domain,
        ):
            domain = Domain("different-domain", status=DEPRECATED, description="blabla")
            diffs = domain._diff()

            self.assertIsNotNone(diffs)
            self.assertEqual(len(diffs), 4)

            self.assertTrue(hasattr(diffs[0], "attr"))
            self.assertTrue(hasattr(diffs[0], "local"))
            self.assertTrue(hasattr(diffs[0], "upstream"))

    def test_domain__diff_with_identical_domain(self):
        with patch.object(
            Layer1, "describe_domain", mock_describe_domain,
        ):
            mocked = mock_describe_domain()
            domain = Domain(
                mocked["domainInfo"]["name"],
                status=mocked["domainInfo"]["status"],
                description=mocked["domainInfo"]["description"],
                retention_period=mocked["configuration"][
                    "workflowExecutionRetentionPeriodInDays"
                ],
            )

            diffs = domain._diff()

            self.assertEqual(len(diffs), 0)

    def test_domain_exists_with_existing_domain(self):
        with patch.object(self.domain.connection, "describe_domain"):
            self.assertTrue(self.domain.exists)

    def test_domain_exists_with_non_existent_domain(self):
        with patch.object(self.domain.connection, "describe_domain") as mock:
            mock.side_effect = SWFResponseError(
                400,
                "Bad Request",
                {
                    "message": "Unknown domain: does not exist",
                    "__type": "com.amazonaws.swf.base.model#UnknownResourceFault",
                },
                "UnknownResourceFault",
            )

            self.assertFalse(self.domain.exists)

    def test_domain_exists_with_whatever_error(self):
        with patch.object(self.domain.connection, "describe_domain") as mock:
            with self.assertRaises(ResponseError):
                mock.side_effect = SWFResponseError(
                    400,
                    "mocking exception",
                    {"__type": "WhateverError", "message": "Whatever"},
                )
                dummy = self.domain.exists

    def test_domain_is_synced_with_unsynced_domain(self):
        pass

    def test_domain_is_synced_with_synced_domain(self):
        pass

    def test_domain_is_synced_over_non_existent_domain(self):
        with patch.object(Layer1, "describe_domain", mock_describe_domain):
            domain = Domain("non-existent-domain")
            self.assertFalse(domain.is_synced)

    def test_domain_changes_with_different_domain(self):
        with patch.object(
            Layer1, "describe_domain", mock_describe_domain,
        ):
            domain = Domain("different-domain", status=DEPRECATED, description="blabla")
            diffs = domain.changes

            self.assertIsNotNone(diffs)
            self.assertEqual(len(diffs), 4)

            self.assertTrue(hasattr(diffs[0], "attr"))
            self.assertTrue(hasattr(diffs[0], "local"))
            self.assertTrue(hasattr(diffs[0], "upstream"))

    def test_domain_changes_with_identical_domain(self):
        with patch.object(
            Layer1, "describe_domain", mock_describe_domain,
        ):
            mocked = mock_describe_domain()
            domain = Domain(
                mocked["domainInfo"]["name"],
                status=mocked["domainInfo"]["status"],
                description=mocked["domainInfo"]["description"],
                retention_period=mocked["configuration"][
                    "workflowExecutionRetentionPeriodInDays"
                ],
            )

            diffs = domain.changes

            self.assertEqual(len(diffs), 0)

    def test_domain_save_valid_domain(self):
        with patch.object(self.domain.connection, "register_domain"):
            self.domain.save()

    def test_domain_save_already_existing_domain(self):
        with patch.object(self.domain.connection, "register_domain") as mock:
            with self.assertRaises(AlreadyExistsError):
                mock.side_effect = SWFDomainAlreadyExistsError(400, "mocking exception")
                self.domain.save()

    def test_domain_delete_existing_domain(self):
        with patch.object(self.domain.connection, "deprecate_domain"):
            self.domain.delete()

    def test_domain_delete_non_existent_domain(self):
        with patch.object(self.domain.connection, "deprecate_domain") as mock:
            with self.assertRaises(DomainDoesNotExist):
                mock.side_effect = SWFResponseError(
                    400,
                    "Bad Request",
                    {
                        "message": "Unknown domain: does not exist",
                        "__type": "com.amazonaws.swf.base.model#UnknownResourceFault",
                    },
                    "UnknownResourceFault",
                )
                self.domain.delete()

    def test_domain_workflows_without_existent_workflows(self):
        with patch.object(WorkflowTypeQuerySet, "all") as all_method:
            all_method.return_value = []
            self.assertEqual(self.domain.workflows(), [])