예제 #1
0
    def all_organizations(self):
        """Get all organizations.

        :return: Tuple of status request and list of organizations
                  (if request failed return failure messages).
        :rtype: (bool, list/str)
        """
        network = NetworkMixin(get_url_instance() + self.api_url)
        return self._call_api(network, paginated=True)
 def test_network_mixin_get(self):
     """Test network mixin get"""
     request_url = 'http://jsonplaceholder.typicode.com/posts/1'
     manager = NetworkMixin(request_url=request_url)
     manager.connect_get()
     while not manager.is_finished():
         QCoreApplication.processEvents()
     self.assertIsNotNone(manager.get_json_results())
     self.assertEqual(manager.get_json_results()['userId'],
                      self.api_results['userId'])
예제 #3
0
    def summary_organization(self, slug):
        """Get detail summary organization.

        :param slug: organization slug
        :type slug: str

        :return: Tuple of status request and summary of organization
                  (if request failed return failure messages).
        :rtype: (bool, dict/str)
        """
        if not slug:
            return False, None
        network = NetworkMixin(get_url_instance() + self.api_url + slug + '/')
        return self._call_api(network)
예제 #4
0
    def organizations_project_filtered(self, permissions=None):
        """Get organizations with permission to list and add project.

        :return: Tuple of status request and list of organizations
                  (if request failed return failure messages).
        :rtype: (bool, list/str)
        """
        if not permissions:
            filter_permissions = '?permissions=project.create,project.list'
        else:
            filter_permissions = '?permissions=' + permissions
        network = NetworkMixin(get_url_instance() + self.api_url +
                               filter_permissions)
        return self._call_api(network, paginated=True)
    def test_network_mixin_post(self):
        """Test network mixin post"""
        request_url = 'http://jsonplaceholder.typicode.com/posts'

        post_data = QByteArray()
        post_data.append("title=%s&" % self.api_results['title'])
        post_data.append("body=%s&" % self.api_results['body'])
        post_data.append("userId=%d&" % self.api_results['userId'])

        manager = NetworkMixin(request_url=request_url)
        manager.connect_post(post_data)
        while not manager.is_finished():
            QCoreApplication.processEvents()
        self.assertIsNotNone(manager.get_json_results())
        self.assertEqual(manager.get_json_results()['userId'],
                         self.api_results['userId'])
        self.assertEqual(manager.get_json_results()['body'],
                         self.api_results['body'])
    def send_update_request(self, post_data):
        """Send update request to server and return the responses

        :param post_data: Data to post
        :type post_data: json string

        :returns: Tuple of request status and error message
        :rtype: ( bool, str )
        """
        update_url = '/api/v1/organizations/%s/projects/%s/' % (
            self.project['organization']['slug'], self.project['slug'])
        network = NetworkMixin(get_url_instance() + update_url)
        network.connect_json_patch(json.dumps(post_data))
        while not network.is_finished():
            QCoreApplication.processEvents()

        if not network.error:
            return True, network.get_json_results()
        else:
            return False, \
                   '{"code" : %s, "result": %s}' % (
                       str(network.http_code), network.results.data()
                   )