示例#1
0
  def setUp(self):
    super(ManageInviteTest, self).setUp()
    self.init()

    self.invitee = self._invitee()
    self.invite = GCIInviteHelper().createOrgAdminInvite(
        self.org, self.invitee.user)
示例#2
0
  def testSecondInviteForbidden(self):
    self.data.createOrgAdmin(self.org)
    invitee = self._invitee()

    GCIInviteHelper().createMentorInvite(self.org, invitee.user)

    post_data = {
        'identifiers': invitee.user.link_id,
        }
    response = self.post(self._inviteMentorUrl(), post_data)
    self.assertResponseOK(response)
    self._assertFormValidationError(response, 'identifiers')
示例#3
0
  def testOrgAdminInviteAfterMentorInvite(self):
    self.data.createOrgAdmin(self.org)
    invitee = self._invitee()

    GCIInviteHelper().createMentorInvite(self.org, invitee.user)

    post_data = {
        'identifiers': invitee.user.link_id,
        }
    response = self.post(self._inviteOrgAdminUrl(), post_data)
    self.assertResponseRedirect(response,
        '/gci/dashboard/%s' % self.gci.key().name())

    invite = GCIRequest.all().filter('role =', 'org_admin').get()
    self.assertPropertiesEqual(self._defaultOrgAdminInviteProperties(), invite)
示例#4
0
  def testMentorInviteAfterOrgAdminInvite(self):
    # TODO(dhans): this test should fail in the future:
    # a existing mentor invite should be extended to become org_admin one

    self.data.createOrgAdmin(self.org)
    invitee = self._invitee()

    GCIInviteHelper().createOrgAdminInvite(self.org, invitee.user)

    post_data = {
        'identifiers': invitee.user.link_id,
        }
    response = self.post(self._inviteMentorUrl(), post_data)
    self.assertResponseRedirect(response,
        '/gci/dashboard/%s' % self.gci.key().name())

    invite = GCIRequest.all().filter('role =', 'mentor').get()
    self.assertPropertiesEqual(self._defaultMentorInviteProperties(), invite)
示例#5
0
    def setUp(self):
        super(ManageInviteTest, self).setUp()
        self.init()

        self.invitee = self._invitee()
        self.invite = GCIInviteHelper().createOrgAdminInvite(self.org, self.invitee.user)
示例#6
0
class ManageInviteTest(BaseInviteTest):
    """Tests for Manage Invite views.
  """

    def setUp(self):
        super(ManageInviteTest, self).setUp()
        self.init()

        self.invitee = self._invitee()
        self.invite = GCIInviteHelper().createOrgAdminInvite(self.org, self.invitee.user)

    def assertInviteTemplatesUsed(self, response):
        """Asserts that all the templates are used.
    """
        self.assertGCITemplatesUsed(response)
        self.assertTemplateUsed(response, "v2/modules/gci/invite/base.html")

    def testLoggedInCannotManageInvite(self):
        url = self._manageInviteUrl(self.invite)
        response = self.get(url)
        self.assertResponseForbidden(response)

    def testUserCannotManageInvite(self):
        self.data.createUser()

        url = self._manageInviteUrl(self.invite)
        response = self.get(url)
        self.assertResponseForbidden(response)

    def testMentorCannotManageInvite(self):
        self.data.createMentor(self.org)

        url = self._manageInviteUrl(self.invite)
        response = self.get(url)
        self.assertResponseForbidden(response)

    def testOrgAdminCanInvite(self):
        self.data.createOrgAdmin(self.org)

        url = self._manageInviteUrl(self.invite)
        response = self.get(url)
        self.assertInviteTemplatesUsed(response)

    def testInvalidPostDataForbidden(self):
        self.data.createOrgAdmin(self.org)

        # empty post data
        post_data = {}
        response = self.post(self._manageInviteUrl(self.invite), post_data)
        self.assertResponseCode(response, BadRequest.status)

        # only invalid data
        post_data = {"invalid_field": ""}
        response = self.post(self._manageInviteUrl(self.invite), post_data)
        self.assertResponseCode(response, BadRequest.status)

    def testWithdrawInvite(self):
        self.data.createOrgAdmin(self.org)

        post_data = {"withdraw": ""}
        response = self.post(self._manageInviteUrl(self.invite), post_data)
        self.assertResponseRedirect(response, self._manageInviteUrl(self.invite))

        new_invite = GCIRequest.all().get()
        self.assertTrue(new_invite.status == "withdrawn")

    def testPendingInviteCannotBeResubmitted(self):
        self.data.createOrgAdmin(self.org)

        post_data = {"resubmit": ""}
        response = self.post(self._manageInviteUrl(self.invite), post_data)
        self.assertResponseForbidden(response)

    def testResubmitInvite(self):
        self.data.createOrgAdmin(self.org)

        self.invite.status = "withdrawn"
        self.invite.put()

        post_data = {"resubmit": ""}
        response = self.post(self._manageInviteUrl(self.invite), post_data)
        self.assertResponseRedirect(response, self._manageInviteUrl(self.invite))

        new_invite = GCIRequest.all().get()
        self.assertTrue(new_invite.status == "pending")

    def testAcceptedInviteCannotBeManaged(self):
        self.data.createOrgAdmin(self.org)

        self.invite.status = "accepted"
        self.invite.put()

        post_data = {"resubmit": ""}
        response = self.post(self._manageInviteUrl(self.invite), post_data)
        self.assertResponseForbidden(response)

        post_data = {"withdraw": ""}
        response = self.post(self._manageInviteUrl(self.invite), post_data)
        self.assertResponseForbidden(response)

    def _manageInviteUrl(self, invite):
        return "/gci/invite/manage/%s/%s" % (self.invite.org.scope.key().name(), self.invite.key().id())
