コード例 #1
0
ファイル: views.py プロジェクト: reviewboard/rbintegrations
    def get(self, request, **kwargs):
        """Perform a search for tasks.

        Args:
            request (django.http.HttpRequest):
                The request.

            **kwargs (dict):
                Additional keyword arguments.

        Returns:
            django.http.HttpResponse:
            A response containing JSON with a list of tasks matching the
            search criteria.
        """
        from rbintegrations.asana.integration import AsanaIntegration

        integration_manager = get_integration_manager()
        integration = integration_manager.get_integration(
            AsanaIntegration.integration_id)

        configs = (
            config
            for config in integration.get_configs(
                self.review_request.local_site)
            if config.match_conditions(form_cls=integration.config_form_cls,
                                       review_request=self.review_request)
        )

        results = []

        params = {
            'type': 'task',
            'query': request.GET.get('q'),
            'count': 20,
            'opt_fields': ['completed', 'name', 'notes'],
        }

        for config in configs:
            try:
                client = asana.Client.access_token(
                    config.settings['asana_access_token'])

                workspace = config.settings['asana_workspace']

                results.append({
                    'workspace': config.settings['asana_workspace_name'],
                    'workspace_id': workspace,
                    'tasks': list(
                        client.workspaces.typeahead(workspace, params)),
                })
            except Exception as e:
                logger.exception('Unexpected error when searching for Asana '
                                 'tasks: %s',
                                 e)

        return HttpResponse(json.dumps(results),
                            content_type='application/json')
コード例 #2
0
ファイル: testcases.py プロジェクト: xiaohanc/rbintegrations
    def setUp(self):
        super(IntegrationTestCase, self).setUp()

        integration_mgr = get_integration_manager()

        self.integration = integration_mgr.get_integration(
            self.integration_cls.integration_id)

        integration_mgr.clear_all_configs_cache()
コード例 #3
0
ファイル: test_views.py プロジェクト: chipx86/reviewboard
    def setUp(self):
        super(AdminIntegrationConfigFormViewTests, self).setUp()

        self.integration = MyIntegration(get_integration_manager())
        self.config = IntegrationConfig()
        self.request = RequestFactory().request()

        # NOTE: integration and config are normally set in dispatch(), but
        #       we're not calling into all that, so we're taking advantage of
        #       the fact that Django's class-based generic views will set any
        #       attribute passed in during construction.
        self.view = AdminIntegrationConfigFormView(
            request=self.request,
            integration=self.integration,
            config=self.config)
コード例 #4
0
ファイル: test_views.py プロジェクト: zhengxx25/reviewboard
    def setUp(self):
        super(AdminIntegrationConfigFormViewTests, self).setUp()

        self.integration = MyIntegration(get_integration_manager())
        self.config = IntegrationConfig()
        self.request = RequestFactory().request()

        # NOTE: integration and config are normally set in dispatch(), but
        #       we're not calling into all that, so we're taking advantage of
        #       the fact that Django's class-based generic views will set any
        #       attribute passed in during construction.
        self.view = AdminIntegrationConfigFormView(
            request=self.request,
            integration=self.integration,
            config=self.config)
コード例 #5
0
ファイル: fields.py プロジェクト: reviewboard/rbintegrations
    def should_render(self):
        """Whether the field should render or not.

        This field is only shown if there are any matching configs.
        """
        from rbintegrations.asana.integration import AsanaIntegration

        integration_manager = get_integration_manager()
        integration = integration_manager.get_integration(
            AsanaIntegration.integration_id)
        review_request = self.review_request_details.get_review_request()

        for config in integration.get_configs(review_request.local_site):
            if config.match_conditions(form_cls=integration.config_form_cls,
                                       review_request=review_request):
                return True

        return False
コード例 #6
0
ファイル: fields.py プロジェクト: reviewboard/rbintegrations
    def should_render(self):
        """Whether the field should render or not.

        The Trello Cards field renders when there are any matching
        integration configs for the current review request.
        """
        from rbintegrations.trello.integration import TrelloIntegration

        integration_manager = get_integration_manager()
        integration = integration_manager.get_integration(
            TrelloIntegration.integration_id)
        review_request = self.review_request_details.get_review_request()

        for config in integration.get_configs(review_request.local_site):
            if config.match_conditions(form_cls=integration.config_form_cls,
                                       review_request=review_request):
                return True

        return False
コード例 #7
0
    def setUp(self):
        super(IntegrationConfigFormTests, self).setUp()

        self.local_site_1 = LocalSite.objects.create(name='site1')
        self.local_site_2 = LocalSite.objects.create(name='site2')

        self.manager = get_integration_manager()
        self.integration = \
            self.manager.register_integration_class(MyIntegration)

        self.request = RequestFactory().request()
        self.request.user = User.objects.create(username='******')

        self.local_site_1_group = self.create_review_group(
            name='local-site-1-group', local_site=self.local_site_1)

        self.local_site_2_group = self.create_review_group(
            name='local-site-2-group', local_site=self.local_site_2)

        self.global_site_group = self.create_review_group(
            name='global-site-group')
コード例 #8
0
ファイル: test_forms.py プロジェクト: chipx86/reviewboard
    def setUp(self):
        super(IntegrationConfigFormTests, self).setUp()

        self.local_site_1 = LocalSite.objects.create(name='site1')
        self.local_site_2 = LocalSite.objects.create(name='site2')

        self.manager = get_integration_manager()
        self.integration = \
            self.manager.register_integration_class(MyIntegration)

        self.request = RequestFactory().request()
        self.request.user = User.objects.create(username='******')

        self.local_site_1_group = self.create_review_group(
            name='local-site-1-group',
            local_site=self.local_site_1)

        self.local_site_2_group = self.create_review_group(
            name='local-site-2-group',
            local_site=self.local_site_2)

        self.global_site_group = self.create_review_group(
            name='global-site-group')
コード例 #9
0
ファイル: test_forms.py プロジェクト: younghank/reviewboard
    def setUp(self):
        super(IntegrationConfigFormTests, self).setUp()

        self.integration = MyIntegration(get_integration_manager())
        self.request = RequestFactory().request()
コード例 #10
0
ファイル: test_forms.py プロジェクト: darmhoo/reviewboard
    def setUp(self):
        super(IntegrationConfigFormTests, self).setUp()

        self.integration = MyIntegration(get_integration_manager())
        self.request = RequestFactory().request()