示例#1
0
    def set_cache_timeout(cls, timeout):
        """Set the cache timeout for this object type.

        :param timeout:
            The timeout to set against this object type.
        """
        get_accessor().set_cache_timeout(cls.rally_name, timeout)
示例#2
0
文件: models.py 项目: lenciel/pyrally
    def set_cache_timeout(cls, timeout):
        """Set the cache timeout for this object type.

        :param timeout:
            The timeout to set against this object type.
        """
        get_accessor().set_cache_timeout(cls.rally_name, timeout)
示例#3
0
    def create_from_ref(cls, reference):
        """Create an instance of ``cls`` by getting data for ``reference``.

        :param reference:
            The full url reference to make an api call with.

        :returns:
            A populated :py:exc:`~pyrally.models.BaseRallyModel` inheriting
            instance which matches the reference.

        :raises:
            A :py:class:`~pyrally.models.ReferenceNotFoundException` if we get
            any error back from the API.
        """
        response = get_accessor().make_api_call(reference, True)
        errors = response.get('OperationResult', {'Errors': []}).get('Errors')
        if errors:
            msg = """
        Failure: {0}-{1}: {2}.
        If you called this directly, check that you've got the right reference
        number.
        Otherwise, it's highly likely that the reference was left hanging
        around in Rally after a delete (eg if a User was deleted).
        """.format(cls, reference, errors)
            raise ReferenceNotFoundException(msg)
        return cls(response[cls.rally_name])
示例#4
0
    def _get_results_page(cls, query_string, start_index=1):
        """
        Get a page of results for the query given.

        :param query_string:
            The string to get results for. If ``None``, or ``""``, no query
            is passed in and all objects for the class will be returned.

        :param start_index:
            The 1-based offset to fetch from. A pagesize of 100 is returned.

        :returns:
            The QueryResult entity as returned by the API, containing at most
            100 results.

        :raises:
            Exception if ['QueryResult']['Errors'] contains anything.
        """
        query_arg = ""
        if query_string:
            query_arg = "query=({0})&".format(query_string)

        url = "{0}.js?{1}pagesize=100&start={2}&fetch=true".format(
                        cls.rally_name.lower(), query_arg, start_index)

        query_result_dict = get_accessor().make_api_call(url)

        if query_result_dict['QueryResult']['Errors']:
            raise Exception('Errors in query: {0}'.format(
                             query_result_dict['QueryResult']['Errors']))
        return query_result_dict['QueryResult']
示例#5
0
文件: models.py 项目: lenciel/pyrally
    def _get_results_page(cls, query_string, start_index=1):
        """
        Get a page of results for the query given.

        :param query_string:
            The string to get results for. If ``None``, or ``""``, no query
            is passed in and all objects for the class will be returned.

        :param start_index:
            The 1-based offset to fetch from. A pagesize of 100 is returned.

        :returns:
            The QueryResult entity as returned by the API, containing at most
            100 results.

        :raises:
            Exception if ['QueryResult']['Errors'] contains anything.
        """
        query_arg = ""
        if query_string:
            query_arg = "query=({0})&".format(query_string)

        url = "{0}.js?{1}pagesize=100&start={2}&fetch=true".format(
            cls.rally_name.lower(), query_arg, start_index)

        query_result_dict = get_accessor().make_api_call(url)

        if query_result_dict['QueryResult']['Errors']:
            raise Exception('Errors in query: {0}'.format(
                query_result_dict['QueryResult']['Errors']))
        return query_result_dict['QueryResult']
示例#6
0
文件: models.py 项目: lenciel/pyrally
    def create_from_ref(cls, reference):
        """Create an instance of ``cls`` by getting data for ``reference``.

        :param reference:
            The full url reference to make an api call with.

        :returns:
            A populated :py:exc:`~pyrally.models.BaseRallyModel` inheriting
            instance which matches the reference.

        :raises:
            A :py:class:`~pyrally.models.ReferenceNotFoundException` if we get
            any error back from the API.
        """
        response = get_accessor().make_api_call(reference, True)
        errors = response.get('OperationResult', {'Errors': []}).get('Errors')
        if errors:
            msg = """
        Failure: {0}-{1}: {2}.
        If you called this directly, check that you've got the right reference
        number.
        Otherwise, it's highly likely that the reference was left hanging
        around in Rally after a delete (eg if a User was deleted).
        """.format(cls, reference, errors)
            raise ReferenceNotFoundException(msg)
        return cls(response[cls.rally_name])
