Пример #1
0
    def __init__(self, swimlane, raw):
        super(Comment, self).__init__(swimlane, raw)

        self.user = UserGroup(swimlane, self._raw['createdByUser'])
        self.created_date = pendulum.parse(self._raw['createdDate'])
        self.message = self._raw['message']
        self.is_rich_text = self._raw.get('isRichText', False)
Пример #2
0
    def __init__(self, swimlane, raw):
        super(RevisionBase, self).__init__(swimlane, raw)

        self.modified_date = pendulum.parse(self._raw['modifiedDate'])
        self.revision_number = self._raw['revisionNumber']
        self.status = self._raw['status']

        # UserGroupSelection, can't set as User without additional lookup
        self.user = UserGroup(self._swimlane, self._raw['userId'])

        self._raw_version = self._raw['version']
        self._version = None
Пример #3
0
    def __init__(self, record, raw):
        super(Revision, self).__init__(record._swimlane, raw)

        self.record = record

        self.modified_date = pendulum.parse(self._raw['modifiedDate'])
        self.revision_number = int(self._raw['revisionNumber'])
        self.status = self._raw['status']

        # UserGroupSelection, can't set as User without additional lookup
        self.user = UserGroup(self._swimlane, self._raw['userId'])

        # Avoid circular imports
        from swimlane.core.resources.record import Record
        self.version = Record(self.record.app, self._raw['version'])
Пример #4
0
class Comment(APIResource):
    """Abstraction of a single comment from a comment field

    Attributes:
        user (UserGroup): UserGroup instance of user who created the comment
        created_date (pendulum.DateTime): Pendulum datetime of when comment was created
        message (str): Comment message body
    """

    def __init__(self, swimlane, raw):
        super(Comment, self).__init__(swimlane, raw)

        self.user = UserGroup(swimlane, self._raw['createdByUser'])
        self.created_date = pendulum.parse(self._raw['createdDate'])
        self.message = self._raw['message']
        self.is_rich_text = self._raw.get('isRichText', False)

    def __str__(self):
        return self.message

    def for_json(self):
        """Called by CommentField.for_json(), returns relevant Comment attributes in JSON-compatible format"""
        return {
            'message': self.message,
            'createdDate': self._raw['createdDate'],
            'createdByUser': self.user.for_json()
        }
Пример #5
0
class Revision(APIResource):
    """Encapsulates a single revision returned from a History lookup"""
    def __init__(self, record, raw):
        super(Revision, self).__init__(record._swimlane, raw)

        self.record = record

        self.modified_date = pendulum.parse(self._raw['modifiedDate'])
        self.revision_number = int(self._raw['revisionNumber'])
        self.status = self._raw['status']

        # UserGroupSelection, can't set as User without additional lookup
        self.user = UserGroup(self._swimlane, self._raw['userId'])

        # Avoid circular imports
        from swimlane.core.resources.record import Record
        self.version = Record(self.record.app, self._raw['version'])

    def __str__(self):
        return '{} ({})'.format(self.version, self.revision_number)

    def for_json(self):
        """Return revision metadata"""
        return {
            'modifiedDate': self._raw['modifiedDate'],
            'revisionNumber': self.revision_number,
            'user': self.user.for_json()
        }
Пример #6
0
    def cast_to_python(self, value):
        """Convert JSON definition to UserGroup object"""
        # v2.x does not provide a distinction between users and groups at the field selection level, can only return
        # UserGroup instances instead of specific User or Group instances
        if value is not None:
            value = UserGroup(self._swimlane, value)

        return value
Пример #7
0
 def test_constructor(self, mock_swimlane, mock_rr_record_revision, mock_rr_raw_record_revision):
     assert mock_rr_record_revision.app_revision_number is mock_rr_raw_record_revision['version'][
         'applicationRevision']
     assert str(mock_rr_record_revision.modified_date) == str(
         pendulum.parse(mock_rr_raw_record_revision['modifiedDate']))
     assert mock_rr_record_revision.revision_number is mock_rr_raw_record_revision['revisionNumber']
     assert mock_rr_record_revision.status is mock_rr_raw_record_revision['status']
     assert str(mock_rr_record_revision.user) == str(UserGroup(mock_swimlane, mock_rr_raw_record_revision['userId']))
Пример #8
0
class RevisionBase(APIResource):
    """
    The base class representing a single revision returned from a History lookup.

    Attributes:
        Attributes:
        modified_date: The date this revision was created.
        revision_number: The revision number of this revision.
        status: Indicates whether this revision is the current revision or a historical revision.
        user: The user that saved this revision.
    """
    def __init__(self, swimlane, raw):
        super(RevisionBase, self).__init__(swimlane, raw)

        self.modified_date = pendulum.parse(self._raw['modifiedDate'])
        self.revision_number = self._raw['revisionNumber']
        self.status = self._raw['status']

        # UserGroupSelection, can't set as User without additional lookup
        self.user = UserGroup(self._swimlane, self._raw['userId'])

        self._raw_version = self._raw['version']
        self._version = None

    def __str__(self):
        return '{} ({})'.format(self.version, self.revision_number)

    @property
    def version(self):
        raise NotImplementedError

    def for_json(self):
        """Return revision metadata"""
        return {
            'modifiedDate': self._raw['modifiedDate'],
            'revisionNumber': self.revision_number,
            'user': self.user.for_json()
        }
def test_resolve(mock_swimlane, mock_user, mock_group):
    """Test resolving a generic UserGroup to more specific type"""
    ug_user = UserGroup(mock_user._swimlane, mock_user._raw)
    ug_group = UserGroup(mock_group._swimlane, mock_group._raw)

    # Test resolve is no-op when already resolved
    for ug in (mock_user, mock_group):
        assert ug.resolve() is ug

    with patch.object(mock_swimlane.users, 'get') as mock_user_get:
        with patch.object(mock_swimlane.groups, 'get') as mock_group_get:
            mock_group_get.return_value = mock_group
            mock_user_get.return_value = mock_user

            assert ug_user.resolve() is mock_user

            mock_user_get.side_effect = ValueError

            assert ug_group.resolve() is mock_group
Пример #10
0
 def restrictions(self):
     """Returns cached set of retrieved UserGroups in the record's list of allowed accounts"""
     return [UserGroup(self._swimlane, raw) for raw in self._raw['allowed']]
Пример #11
0
    def __init__(self, swimlane, raw):
        super(Comment, self).__init__(swimlane, raw)

        self.user = UserGroup(swimlane, self._raw['createdByUser'])
        self.created_date = pendulum.parse(self._raw['createdDate'])
        self.message = self._raw['message']