Example #1
0
    def activities(self, status=REGISTERED):
        """Lists the current domain's activity types

        :param      status: Specifies the registration status of the
                            workflow types to list. Valid values are:
                            * swf.constants.REGISTERED
                            * swf.constants.DEPRECATED
        :type       status: string
        """
        from swf.querysets.activity import ActivityTypeQuerySet
        qs = ActivityTypeQuerySet(self)
        return qs.all(registration_status=status)
Example #2
0
    def activities(self, status=REGISTERED):
        """Lists the current domain's activity types

        :param      status: Specifies the registration status of the
                            workflow types to list. Valid values are:
                            * swf.constants.REGISTERED
                            * swf.constants.DEPRECATED
        :type       status: string
        """
        from swf.querysets.activity import ActivityTypeQuerySet
        qs = ActivityTypeQuerySet(self)
        return qs.all(registration_status=status)
Example #3
0
    def test_get_domain_property_instantiates_private_attribute(self):
        """Assert .__init__() instantiate _domain private attr"""
        bw = ActivityTypeQuerySet(self.domain)
        delattr(bw, "_domain")
        dummy = bw.domain

        self.assertTrue(hasattr(bw, "_domain"))
Example #4
0
 def upstream(self):
     from swf.querysets.activity import ActivityTypeQuerySet
     qs = ActivityTypeQuerySet(self.domain)
     return qs.get(self.name, self.version)
Example #5
0
 def test_instantiation_with_invalid_domain(self):
     """Assert instantiation with invalid domain raises"""
     with self.assertRaises(TypeError):
         # noinspection PyTypeChecker
         ActivityTypeQuerySet("WrongType")
Example #6
0
    def test_instantiation_with_valid_domain(self):
        """Assert instantiation with valid domain object"""
        bw = ActivityTypeQuerySet(self.domain)

        self.assertIsInstance(bw.domain, Domain)
        self.assertEqual(bw._domain, bw.domain)
Example #7
0
 def setUp(self):
     self.domain = Domain("TestDomain")
     self.atq = ActivityTypeQuerySet(self.domain)
Example #8
0
class TestActivityTypeQuerySet(unittest.TestCase):
    def setUp(self):
        self.domain = Domain("TestDomain")
        self.atq = ActivityTypeQuerySet(self.domain)

    def tearDown(self):
        pass

    def test_get_domain_property_instantiates_private_attribute(self):
        """Assert .__init__() instantiate _domain private attr"""
        bw = ActivityTypeQuerySet(self.domain)
        delattr(bw, "_domain")
        dummy = bw.domain

        self.assertTrue(hasattr(bw, "_domain"))

    def test_get_or_create_existing_activity_type(self):
        with patch.object(Layer1, "describe_activity_type",
                          mock_describe_activity_type):
            activity_type = self.atq.get_or_create("TestActivityType",
                                                   "testversion")

            self.assertIsInstance(activity_type, ActivityType)

    def test_get_or_create_non_existent_activity_type(self):
        with patch.object(Layer1, "describe_activity_type") as mock:
            mock.side_effect = DoesNotExistError("Mocked exception")

            with patch.object(Layer1, "register_activity_type",
                              mock_describe_activity_type):
                activity_type = self.atq.get_or_create("TestDomain",
                                                       "testversion")

                self.assertIsInstance(activity_type, ActivityType)

    def test_instantiation_with_valid_domain(self):
        """Assert instantiation with valid domain object"""
        bw = ActivityTypeQuerySet(self.domain)

        self.assertIsInstance(bw.domain, Domain)
        self.assertEqual(bw._domain, bw.domain)

    def test_instantiation_with_invalid_domain(self):
        """Assert instantiation with invalid domain raises"""
        with self.assertRaises(TypeError):
            # noinspection PyTypeChecker
            ActivityTypeQuerySet("WrongType")

    def test_all(self):
        """Asserts .all() method returns a list of valid Activity instances"""
        with patch.object(
                self.atq.connection,
                "list_activity_types",
                mock_list_activity_types,
        ):
            activities = self.atq.all()

            self.assertIsNotNone(activities)
            self.assertIsInstance(activities, list)

            for activity in activities:
                self.assertIsInstance(activity, ActivityType)

    def test_get_existent_activity_type(self):
        """Assert .get() method with valid params returns the asked ActivityType model"""
        with patch.object(self.atq.connection, "describe_activity_type",
                          mock_describe_activity_type):
            activity = self.atq.get("mocked-activity-type", "0.1")

            self.assertIsNotNone(activity)
            self.assertIsInstance(activity, ActivityType)

    def test_get_with_failing_activity_type(self):
        """Asserts get method over a failing activity type raises"""
        with patch.object(self.atq.connection,
                          "describe_activity_type") as mock:
            with self.assertRaises(ResponseError):
                mock.side_effect = SWFResponseError(
                    400, "mocking exception",
                    {"__type": "UnrecognizedClientException"})

                self.atq.get("mocked-failing-activity-type", "0.1")

    def test_get_with_non_existent_name(self):
        """Asserts get method with non existent activity type name provided raises"""
        with patch.object(self.atq.connection,
                          "describe_activity_type") as mock:
            with self.assertRaises(DoesNotExistError):
                mock.side_effect = SWFResponseError(
                    400, "mocking exception",
                    {"__type": "UnknownResourceFault"})
                self.atq.get("mocked-non-existent-activity-type-name", "0.1")

    def test_get_with_non_existent_version(self):
        """Asserts get method with non existent activity type version provided raises"""
        with patch.object(self.atq.connection,
                          "describe_activity_type") as mock:
            with self.assertRaises(DoesNotExistError):
                mock.side_effect = SWFResponseError(
                    400, "mocking exception",
                    {"__type": "UnknownResourceFault"})
                self.atq.get("mocked-non-existent-activity-type-name", "na")

    def test_create(self):
        with patch.object(Layer1, "register_activity_type"):
            new_activity_type = ActivityType(self.domain, "TestActivityType",
                                             "0.test")

            self.assertIsNotNone(new_activity_type)
            self.assertIsInstance(new_activity_type, ActivityType)
