def test_create(self): values = { 'summary': f'Test new case: {self.__class__.__name__}', 'is_automated': True, 'is_automated_proposed': True, 'script': '', 'arguments': '', 'extra_link': 'https://localhost/case-2', 'requirement': '', 'alias': 'alias', 'estimated_time': 0, 'case_status': TestCaseStatus.objects.get(name='CONFIRMED'), 'category': TestCaseCategory.objects.all()[0], 'priority': Priority.objects.all()[0], 'default_tester': self.tester, 'notes': '', 'tag': [self.tag_fedora, self.tag_python], 'component': [self.component_db, self.component_web], } TestCase.create(self.tester, values=values, plans=[self.plan]) new_case = TestCase.objects.get(summary=values['summary']) expected = values.copy() expected['estimated_time'] = timedelta(0) from tests.testcases import assert_new_case assert_new_case(new_case, expected) self.assertTrue( TestCasePlan.objects.filter(plan=self.plan, case=new_case).exists())
def create(values, **kwargs): """ .. function:: XML-RPC TestCase.create(values) Create a new TestCase object and store it in the database. :param values: Field values for :class:`tcms.testcases.models.TestCase` :type values: dict :return: Serialized :class:`tcms.testcases.models.TestCase` object :rtype: dict :raises: PermissionDenied if missing *testcases.add_testcase* permission Minimal test case parameters:: >>> values = { 'category': 135, 'product': 61, 'summary': 'Testing XML-RPC', 'priority': 1, } >>> TestCase.create(values) """ request = kwargs.get(REQUEST_KEY) if not (values.get('category') or values.get('summary')): raise ValueError() if values.get('estimated_time'): values['estimated_time'] = parse_duration(values.get('estimated_time')) form = NewCaseForm(values) form.populate(values.get('product')) if form.is_valid(): # Create the case test_case = TestCase.create(author=request.user, values=form.cleaned_data) # Add case text to the case test_case.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 tag to the case for tag in string_to_list(values.get('tag', [])): tag, _ = Tag.objects.get_or_create(name=tag) test_case.add_tag(tag=tag) else: # Print the errors if the form is not passed validation. raise ValueError(form_errors_to_list(form)) result = test_case.serialize() result['text'] = test_case.latest_text().serialize() return result
def create_test_case(self, form, notify_form, test_plan): """Create new test case""" test_case = TestCase.create(author=self.request.user, values=form.cleaned_data) # Assign the case to the plan if test_plan: test_plan.add_case(test_case) update_case_email_settings(test_case, notify_form) return test_case
def create_testcase(request, form, test_plan): """Create testcase""" test_case = TestCase.create(author=request.user, values=form.cleaned_data) # Assign the case to the plan if test_plan: test_plan.add_case(test_case) # Add components into the case for component in form.cleaned_data['component']: test_case.add_component(component=component) return test_case
def create_testcase(request, form, test_plan): """Create testcase""" test_case = TestCase.create(author=request.user, values=form.cleaned_data) test_case.add_text(case_text_version=1, author=request.user, action=form.cleaned_data['action'], effect=form.cleaned_data['effect'], setup=form.cleaned_data['setup'], breakdown=form.cleaned_data['breakdown']) # Assign the case to the plan if test_plan: test_case.add_to_plan(plan=test_plan) # Add components into the case for component in form.cleaned_data['component']: test_case.add_component(component=component) return test_case
def create(values, **kwargs): """ .. function:: XML-RPC TestCase.create(values) Create a new TestCase object and store it in the database. :param values: Field values for :class:`tcms.testcases.models.TestCase` :type values: dict :return: Serialized :class:`tcms.testcases.models.TestCase` object :rtype: dict :raises: PermissionDenied if missing *testcases.add_testcase* permission Minimal test case parameters:: >>> values = { 'category': 135, 'product': 61, 'summary': 'Testing XML-RPC', 'priority': 1, } >>> TestCase.create(values) """ request = kwargs.get(REQUEST_KEY) if not (values.get('category') or values.get('summary')): raise ValueError() form = NewCaseForm(values) form.populate(values.get('product')) if form.is_valid(): # Create the case test_case = TestCase.create(author=request.user, values=form.cleaned_data) else: # Print the errors if the form is not passed validation. raise ValueError(form_errors_to_list(form)) result = test_case.serialize() return result
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 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)