def get_tags(request, values): """Get tags by ID or name. :param dict values: a mapping containing these criteria. * ids: (list[int]) list of tag IDs. * names: (list[str]) list of names. :return: a list of mappings of :class:`TestTag`. :rtype: list Example:: >>> Tag.get_tags({'ids': [121, 123]}) """ if not isinstance(values, dict): raise TypeError('Argument values must be an dictionary.') if values.get('ids'): query = {'id__in': values.get('ids')} return TestTag.to_xmlrpc(query) elif values.get('names'): query = {'name__in': values.get('names')} return TestTag.to_xmlrpc(query) else: raise ValueError('Must specify ids or names at least.')
def get_tags(request, values): """ Description: Get the list of tags. Params: $values - Hash: keys must match valid search fields. +------------------------------------------------------------+ | tag Search Parameters | +------------------------------------------------------------+ | Key | Valid Values | | ids | List of Integer | | names | List of String | +------------------------------------------------------------+ Returns: Array: An array of tag object hashes. Example: >>> values= {'ids': [121, 123]} >>> Tag.get_tags(values) """ if values.get('ids'): query = {'id__in': values.get('ids')} return TestTag.to_xmlrpc(query) elif values.get('names'): query = {'name__in': values.get('names')} return TestTag.to_xmlrpc(query) else: raise ValueError('Must specify ids or names at least.')
def get(request, run_id): """Used to load an existing test run from the database. :param int run_id: test run ID. :return: a mapping representing found :class:`TestRun`. :rtype: dict Example:: >>> TestRun.get(1) """ try: tr = TestRun.objects.get(run_id=run_id) except TestRun.DoesNotExist as error: return error response = tr.serialize() # get the xmlrpc tags tag_ids = tr.tag.values_list('id', flat=True) query = {'id__in': tag_ids} tags = TestTag.to_xmlrpc(query) # cut 'id' attribute off, only leave 'name' here tags_without_id = map(lambda x: x["name"], tags) # replace tag_id list in the serialize return data response["tag"] = tags_without_id return response
def remove_tag(request, case_ids, tags): """Remove a tag from a case. :param case_ids: give one or more case IDs. It could be an integer, a string containing comma separated IDs, or a list of int each of them is a case ID. :type case_ids: int, str or list :param tags: tag name or a list of tag names to remove. :type tags: str or list :return: a list which is emtpy on success. :rtype: list Example:: # Remove tag 'foo' from case 1 TestCase.remove_tag(1, 'foo') # Remove tag 'foo' and bar from cases list [1, 2] TestCase.remove_tag([1, 2], ['foo', 'bar']) # Remove tag 'foo' and 'bar' from cases list '1, 2' with String TestCase.remove_tag('1, 2', 'foo, bar') """ cases = TestCase.objects.filter( case_id__in=pre_process_ids(value=case_ids) ) tags = TestTag.objects.filter( name__in=TestTag.string_to_list(tags) ) for case, tag in itertools.product(cases, tags): case.remove_tag(tag)
def get(request, plan_id): """ Description: Used to load an existing test plan from the database. Params: $id - Integer/String: An integer representing the ID of this plan in the database Returns: Hash: A blessed TestPlan object hash Example: >>> TestPlan.get(137) """ tp = TestPlan.objects.get(plan_id=plan_id) response = tp.serialize() # This is for backward-compatibility. Actually, this is not a good way to # add this extra field. But, now that's it. response['default_product_version'] = response['product_version'] # get the xmlrpc tags tag_ids = tp.tag.values_list('id', flat=True) query = {'id__in': tag_ids} tags = TestTag.to_xmlrpc(query) # cut 'id' attribute off, only leave 'name' here tags_without_id = map(lambda x: x["name"], tags) # replace tag_id list in the serialize return data response["tag"] = tags_without_id return response
def get(plan_id): """ Description: Used to load an existing test plan from the database. Params: $id - Integer/String: An integer representing the ID of this plan in the database Returns: Hash: A blessed TestPlan object hash Example: >>> TestPlan.get(137) """ tp = TestPlan.objects.get(plan_id=plan_id) response = tp.serialize() # This is for backward-compatibility. Actually, this is not a good way to # add this extra field. But, now that's it. response['default_product_version'] = response['product_version'] # get the xmlrpc tags tag_ids = tp.tag.values_list('id', flat=True) query = {'id__in': tag_ids} tags = TestTag.to_xmlrpc(query) # cut 'id' attribute off, only leave 'name' here tags_without_id = [x["name"] for x in tags] # replace tag_id list in the serialize return data response["tag"] = tags_without_id return response
def get(request, run_id): """Used to load an existing test run from the database. :param int run_id: test run ID. :return: a mapping representing found :class:`TestRun`. :rtype: dict Example:: TestRun.get(1) """ try: tr = TestRun.objects.get(run_id=run_id) except TestRun.DoesNotExist as error: return error response = tr.serialize() # get the xmlrpc tags tag_ids = tr.tag.values_list('id', flat=True) query = {'id__in': tag_ids} tags = TestTag.to_xmlrpc(query) # cut 'id' attribute off, only leave 'name' here tags_without_id = [tag['name'] for tag in tags] # replace tag_id list in the serialize return data response["tag"] = tags_without_id return response
def remove_tag(request, case_ids, tags): """ Description: Remove a tag from a case. Params: $case_ids - Integer/Array/String: An integer or alias representing the ID in the database, an array of case_ids, or a string of comma separated case_ids. $tags - String/Array - A single or multiple tag to be removed. Returns: Array: Empty on success. Example: # Remove tag 'foo' from case 1234 >>> TestCase.remove_tag(1234, 'foo') # Remove tag 'foo' and bar from cases list [56789, 12345] >>> TestCase.remove_tag([56789, 12345], ['foo', 'bar']) # Remove tag 'foo' and 'bar' from cases list '56789, 12345' with String >>> TestCase.remove_tag('56789, 12345', 'foo, bar') """ tcs = TestCase.objects.filter(case_id__in=pre_process_ids(value=case_ids)) tgs = TestTag.objects.filter(name__in=TestTag.string_to_list(tags)) for tc in tcs.iterator(): for tg in tgs.iterator(): try: tc.remove_tag(tg) except ObjectDoesNotExist: pass except: raise return
def add_tag(request, plan_ids, tags): """ Description: Add one or more tags to the selected test plans. Params: $plan_ids - Integer/Array/String: An integer representing the ID of the plan in the database, an arry of plan_ids, or a string of comma separated plan_ids. $tags - String/Array - A single tag, an array of tags, or a comma separated list of tags. Returns: Array: empty on success or an array of hashes with failure codes if a failure occured. Example: # Add tag 'foobar' to plan 1234 >>> TestPlan.add_tag(1234, 'foobar') # Add tag list ['foo', 'bar'] to plan list [12345, 67890] >>> TestPlan.add_tag([12345, 67890], ['foo', 'bar']) # Add tag list ['foo', 'bar'] to plan list [12345, 67890] with String >>> TestPlan.add_tag('12345, 67890', 'foo, bar') """ # FIXME: this could be optimized to reduce possible huge number of SQLs tps = TestPlan.objects.filter(plan_id__in=pre_process_ids(value=plan_ids)) tags = TestTag.string_to_list(tags) for tag in tags: t, c = TestTag.objects.get_or_create(name=tag) for tp in tps.iterator(): tp.add_tag(tag=t) return
def add_tag(request, case_ids, tags): """Add one or more tags to the selected test cases. :param case_ids: give one or more case IDs. It could be an integer, a string containing comma separated IDs, or a list of int each of them is a case ID. :type case_ids: int, str or list :param tags: tag name or a list of tag names to remove. :type tags: str or list :return: a list which is empty on success or a list of mappings with failure codes if a failure occured. Example:: # Add tag 'foobar' to case 1 >>> TestCase.add_tag(1, 'foobar') # Add tag list ['foo', 'bar'] to cases list [1, 2] >>> TestCase.add_tag([1, 2], ['foo', 'bar']) # Add tag list ['foo', 'bar'] to cases list [1, 2] with String >>> TestCase.add_tag('1, 2', 'foo, bar') """ tcs = TestCase.objects.filter(case_id__in=pre_process_ids(value=case_ids)) tags = TestTag.string_to_list(tags) for tag in tags: t, c = TestTag.objects.get_or_create(name=tag) for tc in tcs.iterator(): tc.add_tag(tag=t) return
def remove_tag(request, plan_ids, tags): """Remove a tag from a plan. :param plan_ids: give one or more plan IDs. It could be an integer, a string containing comma separated IDs, or a list of int each of them is a plan ID. :type plan_ids: int, str or list :param tags: a tag name or a list of tag names to be removed. :type tags: str or list[str] :return: Empty on success. Example:: # Remove tag 'foo' from plan 1 TestPlan.remove_tag(1, 'foo') # Remove tag 'foo' and 'bar' from plan list [1, 2] TestPlan.remove_tag([1, 2], ['foo', 'bar']) # Remove tag 'foo' and 'bar' from plan list '1, 2' with String TestPlan.remove_tag('1, 2', 'foo, bar') """ from tcms.management.models import TestTag tps = TestPlan.objects.filter(plan_id__in=pre_process_ids(value=plan_ids)) tgs = TestTag.objects.filter(name__in=TestTag.string_to_list(tags)) for tp in tps.iterator(): for tg in tgs.iterator(): try: tp.remove_tag(tag=tg) except ObjectDoesNotExist: pass return
def get(request, case_id): """Used to load an existing test case from the database. :param case_id: case ID. :type case_id: int or str :return: a mappings representing found test case. :rtype: dict Example:: >>> TestCase.get(1) """ tc = TestCase.objects.get(case_id=case_id) tc_latest_text = tc.latest_text().serialize() response = tc.serialize() response['text'] = tc_latest_text # get the xmlrpc tags tag_ids = tc.tag.values_list('id', flat=True) query = {'id__in': tag_ids} tags = TestTag.to_xmlrpc(query) # cut 'id' attribute off, only leave 'name' here tags_without_id = map(lambda x: x["name"], tags) # replace tag_id list in the serialize return data response["tag"] = tags_without_id return response
def add_tag(request, run_ids, tags): """Add one or more tags to the selected test runs. :param run_ids: give one or more run IDs. It could be an integer, a string containing comma separated IDs, or a list of int each of them is a run ID. :type run_ids: int, str or list :param tags: tag name or a list of tag names to remove. :type tags: str or list :return: a list which is empty on success or a list of mappings with failure codes if a failure occured. :rtype: list Example:: # Add tag 'foobar' to run 1 TestPlan.add_tag(1, 'foobar') # Add tag list ['foo', 'bar'] to run list [1, 2] TestPlan.add_tag([1, 2], ['foo', 'bar']) # Add tag list ['foo', 'bar'] to run list [1, 2] with String TestPlan.add_tag('1, 2', 'foo, bar') """ trs = TestRun.objects.filter(pk__in=pre_process_ids(value=run_ids)) tags = TestTag.string_to_list(tags) for tag in tags: t, c = TestTag.objects.get_or_create(name=tag) for tr in trs.iterator(): tr.add_tag(tag=t) return
def remove_tag(request, run_ids, tags): """Remove a tag from a run. :param run_ids: give one or more run IDs. It could be an integer, a string containing comma separated IDs, or a list of int each of them is a run ID. :type run_ids: int, str or list :param tags: tag name or a list of tag names to remove. :type tags: str or list :return: a list which is empty on success. :rtype: list Example:: # Remove tag 'foo' from run 1 TestRun.remove_tag(1, 'foo') # Remove tag 'foo' and 'bar' from run list [1, 2] TestRun.remove_tag([1, 2], ['foo', 'bar']) # Remove tag 'foo' and 'bar' from run list '1, 2' with String TestRun.remove_tag('1, 2', 'foo, bar') """ trs = TestRun.objects.filter(run_id__in=pre_process_ids(value=run_ids)) tgs = TestTag.objects.filter(name__in=TestTag.string_to_list(tags)) for tr in trs.iterator(): for tg in tgs.iterator(): try: tr.remove_tag(tag=tg) except ObjectDoesNotExist: pass return
def add_tag(request, case_ids, tags): """Add one or more tags to the selected test cases. :param case_ids: give one or more case IDs. It could be an integer, a string containing comma separated IDs, or a list of int each of them is a case ID. :type case_ids: int, str or list :param tags: tag name or a list of tag names to remove. :type tags: str or list :return: a list which is empty on success or a list of mappings with failure codes if a failure occured. Example:: # Add tag 'foobar' to case 1 >>> TestCase.add_tag(1, 'foobar') # Add tag list ['foo', 'bar'] to cases list [1, 2] >>> TestCase.add_tag([1, 2], ['foo', 'bar']) # Add tag list ['foo', 'bar'] to cases list [1, 2] with String >>> TestCase.add_tag('1, 2', 'foo, bar') """ tcs = TestCase.objects.filter( case_id__in=pre_process_ids(value=case_ids)) tags = TestTag.string_to_list(tags) for tag in tags: t, c = TestTag.objects.get_or_create(name=tag) for tc in tcs.iterator(): tc.add_tag(tag=t) return
def add_tag(request, case_ids, tags): """ Description: Add one or more tags to the selected test cases. Params: $case_ids - Integer/Array/String: An integer representing the ID in the database, an array of case_ids, or a string of comma separated case_ids. $tags - String/Array - A single tag, an array of tags, or a comma separated list of tags. Returns: Array: empty on success or an array of hashes with failure codes if a failure occured. Example: # Add tag 'foobar' to case 1234 >>> TestCase.add_tag(1234, 'foobar') # Add tag list ['foo', 'bar'] to cases list [12345, 67890] >>> TestCase.add_tag([12345, 67890], ['foo', 'bar']) # Add tag list ['foo', 'bar'] to cases list [12345, 67890] with String >>> TestCase.add_tag('12345, 67890', 'foo, bar') """ tcs = TestCase.objects.filter( case_id__in=pre_process_ids(value=case_ids)) tags = TestTag.string_to_list(tags) for tag in tags: t, c = TestTag.objects.get_or_create(name=tag) for tc in tcs.iterator(): tc.add_tag(tag=t) return
def get(request, case_id): """ Description: Used to load an existing test case from the database. Params: $id - Integer/String: An integer representing the ID in the database Returns: A blessed TestCase object Hash Example: >>> TestCase.get(1193) """ try: tc = TestCase.objects.get(case_id=case_id) except: raise tc_latest_text = tc.latest_text().serialize() response = tc.serialize() response['text'] = tc_latest_text #get the xmlrpc tags tag_ids = tc.tag.values_list('id', flat=True) query = {'id__in': tag_ids} tags = TestTag.to_xmlrpc(query) #cut 'id' attribute off, only leave 'name' here tags_without_id = map(lambda x: x["name"], tags) #replace tag_id list in the serialize return data response["tag"] = tags_without_id return response
def get(run_id): """ Description: Used to load an existing test run from the database. Params: $run_id - Integer: An integer representing the ID of the run in the database Returns: Hash: A blessed TestRun object hash Example: >>> TestRun.get(1193) """ try: tr = TestRun.objects.get(run_id=run_id) except TestRun.DoesNotExist as error: return error response = tr.serialize() # get the xmlrpc tags tag_ids = tr.tag.values_list('id', flat=True) query = {'id__in': tag_ids} tags = TestTag.to_xmlrpc(query) # cut 'id' attribute off, only leave 'name' here tags_without_id = [x["name"] for x in tags] # replace tag_id list in the serialize return data response["tag"] = tags_without_id return response
def get(request, plan_id): """Used to load an existing test plan from the database. :param int plan_id: plan ID. :return: a mapping of found :class:`TestPlan`. :rtype: dict Example:: >>> TestPlan.get(1) """ tp = TestPlan.objects.get(plan_id=plan_id) response = tp.serialize() # This is for backward-compatibility. Actually, this is not a good way to # add this extra field. But, now that's it. response['default_product_version'] = response['product_version'] # get the xmlrpc tags tag_ids = tp.tag.values_list('id', flat=True) query = {'id__in': tag_ids} tags = TestTag.to_xmlrpc(query) # cut 'id' attribute off, only leave 'name' here tags_without_id = map(lambda x: x["name"], tags) # replace tag_id list in the serialize return data response["tag"] = tags_without_id return response
def remove_tag(request, case_ids, tags): """Remove a tag from a case. :param case_ids: give one or more case IDs. It could be an integer, a string containing comma separated IDs, or a list of int each of them is a case ID. :type case_ids: int, str or list :param tags: tag name or a list of tag names to remove. :type tags: str or list :return: a list which is emtpy on success. :rtype: list Example:: # Remove tag 'foo' from case 1 >>> TestCase.remove_tag(1, 'foo') # Remove tag 'foo' and bar from cases list [1, 2] >>> TestCase.remove_tag([1, 2], ['foo', 'bar']) # Remove tag 'foo' and 'bar' from cases list '1, 2' with String >>> TestCase.remove_tag('1, 2', 'foo, bar') """ tcs = TestCase.objects.filter(case_id__in=pre_process_ids(value=case_ids)) tgs = TestTag.objects.filter(name__in=TestTag.string_to_list(tags)) for tc in tcs.iterator(): for tg in tgs.iterator(): try: tc.remove_tag(tg) except ObjectDoesNotExist: pass return
def get(request, plan_id): """Used to load an existing test plan from the database. :param int plan_id: plan ID. :return: a mapping of found :class:`TestPlan`. :rtype: dict Example:: TestPlan.get(1) """ tp = TestPlan.objects.get(plan_id=plan_id) response = tp.serialize() # This is for backward-compatibility. Actually, this is not a good way to # add this extra field. But, now that's it. response['default_product_version'] = response['product_version'] # get the xmlrpc tags tag_ids = tp.tag.values_list('id', flat=True) query = {'id__in': tag_ids} tags = TestTag.to_xmlrpc(query) # cut 'id' attribute off, only leave 'name' here tags_without_id = [tag['name'] for tag in tags] # replace tag_id list in the serialize return data response["tag"] = tags_without_id return response
def add_tag(request, plan_ids, tags): """Add one or more tags to the selected test plans. :param plan_ids: give one or more plan IDs. It could be an integer, a string containing comma separated IDs, or a list of int each of them is a plan ID. :type plan_ids: int, str or list :param tags: a tag name or list of tag names to be added. :type tags: str or list[str] :return: a list which is empty on success or a list of mappings with failure codes if a failure occured. Example:: # Add tag 'foobar' to plan 1 TestPlan.add_tag(1, 'foobar') # Add tag list ['foo', 'bar'] to plan list [1, 2] TestPlan.add_tag([1, 2], ['foo', 'bar']) # Add tag list ['foo', 'bar'] to plan list [1, 2] with String TestPlan.add_tag('1, 2', 'foo, bar') """ # FIXME: this could be optimized to reduce possible huge number of SQLs tps = TestPlan.objects.filter(plan_id__in=pre_process_ids(value=plan_ids)) tags = TestTag.string_to_list(tags) for tag in tags: t, c = TestTag.objects.get_or_create(name=tag) for tp in tps.iterator(): tp.add_tag(tag=t) return
def get(request, case_id): """Used to load an existing test case from the database. :param case_id: case ID. :type case_id: int or str :return: a mappings representing found test case. :rtype: dict Example:: TestCase.get(1) """ tc = TestCase.objects.get(case_id=case_id) tc_latest_text = tc.latest_text().serialize() response = tc.serialize() response['text'] = tc_latest_text # get the xmlrpc tags tag_ids = tc.tag.values_list('id', flat=True) query = {'id__in': tag_ids} tags = TestTag.to_xmlrpc(query) # cut 'id' attribute off, only leave 'name' here tags_without_id = [tag['name'] for tag in tags] # replace tag_id list in the serialize return data response["tag"] = tags_without_id return response
def add_tag(request, plan_ids, tags): """Add one or more tags to the selected test plans. :param plan_ids: give one or more plan IDs. It could be an integer, a string containing comma separated IDs, or a list of int each of them is a plan ID. :type plan_ids: int, str or list :param tags: a tag name or list of tag names to be added. :type tags: str or list[str] :return: a list which is empty on success or a list of mappings with failure codes if a failure occured. Example:: # Add tag 'foobar' to plan 1 >>> TestPlan.add_tag(1, 'foobar') # Add tag list ['foo', 'bar'] to plan list [1, 2] >>> TestPlan.add_tag([1, 2], ['foo', 'bar']) # Add tag list ['foo', 'bar'] to plan list [1, 2] with String >>> TestPlan.add_tag('1, 2', 'foo, bar') """ # FIXME: this could be optimized to reduce possible huge number of SQLs tps = TestPlan.objects.filter(plan_id__in=pre_process_ids(value=plan_ids)) tags = TestTag.string_to_list(tags) for tag in tags: t, c = TestTag.objects.get_or_create(name=tag) for tp in tps.iterator(): tp.add_tag(tag=t) return
def remove_tag(request, plan_ids, tags): """ Description: Remove a tag from a plan. Params: $plan_ids - Integer/Array/String: An integer or alias representing the ID in the database, an array of plan_ids, or a string of comma separated plan_ids. $tag - String - A single tag to be removed. Returns: Array: Empty on success. Example: # Remove tag 'foo' from plan 1234 >>> TestPlan.remove_tag(1234, 'foo') # Remove tag 'foo' and 'bar' from plan list [56789, 12345] >>> TestPlan.remove_tag([56789, 12345], ['foo', 'bar']) # Remove tag 'foo' and 'bar' from plan list '56789, 12345' with String >>> TestPlan.remove_tag('56789, 12345', 'foo, bar') """ from tcms.management.models import TestTag tps = TestPlan.objects.filter(plan_id__in=pre_process_ids(value=plan_ids)) tgs = TestTag.objects.filter(name__in=TestTag.string_to_list(tags)) for tp in tps.iterator(): for tg in tgs.iterator(): try: tp.remove_tag(tag=tg) except ObjectDoesNotExist: pass except: raise return
def filter(query): """ .. function:: XML-RPC Tag.filter(query) Search and return a list of tags :param query: Field lookups for :class:`tcms.management.models.TestTag` :type query: dict :return: Serialized list of :class:`tcms.management.models.TestTag` objects :rtype: list(dict) """ return TestTag.to_xmlrpc(query)
def get_tags(request, run_id): """Get the list of tags attached to this run. :param int run_id: run ID. :return: a mapping representing found :class:`TestTag`. :rtype: dict Example:: TestRun.get_tags(1) """ tr = TestRun.objects.get(run_id=run_id) tag_ids = tr.tag.values_list('id', flat=True) query = {'id__in': tag_ids} return TestTag.to_xmlrpc(query)
def get_tags(plan_id): """ Description: Get the list of tags attached to this plan. Params: $plan_id - Integer An integer representing the ID of this plan in the database Returns: Array: An array of tag object hashes. Example: >>> TestPlan.get_tags(137) """ test_plan = TestPlan.objects.get(plan_id=plan_id) tag_ids = test_plan.tag.values_list('id', flat=True) query = {'id__in': tag_ids} return TestTag.to_xmlrpc(query)
def get_tags(request, plan_id): """Get the list of tags attached to this plan. :param int plan_id: plan ID. :return: list of mappings of found :class:`TestTag`. :rtype: list[dict] Example:: >>> TestPlan.get_tags(1) """ tp = TestPlan.objects.get(plan_id=plan_id) tag_ids = tp.tag.values_list('id', flat=True) query = {'id__in': tag_ids} return TestTag.to_xmlrpc(query)
def get_tags(request, run_id): """Get the list of tags attached to this run. :param int run_id: run ID. :return: a mapping representing found :class:`TestTag`. :rtype: dict Example:: >>> TestRun.get_tags(1) """ tr = TestRun.objects.get(run_id=run_id) tag_ids = tr.tag.values_list('id', flat=True) query = {'id__in': tag_ids} return TestTag.to_xmlrpc(query)
def get_tags(request, plan_id): """Get the list of tags attached to this plan. :param int plan_id: plan ID. :return: list of mappings of found :class:`TestTag`. :rtype: list[dict] Example:: TestPlan.get_tags(1) """ tp = TestPlan.objects.get(plan_id=plan_id) tag_ids = tp.tag.values_list('id', flat=True) query = {'id__in': tag_ids} return TestTag.to_xmlrpc(query)
def get_tags(case_id): """ Description: Get the list of tags attached to this case. Params: $case_id - Integer/String: An integer representing the ID in the database Returns: Array: An array of tag object hashes. Example: >>> TestCase.get_tags(12345) """ test_case = TestCase.objects.get(case_id=case_id) tag_ids = test_case.tag.values_list('id', flat=True) query = {'id__in': tag_ids} return TestTag.to_xmlrpc(query)
def get_tags(request, case_id): """Get the list of tags attached to this case. :param case_id: case ID. :type case_id: int or str :return: a list of mappings of :class:`TestTag`. :rtype: list[dict] Example:: TestCase.get_tags(1) """ tc = TestCase.objects.get(case_id=case_id) tag_ids = tc.tag.values_list('id', flat=True) query = {'id__in': tag_ids} return TestTag.to_xmlrpc(query)
def get_tags(request, case_id): """Get the list of tags attached to this case. :param case_id: case ID. :type case_id: int or str :return: a list of mappings of :class:`TestTag`. :rtype: list[dict] Example:: >>> TestCase.get_tags(1) """ tc = TestCase.objects.get(case_id=case_id) tag_ids = tc.tag.values_list('id', flat=True) query = {'id__in': tag_ids} return TestTag.to_xmlrpc(query)
def get_tags(request, run_id): """ Description: Get the list of tags attached to this run. Params: $run_id - Integer: An integer representing the ID of the run in the database Returns: Array: An array of tag object hashes. Example: >>> TestRun.get_tags(1193) """ try: tr = TestRun.objects.get(run_id=run_id) except: raise tag_ids = tr.tag.values_list('id', flat=True) query = {'id__in': tag_ids} return TestTag.to_xmlrpc(query)
def get_tags(request, case_id): """ Description: Get the list of tags attached to this case. Params: $case_id - Integer/String: An integer representing the ID in the database Returns: Array: An array of tag object hashes. Example: >>> TestCase.get_tags(12345) """ try: tc = TestCase.objects.get(case_id=case_id) except: raise tag_ids = tc.tag.values_list('id', flat=True) query = {'id__in': tag_ids} return TestTag.to_xmlrpc(query)
def get_tags(request, plan_id): """ Description: Get the list of tags attached to this plan. Params: $plan_id - Integer An integer representing the ID of this plan in the database Returns: Array: An array of tag object hashes. Example: >>> TestPlan.get_tags(137) """ try: tp = TestPlan.objects.get(plan_id=plan_id) except: raise tag_ids = tp.tag.values_list('id', flat=True) query = {'id__in': tag_ids} return TestTag.to_xmlrpc(query)
def get_all_cases_tags(request, plan_id): """Get the list of tags attached to this plan's testcases. :param int plan_id: plan ID. :return: list of mappings of found :class:`TestTag`. :rtype: list[dict] Example:: >>> TestPlan.get_all_cases_tags(137) """ tp = TestPlan.objects.get(plan_id=plan_id) tcs = tp.case.all() tag_ids = [] for tc in tcs.iterator(): tag_ids.extend(tc.tag.values_list('id', flat=True)) tag_ids = list(set(tag_ids)) query = {'id__in': tag_ids} return TestTag.to_xmlrpc(query)
def get_all_cases_tags(request, plan_id): """Get the list of tags attached to this plan's testcases. :param int plan_id: plan ID. :return: list of mappings of found :class:`TestTag`. :rtype: list[dict] Example:: TestPlan.get_all_cases_tags(137) """ tp = TestPlan.objects.get(plan_id=plan_id) tcs = tp.case.all() tag_ids = [] for tc in tcs.iterator(): tag_ids.extend(tc.tag.values_list('id', flat=True)) tag_ids = list(set(tag_ids)) query = {'id__in': tag_ids} return TestTag.to_xmlrpc(query)
def get_all_cases_tags(plan_id): """ Description: Get the list of tags attached to this plan's testcases. Params: $plan_id - Integer An integer representing the ID of this plan in the database Returns: Array: An array of tag object hashes. Example: >>> TestPlan.get_all_cases_tags(137) """ test_plan = TestPlan.objects.get(plan_id=plan_id) test_cases = test_plan.case.all() tag_ids = [] for test_case in test_cases.iterator(): tag_ids.extend(test_case.tag.values_list('id', flat=True)) tag_ids = list(set(tag_ids)) query = {'id__in': tag_ids} return TestTag.to_xmlrpc(query)
def remove_tag(request, plan_ids, tags): """ Description: Remove a tag from a plan. Params: $plan_ids - Integer/Array/String: An integer or alias representing the ID in the database, an array of plan_ids, or a string of comma separated plan_ids. $tag - String - A single tag to be removed. Returns: Array: Empty on success. Example: # Remove tag 'foo' from plan 1234 >>> TestPlan.remove_tag(1234, 'foo') # Remove tag 'foo' and 'bar' from plan list [56789, 12345] >>> TestPlan.remove_tag([56789, 12345], ['foo', 'bar']) # Remove tag 'foo' and 'bar' from plan list '56789, 12345' with String >>> TestPlan.remove_tag('56789, 12345', 'foo, bar') """ from tcms.management.models import TestTag tps = TestPlan.objects.filter( plan_id__in=pre_process_ids(value=plan_ids) ) tgs = TestTag.objects.filter( name__in=TestTag.string_to_list(tags) ) for tp in tps.iterator(): for tg in tgs.iterator(): try: tp.remove_tag(tag=tg) except ObjectDoesNotExist: pass except: raise return
def get_all_cases_tags(request, plan_id): """ Description: Get the list of tags attached to this plan's testcases. Params: $plan_id - Integer An integer representing the ID of this plan in the database Returns: Array: An array of tag object hashes. Example: >>> TestPlan.get_all_cases_tags(137) """ try: tp = TestPlan.objects.get(plan_id=plan_id) except: raise tcs = tp.case.all() tag_ids = [] for tc in tcs.iterator(): tag_ids.extend(tc.tag.values_list('id', flat=True)) tag_ids = list(set(tag_ids)) query = {'id__in': tag_ids} return TestTag.to_xmlrpc(query)
def remove_tag(request, plan_ids, tags): """Remove a tag from a plan. :param plan_ids: give one or more plan IDs. It could be an integer, a string containing comma separated IDs, or a list of int each of them is a plan ID. :type plan_ids: int, str or list :param tags: a tag name or a list of tag names to be removed. :type tags: str or list[str] :return: Empty on success. Example:: # Remove tag 'foo' from plan 1 >>> TestPlan.remove_tag(1, 'foo') # Remove tag 'foo' and 'bar' from plan list [1, 2] >>> TestPlan.remove_tag([1, 2], ['foo', 'bar']) # Remove tag 'foo' and 'bar' from plan list '1, 2' with String >>> TestPlan.remove_tag('1, 2', 'foo, bar') """ from tcms.management.models import TestTag tps = TestPlan.objects.filter( plan_id__in=pre_process_ids(value=plan_ids) ) tgs = TestTag.objects.filter( name__in=TestTag.string_to_list(tags) ) for tp in tps.iterator(): for tg in tgs.iterator(): try: tp.remove_tag(tag=tg) except ObjectDoesNotExist: pass return
def remove_tag(request, case_ids, tags): """Remove a tag from a case. :param case_ids: give one or more case IDs. It could be an integer, a string containing comma separated IDs, or a list of int each of them is a case ID. :type case_ids: int, str or list :param tags: tag name or a list of tag names to remove. :type tags: str or list :return: a list which is emtpy on success. :rtype: list Example:: # Remove tag 'foo' from case 1 >>> TestCase.remove_tag(1, 'foo') # Remove tag 'foo' and bar from cases list [1, 2] >>> TestCase.remove_tag([1, 2], ['foo', 'bar']) # Remove tag 'foo' and 'bar' from cases list '1, 2' with String >>> TestCase.remove_tag('1, 2', 'foo, bar') """ tcs = TestCase.objects.filter( case_id__in=pre_process_ids(value=case_ids) ) tgs = TestTag.objects.filter( name__in=TestTag.string_to_list(tags) ) for tc in tcs.iterator(): for tg in tgs.iterator(): try: tc.remove_tag(tg) except ObjectDoesNotExist: pass return
def remove_tag(request, case_ids, tags): """ Description: Remove a tag from a case. Params: $case_ids - Integer/Array/String: An integer or alias representing the ID in the database, an array of case_ids, or a string of comma separated case_ids. $tags - String/Array - A single or multiple tag to be removed. Returns: Array: Empty on success. Example: # Remove tag 'foo' from case 1234 >>> TestCase.remove_tag(1234, 'foo') # Remove tag 'foo' and bar from cases list [56789, 12345] >>> TestCase.remove_tag([56789, 12345], ['foo', 'bar']) # Remove tag 'foo' and 'bar' from cases list '56789, 12345' with String >>> TestCase.remove_tag('56789, 12345', 'foo, bar') """ tcs = TestCase.objects.filter( case_id__in=pre_process_ids(value=case_ids) ) tgs = TestTag.objects.filter( name__in=TestTag.string_to_list(tags) ) for tc in tcs.iterator(): for tg in tgs.iterator(): try: tc.remove_tag(tg) except ObjectDoesNotExist: pass except: raise return
in the database Returns: Hash: A blessed TestRun object hash Example: >>> TestRun.get(1193) """ try: tr = TestRun.objects.get(run_id=run_id) except TestRun.DoesNotExist, error: return error response = tr.serialize() # get the xmlrpc tags tag_ids = tr.tag.values_list('id', flat=True) query = {'id__in': tag_ids} tags = TestTag.to_xmlrpc(query) # cut 'id' attribute off, only leave 'name' here tags_without_id = map(lambda x: x["name"], tags) # replace tag_id list in the serialize return data response["tag"] = tags_without_id return response @log_call(namespace=__xmlrpc_namespace__) def get_bugs(request, run_ids): """ *** FIXME: BUGGY IN SERIALISER - List can not be serialize. *** Description: Get the list of bugs attached to this run. Params: $run_ids - Integer/Array/String: An integer representing the ID in the database an array of integers or a comma separated list of integers.
def clean_tag(self): tags = [] if self.cleaned_data['tag']: tag_names = TestTag.string_to_list(self.cleaned_data['tag']) tags = TestTag.get_or_create_many_by_name(tag_names) return tags
def clean_tag__name__in(self): return TestTag.string_to_list(self.cleaned_data['tag__name__in'])
def clean_tag(self): return TestTag.objects.filter( name__in=TestTag.string_to_list(self.cleaned_data['tag']) )
def create(request, values): """ Description: Creates a new Test Case object and stores it in the database. Params: $values - Array/Hash: A reference to a hash or array of hashes with keys and values matching the fields of the test case to be created. +----------------------------+----------------+-----------+---------------------------------------+ | Field | Type | Null | Description | +----------------------------+----------------+-----------+---------------------------------------+ | product | Integer | Required | ID of Product | | category | Integer | Required | ID of Category | | priority | Integer | Required | ID of Priority | | summary | String | Required | | | case_status | Integer | Optional | ID of case status | | plan | Array/Str/Int | Optional | ID or List of plan_ids | | component | Integer/String | Optional | ID of Priority | | default_tester | String | Optional | Login of tester | | estimated_time | String | Optional | 2h30m30s(recommend) or HH:MM:SS Format| | is_automated | Integer | Optional | 0: Manual, 1: Auto, 2: Both | | is_automated_proposed | Boolean | Optional | Default 0 | | script | String | Optional | | | arguments | String | Optional | | | requirement | String | Optional | | | alias | String | Optional | Must be unique | | action | String | Optional | | | effect | String | Optional | Expected Result | | setup | String | Optional | | | breakdown | String | Optional | | | tag | Array/String | Optional | String Comma separated | | bug | Array/String | Optional | String Comma separated | | extra_link | String | Optional | reference link | +----------------------------+----------------+-----------+---------------------------------------+ Returns: Array/Hash: The newly created object hash if a single case was created, or an array of objects if more than one was created. If any single case threw an error during creation, a hash with an ERROR key will be set in its place. Example: # Minimal test case parameters >>> values = { 'category': 135, 'product': 61, 'summary': 'Testing XML-RPC', 'priority': 1, } >>> TestCase.create(values) """ from tcms.core import forms from tcms.xmlrpc.forms import NewCaseForm if not (values.get('category') or values.get('summary')): raise ValueError() values['component'] = pre_process_ids(values.get('component', [])) values['plan'] = pre_process_ids(values.get('plan', [])) values['bug'] = pre_process_ids(values.get('bug', [])) if values.get('estimated_time'): values['estimated_time'] = pre_process_estimated_time(values.get('estimated_time')) form = NewCaseForm(values) form.populate(values.get('product')) if form.is_valid(): # Create the case tc = TestCase.create(author=request.user, values=form.cleaned_data) # Add case text to the case tc.add_text( action=form.cleaned_data['action'] or '', effect=form.cleaned_data['effect'] or '', setup=form.cleaned_data['setup'] or '', breakdown=form.cleaned_data['breakdown'] or '', ) # Add the case to specific plans for p in form.cleaned_data['plan']: tc.add_to_plan(plan=p) del p # Add components to the case for c in form.cleaned_data['component']: tc.add_component(component=c) del c # Add tag to the case for tag in TestTag.string_to_list(values.get('tag', [])): t, c = TestTag.objects.get_or_create(name=tag) tc.add_tag(tag=t) else: # Print the errors if the form is not passed validation. raise ValueError(forms.errors_to_list(form)) return get(request, tc.case_id)
def create(request, values): """Creates a new Test Case object and stores it in the database. :param values: a mapping or list of mappings containing these case information for creation. * product: (int) **Required** ID of Product * category: (int) **Required** ID of Category * priority: (int) **Required** ID of Priority * summary: (str) **Required** * case_status: (int) optional ID of case status * plan Array/Str/Int optional ID or List of plan_ids * component: (int)/str optional ID of Priority * default_tester: (str) optional Login of tester * estimated_time: (str) optional 2h30m30s(recommend) or HH:MM:SS Format| * is_automated: (int) optional 0: Manual, 1: Auto, 2: Both * is_automated_proposed: (bool) optional Default 0 * script: (str) optional * arguments: (str) optional * requirement: (str) optional * alias: (str) optional Must be unique * action: (str) optional * effect: (str) optional Expected Result * setup: (str) optional * breakdown: (str) optional * tag Array/str optional String Comma separated * bug Array/str optional String Comma separated * extra_link: (str) optional reference link :return: a mapping of newly created test case if a single case was created, or a list of mappings of created cases if more than one are created. :rtype: dict of list[dict] Example:: # Minimal test case parameters >>> values = { 'category': 1, 'product': 1, 'summary': 'Testing XML-RPC', 'priority': 1, } >>> TestCase.create(values) """ from tcms.core import forms from tcms.xmlrpc.forms import NewCaseForm if not (values.get('category') or values.get('summary')): raise ValueError() values['component'] = pre_process_ids(values.get('component', [])) values['plan'] = pre_process_ids(values.get('plan', [])) values['bug'] = pre_process_ids(values.get('bug', [])) if values.get('estimated_time'): values['estimated_time'] = pre_process_estimated_time(values.get('estimated_time')) form = NewCaseForm(values) form.populate(values.get('product')) if form.is_valid(): # Create the case tc = TestCase.create(author=request.user, values=form.cleaned_data) # Add case text to the case tc.add_text( action=form.cleaned_data['action'] or '', effect=form.cleaned_data['effect'] or '', setup=form.cleaned_data['setup'] or '', breakdown=form.cleaned_data['breakdown'] or '', ) # Add the case to specific plans for p in form.cleaned_data['plan']: tc.add_to_plan(plan=p) del p # Add components to the case for c in form.cleaned_data['component']: tc.add_component(component=c) del c # Add tag to the case for tag in TestTag.string_to_list(values.get('tag', [])): t, c = TestTag.objects.get_or_create(name=tag) tc.add_tag(tag=t) else: # Print the errors if the form is not passed validation. raise ValueError(forms.errors_to_list(form)) return get(request, tc.case_id)
def __init__(self, obj, tag): self.obj = obj self.tag = TestTag.string_to_list(tag) self.request = request