Example #9
0
 def upstream(self):
     from swf.querysets.activity import ActivityTypeQuerySet
     qs = ActivityTypeQuerySet(self.domain)
     return qs.get(self.name, self.version)
Example #10
0
 def setUp(self):
     self.domain = Domain("TestDomain")
     self.atq = ActivityTypeQuerySet(self.domain)
Example #11
0
class TestActivityTypeQuerySet(unittest.TestCase):

    def setUp(self):
        self.domain = Domain("TestDomain")
        self.atq = ActivityTypeQuerySet(self.domain)

    def tearDown(self):
        pass

    def test_get_domain_property_instantiates_private_attribute(self):
        """Assert .__init__() instantiate _domain private attr"""
        bw = ActivityTypeQuerySet(self.domain)
        delattr(bw, '_domain')
        dummy = bw.domain

        self.assertTrue(hasattr(bw, '_domain'))

    def test_get_or_create_existing_activity_type(self):
        with patch.object(Layer1, 'describe_activity_type', mock_describe_activity_type):
            activity_type = self.atq.get_or_create("TestActivityType", "testversion")

            self.assertIsInstance(activity_type, ActivityType)

    def test_get_or_create_non_existent_activity_type(self):
        with patch.object(Layer1, 'describe_activity_type') as mock:
            mock.side_effect = DoesNotExistError("Mocked exception")

            with patch.object(Layer1, 'register_activity_type', mock_describe_activity_type):
                activity_type = self.atq.get_or_create("TestDomain", "testversion")

                self.assertIsInstance(activity_type, ActivityType)

    def test_instantiation_with_valid_domain(self):
        """Assert instantiation with valid domain object"""
        bw = ActivityTypeQuerySet(self.domain)

        self.assertIsInstance(bw.domain, Domain)
        self.assertEqual(bw._domain, bw.domain)

    def test_instantiation_with_invalid_domain(self):
        """Assert instantiation with invalid domain raises"""
        with self.assertRaises(TypeError):
            # noinspection PyTypeChecker
            ActivityTypeQuerySet("WrongType")

    def test_all(self):
        """Asserts .all() method returns a list of valid Activity instances"""
        with patch.object(
            self.atq.connection,
            'list_activity_types',
            mock_list_activity_types,
        ):
            activities = self.atq.all()

            self.assertIsNotNone(activities)
            self.assertIsInstance(activities, list)

            for activity in activities:
                self.assertIsInstance(activity, ActivityType)

    def test_get_existent_activity_type(self):
        """Assert .get() method with valid params returns the asked ActivityType model"""
        with patch.object(
            self.atq.connection,
            'describe_activity_type',
            mock_describe_activity_type
        ):
            activity = self.atq.get('mocked-activity-type', '0.1')

            self.assertIsNotNone(activity)
            self.assertIsInstance(activity, ActivityType)

    def test_get_with_failing_activity_type(self):
        """Asserts get method over a failing activity type raises"""
        with patch.object(self.atq.connection, 'describe_activity_type') as mock:
            with self.assertRaises(ResponseError):
                mock.side_effect = SWFResponseError(
                    400,
                    'mocking exception',
                    {'__type': 'UnrecognizedClientException'}
                )

                self.atq.get('mocked-failing-activity-type', '0.1')

    def test_get_with_non_existent_name(self):
        """Asserts get method with non existent activity type name provided raises"""
        with patch.object(self.atq.connection, 'describe_activity_type') as mock:
            with self.assertRaises(DoesNotExistError):
                mock.side_effect = SWFResponseError(
                    400,
                    'mocking exception',
                    {'__type': 'UnknownResourceFault'}
                )
                self.atq.get('mocked-non-existent-activity-type-name', '0.1')

    def test_get_with_non_existent_version(self):
        """Asserts get method with non existent activity type version provided raises"""
        with patch.object(self.atq.connection, 'describe_activity_type') as mock:
            with self.assertRaises(DoesNotExistError):
                mock.side_effect = SWFResponseError(
                    400,
                    'mocking exception',
                    {'__type': 'UnknownResourceFault'}
                )
                self.atq.get('mocked-non-existent-activity-type-name', 'na')

    def test_create(self):
        with patch.object(Layer1, 'register_activity_type'):
            new_activity_type = ActivityType(
                self.domain,
                "TestActivityType",
                "0.test"
            )

            self.assertIsNotNone(new_activity_type)
            self.assertIsInstance(new_activity_type, ActivityType)