示例#7
0
def test_get_accessor_returns_created_accessor_if_available(RallyAccessor,
                                                            ACCESSOR):
    """
    Test ``get_accessor`` returns created.

    Test that :py:func:`~pyrally.rally_access.get_accessor` returns the created
    accessor if it is available.
    """
    assert_equal(get_accessor(), ACCESSOR)
    assert_false(RallyAccessor.called)
示例#8
0
def test_get_accessor_returns_created_accessor_if_available(
        RallyAccessor, ACCESSOR):
    """
    Test ``get_accessor`` returns created.

    Test that :py:func:`~pyrally.rally_access.get_accessor` returns the created
    accessor if it is available.
    """
    assert_equal(get_accessor(), ACCESSOR)
    assert_false(RallyAccessor.called)
示例#9
0
def test_get_accessor_creates_accessor_if_not_already_created(RallyAccessor):
    """
    Test ``get_accessor`` returns created.

    Test that :py:func:`~pyrally.rally_access.get_accessor` creates
    and returns a :py:class:`~pyrally.rally_access.RallyAccessor` object if it
    has not already been created.
    """
    assert_equal(get_accessor('uname', 'pword', 'base_url'),
                 RallyAccessor.return_value)
    assert_equal(RallyAccessor.call_args[0], ('uname', 'pword', 'base_url'))
示例#10
0
def test_get_accessor_creates_accessor_if_not_already_created(RallyAccessor):
    """
    Test ``get_accessor`` returns created.

    Test that :py:func:`~pyrally.rally_access.get_accessor` creates
    and returns a :py:class:`~pyrally.rally_access.RallyAccessor` object if it
    has not already been created.
    """
    assert_equal(get_accessor('uname', 'pword', 'base_url'),
                 RallyAccessor.return_value)
    assert_equal(RallyAccessor.call_args[0], ('uname', 'pword', 'base_url'))
示例#11
0
        def get_results_page(query_string, start_index=1):
            query_arg = ""
            if query_string:
                query_arg = "query=({0})&".format(query_string)

            url = "{0}.js?{1}pagesize=100&start={2}&fetch=true".format(
                cls.rally_name.lower(), query_arg, start_index)
            query_result_dict = get_accessor().make_api_call(url)
            if query_result_dict['QueryResult']['Errors']:
                raise Exception('Errors in query: {0}'.format(
                    query_result_dict['QueryResult']['Errors']))
            return query_result_dict['QueryResult']
示例#12
0
        def get_results_page(query_string, start_index=1):
            query_arg = ""
            if query_string:
                query_arg = "query=({0})&".format(query_string)

            url = "{0}.js?{1}pagesize=100&start={2}&fetch=true".format(
                            cls.rally_name.lower(), query_arg, start_index)
            query_result_dict = get_accessor().make_api_call(url)
            if query_result_dict['QueryResult']['Errors']:
                raise Exception('Errors in query: {0}'.format(
                                 query_result_dict['QueryResult']['Errors']))
            return query_result_dict['QueryResult']
示例#13
0
 def delete(self):
     """Delete this object from Rally"""
     if not self.ref:
         raise Exception("Cannot delete item that is not synced with Rally."
                         " If you've just created this item try running"
                         "update_rally().")
     response = get_accessor().make_api_call(self.ref, True,
                                             method='DELETE')
     if response['OperationResult']['Errors']:
         raise Exception('Errors in delete: {0}'.format(
                              response['OperationResult']['Errors']))
     self.delete_from_cache()
示例#14
0
文件: models.py 项目: lenciel/pyrally
 def delete(self):
     """Delete this object from Rally"""
     if not self.ref:
         raise Exception("Cannot delete item that is not synced with Rally."
                         " If you've just created this item try running"
                         "update_rally().")
     response = get_accessor().make_api_call(self.ref,
                                             True,
                                             method='DELETE')
     if response['OperationResult']['Errors']:
         raise Exception('Errors in delete: {0}'.format(
             response['OperationResult']['Errors']))
     self.delete_from_cache()
示例#15
0
 def create_from_ref(cls, reference):
     response = get_accessor().make_api_call(reference, True)
     errors = response.get('OperationResult', {'Errors': []}).get('Errors')
     if errors:
         msg = """
     Failure: {0}-{1}: {2}.
     If you called this directly, check that you've got the right reference
     number.
     Otherwise, it's highly likely that the reference was left hanging
     around in Rally after a delete (eg if a User was deleted).
     """.format(cls, reference, errors)
         raise ReferenceNotFoundException(msg)
     return cls(response[cls.rally_name])
