How to use should_not_have method in Selene

Best Python code snippet using selene_python

test_case_sharing.py

Source:test_case_sharing.py Github

copy

Full Screen

1from django.test import TestCase2from casexml.apps.case.mock import CaseBlock3from casexml.apps.case.tests.util import check_user_has_case4from casexml.apps.case.util import post_case_blocks5from corehq.apps.domain.shortcuts import create_domain6from corehq.apps.groups.models import Group7from corehq.apps.users.models import CommCareUser8from corehq.apps.users.util import format_username9class CaseSharingTest(TestCase):10 def setUp(self):11 """12 Two groups A and B, with users A1, A2 and B1, B2 respectively, and supervisor X who belongs to both.13 14 """15 self.domain = "test-domain"16 create_domain(self.domain)17 password = "****"18 def create_user(username):19 return CommCareUser.create(self.domain, format_username(username, self.domain), password)20 def create_group(name, *users):21 group = Group(users=[user.user_id for user in users], name=name, domain=self.domain,22 case_sharing=True)23 group.save()24 return group25 self.userX = create_user("X")26 self.userA1 = create_user("A1")27 self.userA2 = create_user("A2")28 self.userB1 = create_user("B1")29 self.userB2 = create_user("B2")30 self.groupA = create_group("A", self.userX, self.userA1, self.userA2)31 self.groupB = create_group("B", self.userX, self.userB1, self.userB2)32 def test_sharing(self):33 def create_and_test(case_id, user, owner, should_have, should_not_have):34 case_block = self.get_create_block(35 case_id=case_id,36 type="case",37 user_id=user.user_id,38 owner_id=owner.get_id,39 )40 post_case_blocks([case_block], {'domain': self.domain})41 check_has_block(case_block, should_have, should_not_have)42 def update_and_test(case_id, owner=None, should_have=None, should_not_have=None):43 case_block = self.get_update_block(44 case_id=case_id,45 update={'greeting': "Hello!"},46 owner_id=owner.get_id if owner else None,47 )48 post_case_blocks([case_block], {'domain': self.domain})49 check_has_block(case_block, should_have, should_not_have, line_by_line=False)50 def check_has_block(case_block, should_have, should_not_have, line_by_line=True):51 for user in should_have:52 check_user_has_case(self, user.to_ota_restore_user(), case_block, line_by_line=line_by_line)53 for user in should_not_have:54 check_user_has_case(self, user.to_ota_restore_user(), case_block, should_have=False, line_by_line=line_by_line)55 create_and_test(56 case_id='case-a-1',57 user=self.userA1,58 owner=self.groupA,59 should_have=[self.userA1, self.userA2, self.userX],60 should_not_have=[self.userB1, self.userB2],61 )62 create_and_test(63 case_id='case-b-1',64 user=self.userB1,65 owner=self.groupB,66 should_have=[self.userB1, self.userB2, self.userX],67 should_not_have=[self.userA1, self.userA2],68 )69 create_and_test(70 case_id='case-a-2',71 user=self.userX,72 owner=self.groupA,73 should_have=[self.userA1, self.userA2, self.userX],74 should_not_have=[self.userB1, self.userB2],75 )76 update_and_test(77 case_id='case-a-1',78 should_have=[self.userA1, self.userA2, self.userX],79 should_not_have=[self.userB1, self.userB2],80 )81 update_and_test(82 case_id='case-a-1',83 owner=self.groupB,84 should_have=[self.userB1, self.userB2, self.userX],85 should_not_have=[self.userA1, self.userA2],86 )87 def get_create_block(self, case_id, type, user_id, owner_id, name=None, **kwargs):88 name = name or case_id89 case_block = CaseBlock(90 create=True,91 case_id=case_id,92 case_name=name,93 case_type=type,94 user_id=user_id,95 external_id=case_id,96 owner_id=owner_id,97 **kwargs98 ).as_xml()99 return case_block100 def get_update_block(self, case_id, owner_id=None, update=None):101 update = update or {}102 case_block = CaseBlock(103 case_id=case_id,104 update=update,105 owner_id=owner_id or CaseBlock.undefined,106 ).as_xml()...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selene automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful