def add_tag(run_id, tag_name, **kwargs): """ .. function:: XML-RPC TestRun.add_tag(run_id, tag) Add one tag to the specified test run. :param run_id: PK of TestRun to modify :type run_id: int :param tag_name: Tag name to add :type tag_name: str :return: Serialized list of :class:`tcms.management.models.Tag` objects :raises: PermissionDenied if missing *testruns.add_testruntag* permission :raises: TestRun.DoesNotExist if object specified by PK doesn't exist :raises: Tag.DoesNotExist if missing *management.add_tag* permission and *tag_name* doesn't exist in the database! """ request = kwargs.get(REQUEST_KEY) tag, _ = Tag.get_or_create(request.user, tag_name) test_run = TestRun.objects.get(pk=run_id) test_run.add_tag(tag) return Tag.to_xmlrpc({'pk__in': test_run.tag.all()})
def filter(query): # pylint: disable=redefined-builtin """ .. function:: RPC Tag.filter(query) Search and return a list of tags :param query: Field lookups for :class:`tcms.management.models.Tag` :type query: dict :return: Serialized list of :class:`tcms.management.models.Tag` objects :rtype: list(dict) """ return Tag.to_xmlrpc(query)
def add_tag(run_id, tag_name, **kwargs): """ .. function:: RPC TestRun.add_tag(run_id, tag) Add one tag to the specified test run. :param run_id: PK of TestRun to modify :type run_id: int :param tag_name: Tag name to add :type tag_name: str :param kwargs: Dict providing access to the current request, protocol entry point name and handler instance from the rpc method :return: Serialized list of :class:`tcms.management.models.Tag` objects :rtype: dict :raises: PermissionDenied if missing *testruns.add_testruntag* permission :raises: TestRun.DoesNotExist if object specified by PK doesn't exist :raises: Tag.DoesNotExist if missing *management.add_tag* permission and *tag_name* doesn't exist in the database! """ request = kwargs.get(REQUEST_KEY) tag, _ = Tag.get_or_create(request.user, tag_name) test_run = TestRun.objects.get(pk=run_id) test_run.add_tag(tag) return Tag.to_xmlrpc({"pk__in": test_run.tag.all()})
def test_casetags_are_shown_in_template(self): tag, _created = Tag.get_or_create(self.tester, 'Linux') self.case.add_tag(tag) url = reverse('testcases-all') response_data = urlencode({ 'from_plan': self.plan.pk, 'template_type': 'case', 'a': 'initial'}) # note: this is how the UI sends the request response = self.client.post(url, data=response_data, content_type='application/x-www-form-urlencoded; charset=UTF-8', HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEqual(HTTPStatus.OK, response.status_code) self.assertContains(response, _('Tags')) self.assertContains(response, '<a href="#testcases">Linux</a>')
def remove_tag(run_id, tag_name): """ .. function:: XML-RPC TestRun.remove_tag(run_id, tag) Remove a tag from the specified test run. :param run_id: PK of TestRun to modify :type run_id: int :param tag_name: Tag name to add :type tag_name: str :return: Serialized list of :class:`tcms.management.models.Tag` objects :raises: PermissionDenied if missing *testruns.delete_testruntag* permission :raises: DoesNotExist if objects specified don't exist """ tag = Tag.objects.get(name=tag_name) test_run = TestRun.objects.get(pk=run_id) test_run.remove_tag(tag) return Tag.to_xmlrpc({'pk__in': test_run.tag.all()})
def add_tag(bug_id, tag, **kwargs): """ .. function:: XML-RPC Bug.add_tag(bug_id, tag) Add one tag to the specified Bug. :param bug_id: PK of Bug to modify :type bug_id: int :param tag: Tag name to add :type tag: str :return: None :raises: PermissionDenied if missing *bugs.add_bugtag* permission :raises: Bug.DoesNotExist if object specified by PK doesn't exist :raises: Tag.DoesNotExist if missing *management.add_tag* permission and *tag* doesn't exist in the database! """ request = kwargs.get(REQUEST_KEY) tag, _ = Tag.get_or_create(request.user, tag) Bug.objects.get(pk=bug_id).tags.add(tag)
def add_tag(case_id, tag, **kwargs): """ .. function:: XML-RPC TestCase.add_tag(case_id, tag) Add one tag to the specified test case. :param case_id: PK of TestCase to modify :type case_id: int :param tag: Tag name to add :type tag: str :return: None :raises: PermissionDenied if missing *testcases.add_testcasetag* permission :raises: TestCase.DoesNotExist if object specified by PK doesn't exist :raises: Tag.DoesNotExist if missing *management.add_tag* permission and *tag* doesn't exist in the database! """ request = kwargs.get(REQUEST_KEY) tag, _ = Tag.get_or_create(request.user, tag) TestCase.objects.get(pk=case_id).add_tag(tag)
def add_tag(bug_id, tag, **kwargs): """ .. function:: RPC Bug.add_tag(bug_id, tag) Add one tag to the specified Bug. :param bug_id: PK of Bug to modify :type bug_id: int :param tag: Tag name to add :type tag: str :param kwargs: Dict providing access to the current request, protocol entry point name and handler instance from the rpc method :raises PermissionDenied: if missing *bugs.add_bug_tags* permission :raises Bug.DoesNotExist: if object specified by PK doesn't exist :raises Tag.DoesNotExist: if missing *management.add_tag* permission and *tag* doesn't exist in the database! """ request = kwargs.get(REQUEST_KEY) tag, _ = Tag.get_or_create(request.user, tag) Bug.objects.get(pk=bug_id).tags.add(tag)
def add_tag(plan_id, tag_name, **kwargs): """ .. function:: RPC TestPlan.add_tag(plan_id, tag_name) Add a tag to the specified test plan. :param plan_id: PK of TestPlan to modify :type plan_id: int :param tag_name: Tag name to add :type tag_name: str :param \\**kwargs: Dict providing access to the current request, protocol, entry point name and handler instance from the rpc method :raises PermissionDenied: if missing *testplans.add_testplantag* permission :raises TestPlan.DoesNotExist: if object specified by PK doesn't exist :raises Tag.DoesNotExist: if missing *management.add_tag* permission and *tag_name* doesn't exist in the database! """ request = kwargs.get(REQUEST_KEY) tag, _ = Tag.get_or_create(request.user, tag_name) TestPlan.objects.get(pk=plan_id).add_tag(tag)
def test_autocreate_new_tag(self): with self.assertRaises(Tag.DoesNotExist): Tag.get_or_create(self.tester, 'non-existing-tag-without-permission')
def test_get_existing_tag(self): tag, created = Tag.get_or_create(self.tester, self.existing_tag.name) self.assertEqual(tag.pk, self.existing_tag.pk) self.assertFalse(created)
def test_autocreate_new_tag(self): tag, created = Tag.get_or_create(self.tester, 'non-existing-autocreated-tag') self.assertNotEqual(tag.pk, self.existing_tag.pk) self.assertTrue(created)
def clean_tag(self): tags = [] if self.cleaned_data['tag']: tag_names = string_to_list(self.cleaned_data['tag']) tags = Tag.get_or_create_many_by_name(tag_names) return tags