def filter(request, query): """ Description: Performs a search and returns the resulting list of test cases. Params: $query - Hash: keys must match valid search fields. +------------------------------------------------------------------+ | Case Search Parameters | +------------------------------------------------------------------+ | Key | Valid Values | | author | A bugzilla login (email address) | | attachment | ForeignKey: Attchment | | alias | String | | case_id | Integer | | case_status | ForeignKey: Case Stat | | category | ForeignKey: Category | | component | ForeignKey: Component | | default_tester | ForeignKey: Auth.User | | estimated_time | Time | | plan | ForeignKey: Test Plan | | priority | ForeignKey: Priority | | category__product | ForeignKey: Product | | summary | String | | tags | ForeignKey: Tags | | create_date | Datetime | | is_automated | 1: Only show current 0: show not current | | script | Text | +------------------------------------------------------------------+ Returns: Array: Matching test cases are retuned in a list of hashes. Example: # Get all of cases contain 'TCMS' in summary >>> TestCase.filter({'summary__icontain': 'TCMS'}) # Get all of cases create by xkuang >>> TestCase.filter({'author__username': '******'}) # Get all of cases the author name starts with x >>> TestCase.filter({'author__username__startswith': 'x'}) # Get all of cases belong to the plan 137 >>> TestCase.filter({'plan__plan_id': 137}) # Get all of cases belong to the plan create by xkuang >>> TestCase.filter({'plan__author__username': '******'}) # Get cases with ID 12345, 23456, 34567 - Here is only support array so far. >>> TestCase.filter({'case_id__in': [12345, 23456, 34567]}) """ return TestCase.to_xmlrpc(query)
def get_cases(request, product): """ Description: Get the list of cases associated with this product. Params: $product - Integer/String Integer: product_id of the product in the Database String: Product name Returns: Array: Returns an array of TestCase objects. Example: # Get with product id >>> Product.get_cases(61) # Get with product name >>> Product.get_cases('Red Hat Enterprise Linux 5') """ from nitrate.apps.testcases.models import TestCase p = pre_check_product(values = product) query = {'category__product': p} return TestCase.to_xmlrpc(query)
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 | 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 nitrate.core import forms from nitrate.apps.testcases.forms import XMLRPCNewCaseForm 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', [])) form = XMLRPCNewCaseForm(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. return forms.errors_to_list(form) return get(request, tc.case_id)
def update(request, case_ids, values): """ Description: Updates the fields of the selected case or cases. Params: $case_ids - Integer/String/Array Integer: A single TestCase ID. String: A comma separates string of TestCase IDs for batch processing. Array: An array of case IDs for batch mode processing $values - Hash of keys matching TestCase fields and the new values to set each field to. Returns: Array: an array of case hashes. If the update on any particular case failed, the has will contain a ERROR key and the message as to why it failed. +-----------------------+----------------+-----------------------------------------+ | Field | Type | Null | +-----------------------+----------------+-----------------------------------------+ | case_status | Integer | Optional | | product | Integer | Optional(Required if changes category) | | category | Integer | Optional | | priority | Integer | Optional | | default_tester | String/Integer | Optional(str - user_name, int - user_id)| | estimated_time | String | Optional | | is_automated | Integer | Optional(0 - Manual, 1 - Auto, 2 - Both)| | is_automated_proposed | Boolean | Optional | | script | String | Optional | | arguments | String | Optional | | summary | String | Optional | | requirement | String | Optional | | alias | String | Optional | | notes | String | Optional | | extra_link | String | Optional(reference link) +-----------------------+----------------+-----------------------------------------+ Example: # Update alias to 'tcms' for case 12345 and 23456 >>> TestCase.update([12345, 23456], {'alias': 'tcms'}) """ from nitrate.core import forms from nitrate.apps.testcases.forms import XMLRPCUpdateCaseForm form = XMLRPCUpdateCaseForm(values) if values.get('category') and not values.get('product'): raise ValueError('Product ID is required for category') if values.get('product'): form.populate(product_id = values['product']) if form.is_valid(): tcs = TestCase.update( case_ids = pre_process_ids(value = case_ids), values = form.cleaned_data, ) else: return forms.errors_to_list(form) query = {'pk__in': tcs.values_list('pk', flat = True)} return TestCase.to_xmlrpc(query)