示例#16
0
 def create_from_ref(cls, reference):
     response = get_accessor().make_api_call(reference, True)
     errors = response.get('OperationResult', {'Errors': []}).get('Errors')
     if errors:
         msg = """
     Failure: {0}-{1}: {2}.
     If you called this directly, check that you've got the right reference
     number.
     Otherwise, it's highly likely that the reference was left hanging
     around in Rally after a delete (eg if a User was deleted).
     """.format(cls, reference, errors)
         raise ReferenceNotFoundException(msg)
     return cls(response[cls.rally_name])
示例#17
0
    def update_rally(self, refresh=True):
        """Update or create ``self`` on Rally.

        If there is no sign of a _ref internally, a create is sent,
        otherwise an update is sent.

        :param refresh:
            Used on creates. If ``True`` a fetch is performed after the object
            is created in Rally and ``self`` is populated with the new data.

        :returns:
            The response from the server.
        """
        if self.ref:
            # Do update
            data = {self.rally_name: self.rally_data}
            response = get_accessor().make_api_call(self.ref,
                                                    True,
                                                    method='POST',
                                                    data=data)
            if response['OperationResult']['Errors']:
                raise Exception('Errors in query: {0}'.format(
                                 response['OperationResult']['Errors']))
        else:
            data = {self.rally_name: self.rally_data}
            url = "{0}/create.js".format(self.rally_name.lower())
            response = get_accessor().make_api_call(url,
                                                    method='POST',
                                                    data=data)
            if response['CreateResult']['Errors']:
                raise Exception('Errors in query: {0}'.format(
                                 response['CreateResult']['Errors']))
            reference = response['CreateResult']['Object']['_ref']
            if refresh:
                self.delete_from_cache()
                new_data = get_accessor().make_api_call(reference, True)
                self.rally_data = new_data[self.rally_name]
        return response
示例#18
0
文件: models.py 项目: lenciel/pyrally
    def update_rally(self, refresh=True):
        """Update or create ``self`` on Rally.

        If there is no sign of a _ref internally, a create is sent,
        otherwise an update is sent.

        :param refresh:
            Used on creates. If ``True`` a fetch is performed after the object
            is created in Rally and ``self`` is populated with the new data.

        :returns:
            The response from the server.
        """
        if self.ref:
            # Do update
            data = {self.rally_name: self.rally_data}
            response = get_accessor().make_api_call(self.ref,
                                                    True,
                                                    method='POST',
                                                    data=data)
            if response['OperationResult']['Errors']:
                raise Exception('Errors in query: {0}'.format(
                    response['OperationResult']['Errors']))
        else:
            data = {self.rally_name: self.rally_data}
            url = "{0}/create.js".format(self.rally_name.lower())
            response = get_accessor().make_api_call(url,
                                                    method='POST',
                                                    data=data)
            if response['CreateResult']['Errors']:
                raise Exception('Errors in query: {0}'.format(
                    response['CreateResult']['Errors']))
            reference = response['CreateResult']['Object']['_ref']
            if refresh:
                self.delete_from_cache()
                new_data = get_accessor().make_api_call(reference, True)
                self.rally_data = new_data[self.rally_name]
        return response
示例#19
0
 def delete_from_cache(self):
     """Remove this item from the cache"""
     get_accessor().delete_from_cache(self.rally_name, self.ref)
示例#20
0
文件: client.py 项目: nedy13/pyrally
 def __init__(self, username=None, password=None, base_url=None, apikey=None):
     self.rally_access = get_accessor(username, password, base_url, apikey)
示例#21
0
文件: models.py 项目: lenciel/pyrally
 def delete_from_cache(self):
     """Remove this item from the cache"""
     get_accessor().delete_from_cache(self.rally_name, self.ref)
示例#22
0
文件: models.py 项目: lenciel/pyrally
 def rally_url(self):
     defect_id = self.ref.split('/')[-1].replace('.js', '')
     base_url = get_accessor().base_url
     url = "{0}slm/rally.sp#/detail/defect/{1}".format(base_url, defect_id)
     return url
示例#23
0
 def rally_url(self):
     defect_id = self.ref.split('/')[-1].replace('.js', '')
     base_url = get_accessor().base_url
     url = "{0}slm/rally.sp#/detail/defect/{1}".format(base_url,
                                                          defect_id)
     return url
示例#24
0
 def __init__(self, username, password):
     self.rally_access = get_accessor(username, password)
示例#25
0
 def __init__(self, username, password, base_url):
     self.rally_access = get_accessor(username, password, base_url)