def test_update_remote(self, remote_get_user_roles): remote_permissions = Permissions( edit_data=False, edit_reports=True, view_report_list=['corehq.reports.static_report']) # sync with existing local role remote_role1 = self._make_remote_role_json( _id=self.upstream_role1_id, name="test", permissions=remote_permissions.to_json(), ) # create new role remote_role_other = self._make_remote_role_json( _id=uuid.uuid4().hex, name="another", permissions=Permissions().to_json(), assignable_by=[self.upstream_role1_id]) remote_get_user_roles.return_value = [ _clean_json(role) for role in [remote_role1, remote_role_other] ] update_user_roles(self.domain_link) roles = { r.name: r for r in UserRole.objects.get_by_domain(self.linked_domain) } self.assertEqual(3, len(roles)) self.assertEqual(roles['test'].permissions, remote_permissions) self.assertEqual(roles['test'].is_non_admin_editable, False) self.assertEqual(roles['another'].assignable_by, [self.role1.get_id]) self.assertEqual(roles['another'].permissions, Permissions()) self.assertEqual(roles['other_test'].assignable_by, [self.role1.get_id])
def _to_json(role): return _clean_json(role.to_json())