Best Python code snippet using Kiwi_python
testcase.py
Source:testcase.py  
...73    """74    TestCase.objects.get(pk=case_id).remove_component(75        Component.objects.get(pk=component_id)76    )77def _validate_cc_list(cc_list):78    """79        Validate each email address given in argument. Called by80        notification RPC methods.81        :param cc_list: List of email addresses82        :type cc_list: list83        :return: None84        :raises: TypeError or ValidationError if addresses are not valid.85    """86    if not isinstance(cc_list, list):87        raise TypeError('cc_list should be a list object.')88    field = EmailField(required=True)89    invalid_emails = []90    for item in cc_list:91        try:92            field.clean(item)93        except ValidationError:94            invalid_emails.append(item)95    if invalid_emails:96        raise ValidationError(97            field.error_messages['invalid'] % {98                'value': ', '.join(invalid_emails)})99@permissions_required('testcases.change_testcase')100@rpc_method(name='TestCase.add_notification_cc')101def add_notification_cc(case_id, cc_list):102    '''103    .. function:: XML-RPC TestCase.add_notification_cc(case_id, cc_list)104        Add email addresses to the notification list of specified TestCase105        :param case_id: PK of TestCase to be modified106        :param case_id: int107        :param cc_list: List of email addresses108        :type cc_list: list(str)109        :return: None110        :raises: TypeError or ValidationError if email validation fails111        :raises: PermissionDenied if missing *testcases.change_testcase* permission112        :raises: TestCase.DoesNotExist if object with case_id doesn't exist113    '''114    _validate_cc_list(cc_list)115    test_case = TestCase.objects.get(pk=case_id)116    # First, find those that do not exist yet.117    existing_cc = test_case.emailing.get_cc_list()118    adding_cc = list(set(cc_list) - set(existing_cc))119    # add the ones which are new120    test_case.emailing.add_cc(adding_cc)121@permissions_required('testcases.change_testcase')122@rpc_method(name='TestCase.remove_notification_cc')123def remove_notification_cc(case_id, cc_list):124    '''125    .. function:: XML-RPC TestCase.remove_notification_cc(case_id, cc_list)126        Remove email addresses from the notification list of specified TestCase127        :param case_id: PK of TestCase to modify128        :type case_id: int129        :param cc_list: List of email addresses130        :type cc_list: list(str)131        :return: None132        :raises: TypeError or ValidationError if email validation fails133        :raises: PermissionDenied if missing *testcases.change_testcase* permission134        :raises: TestCase.DoesNotExist if object with case_id doesn't exist135    '''136    _validate_cc_list(cc_list)137    TestCase.objects.get(pk=case_id).emailing.remove_cc(cc_list)138@rpc_method(name='TestCase.get_notification_cc')139def get_notification_cc(case_id):140    '''141    .. function:: XML-RPC TestCase.get_notification_cc(case_id)142        Return notification list for specified TestCase143        :param case_id: PK of TestCase144        :type case_id: int145        :return: List of email addresses146        :rtype: list(str)147        :raises: TestCase.DoesNotExist if object with case_id doesn't exist148    '''149    return TestCase.objects.get(pk=case_id).get_cc_list()150@permissions_required('testcases.add_testcasetag')...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
