示例#1
0
 def testNoChange(self):
     # 0. If the case is owned by the user, do nothing.
     case = self._make_case(self.user._id, self.user._id)
     self.assertEqual(case.owner_id, self.user._id)
     reconcile_ownership(case, self.user)
     case = CommCareCase.get(case._id)
     self.assertEqual(case.owner_id, self.user._id)
示例#2
0
 def testNoOwner(self):
     # 1. If the case has no owner, make the user the owner.
     case = self._make_case('', '')
     self.assertFalse(case.owner_id)
     reconcile_ownership(case, self.user)
     case = CommCareCase.get(case._id)
     self.assertEqual(case.owner_id, self.user._id)
示例#3
0
    def testRecursiveUpdates(self):
        parent_case = self._make_case(self.other_user._id, self.other_user._id)
        case = self._make_case(self.other_user._id, self.other_user._id,
                               index={'parent': ('parent-case', parent_case._id)})
        subcase1 = self._make_case(self.other_user._id, self.other_user._id,
                                   index={'parent': ('parent-case', case._id)})
        subcase2 = self._make_case(self.other_user._id, self.other_user._id,
                                   index={'parent': ('parent-case', case._id)})
        subsub1 = self._make_case(self.other_user._id, self.other_user._id,
                                  index={'parent': ('parent-case', subcase1._id)})
        subsub2 = self._make_case(self.other_user._id, self.other_user._id,
                                  index={'parent': ('parent-case', subcase1._id)})
        cases = [case, subcase1, subcase2, subsub1, subsub2]
        for c in cases:
            self.assertEqual(self.other_user._id, c.owner_id)
        reconcile_ownership(case, self.user, recursive=True)
        case = CommCareCase.get(case._id)
        owner = get_wrapped_owner(get_owner_id(case))
        self.assertTrue(isinstance(owner, Group))
        self.assertTrue(self.other_user._id in owner.users)
        self.assertTrue(self.user._id in owner.users)
        self.assertTrue(owner.case_sharing)
        self.assertFalse(owner.reporting)
        for c in cases:
            c = CommCareCase.get(c._id)
            self.assertEqual(owner._id, c.owner_id)

        parent_case = CommCareCase.get(parent_case._id)
        self.assertEqual(self.other_user._id, parent_case.owner_id)
示例#4
0
 def testUserAlreadyInGroup(self):
     # 3. If the case has an owner that is a group, and the user is in the group, do nothing.
     group = Group(
         domain=self.domain,
         name='reconciliation test group',
         users=[self.other_user._id, self.user._id],
         case_sharing=True,
     )
     group.save()
     case = self._make_case(self.other_user._id, group._id)
     self.assertEqual(group._id, case.owner_id)
     reconcile_ownership(case, self.user)
     case = CommCareCase.get(case._id)
     self.assertEqual(group._id, case.owner_id)
示例#5
0
 def testUserToGroup(self):
     # 2. If the case has an owner that is a user create a new case sharing group,
     # add that user and the new user to the case sharing group make the group the owner.
     case = self._make_case(self.other_user._id, self.other_user._id)
     self.assertEqual(self.other_user._id, case.owner_id)
     reconcile_ownership(case, self.user)
     case = CommCareCase.get(case._id)
     self.assertNotEqual(self.other_user._id, case.owner_id)
     owner = get_wrapped_owner(get_owner_id(case))
     self.assertTrue(isinstance(owner, Group))
     self.assertTrue(self.other_user._id in owner.users)
     self.assertTrue(self.user._id in owner.users)
     self.assertTrue(owner.case_sharing)
     self.assertFalse(owner.reporting)
示例#6
0
 def testUserAddedToGroup(self):
     # 4. If the case has an owner that is a group, and the user is not in the group,
     #    add the user to the group and the leave the owner untouched.
     group = Group(
         domain=self.domain, name="reconciliation test group", users=[self.other_user._id], case_sharing=True
     )
     group.save()
     case = self._make_case(self.other_user._id, group._id)
     self.assertEqual(group._id, case.owner_id)
     reconcile_ownership(case, self.user)
     case = CommCareCase.get(case._id)
     self.assertEqual(group._id, case.owner_id)
     group = Group.get(group._id)
     self.assertTrue(self.user._id in group.users)
示例#7
0
def set_commtrack_location(user, location):
    user.commtrack_location = location._id
    supply_point_case = SupplyPointCase.get_by_location(location)
    reconcile_ownership(supply_point_case, user)
    user.save()