示例#7
0
class ManageInviteTest(BaseInviteTest):
  """Tests for Manage Invite views.
  """

  def setUp(self):
    super(ManageInviteTest, self).setUp()
    self.init()

    self.invitee = self._invitee()
    self.invite = GCIInviteHelper().createOrgAdminInvite(
        self.org, self.invitee.user)

  def assertInviteTemplatesUsed(self, response):
    """Asserts that all the templates are used.
    """
    self.assertGCITemplatesUsed(response)
    self.assertTemplateUsed(response, 'v2/modules/gci/invite/base.html')

  def testLoggedInCannotManageInvite(self):
    url = self._manageInviteUrl(self.invite)
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testUserCannotManageInvite(self):
    self.data.createUser()

    url = self._manageInviteUrl(self.invite)
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testMentorCannotManageInvite(self):
    self.data.createMentor(self.org)

    url = self._manageInviteUrl(self.invite)
    response = self.get(url)
    self.assertResponseForbidden(response)

  def testOrgAdminCanInvite(self):
    self.data.createOrgAdmin(self.org)

    url = self._manageInviteUrl(self.invite)
    response = self.get(url)
    self.assertInviteTemplatesUsed(response)

  def testInvalidPostDataForbidden(self):
    self.data.createOrgAdmin(self.org)

    # empty post data
    post_data = {}
    response = self.post(self._manageInviteUrl(self.invite), post_data)
    self.assertResponseCode(response, BadRequest.status)

    # only invalid data
    post_data = {
        'invalid_field': ''
        }
    response = self.post(self._manageInviteUrl(self.invite), post_data)
    self.assertResponseCode(response, BadRequest.status)

  def testWithdrawInvite(self):
    self.data.createOrgAdmin(self.org)

    post_data = {
        'withdraw': ''
        }
    response = self.post(self._manageInviteUrl(self.invite), post_data)
    self.assertResponseRedirect(response, self._manageInviteUrl(self.invite))

    new_invite = GCIRequest.all().get()
    self.assertTrue(new_invite.status == 'withdrawn')

  def testPendingInviteCannotBeResubmitted(self):
    self.data.createOrgAdmin(self.org)

    post_data = {
        'resubmit': ''
        }
    response = self.post(self._manageInviteUrl(self.invite), post_data)
    self.assertResponseForbidden(response)

  def testResubmitInvite(self):
    self.data.createOrgAdmin(self.org)

    self.invite.status = 'withdrawn'
    self.invite.put()

    post_data = {
        'resubmit': ''
        }
    response = self.post(self._manageInviteUrl(self.invite), post_data)
    self.assertResponseRedirect(response, self._manageInviteUrl(self.invite))

    new_invite = GCIRequest.all().get()
    self.assertTrue(new_invite.status == 'pending')

  def testAcceptedInviteCannotBeManaged(self):
    self.data.createOrgAdmin(self.org)

    self.invite.status = 'accepted'
    self.invite.put()

    post_data = {
        'resubmit': ''
        }
    response = self.post(self._manageInviteUrl(self.invite), post_data)
    self.assertResponseForbidden(response)

    post_data = {
        'withdraw': ''
        }
    response = self.post(self._manageInviteUrl(self.invite), post_data)
    self.assertResponseForbidden(response)    

  def _manageInviteUrl(self, invite):
    return '/gci/invite/manage/%s/%s' % (
        self.invite.org.scope.key().name(), self.invite.key().id())