Ejemplo n.º 1
0
    def testSuccessfulActivation(self):
        """Test that given a valid token and date, an AnonymousConnection will be
    used to activate a new Connection for the user."""
        org = org_utils.seedOrganization(self.program.key())
        profile = profile_utils.seedNDBProfile(self.program.key())

        connection_logic.createAnonymousConnection(
            '*****@*****.**', org, connection_model.ORG_ADMIN_ROLE)

        anonymous_connection = connection_model.AnonymousConnection.all().get()

        connection_logic.activateAnonymousConnection(
            profile, anonymous_connection.token)

        query = connection_model.Connection.query(
            connection_model.Connection.org_role ==
            connection_model.ORG_ADMIN_ROLE,
            ancestor=profile.key)
        connection = query.get()

        self.assertEquals(connection.user_role, connection_model.NO_ROLE)
        self.assertEquals(connection.organization, org.key)

        anonymous_connection = connection_model.AnonymousConnection.all().get()
        self.assertIsNone(anonymous_connection)
Ejemplo n.º 2
0
  def testExpiredConnection(self):
    """Test that a user is prevented from activating a Connection that was
    created more than a week ago."""
    org = org_utils.seedOrganization(self.program.key())
    profile = profile_utils.seedNDBProfile(self.program.key())

    connection_logic.createAnonymousConnection(
        org=org, org_role=connection_model.ORG_ADMIN_ROLE,
        email='*****@*****.**')
    # Cause the anonymous connection to "expire."
    anonymous_connection = connection_model.AnonymousConnection.all().get()
    anonymous_connection.expiration_date = datetime.today() - timedelta(1)
    anonymous_connection.put()

    with self.assertRaises(ValueError):
      connection_logic.activateAnonymousConnection(profile, 'bad token')
Ejemplo n.º 3
0
    def testExpiredConnection(self):
        """Test that a user is prevented from activating a Connection that was
    created more than a week ago."""
        org = org_utils.seedOrganization(self.program.key())
        profile = profile_utils.seedNDBProfile(self.program.key())

        connection_logic.createAnonymousConnection(
            org=org,
            org_role=connection_model.ORG_ADMIN_ROLE,
            email='*****@*****.**')
        # Cause the anonymous connection to "expire."
        anonymous_connection = connection_model.AnonymousConnection.all().get()
        anonymous_connection.expiration_date = datetime.today() - timedelta(1)
        anonymous_connection.put()

        with self.assertRaises(ValueError):
            connection_logic.activateAnonymousConnection(profile, 'bad token')
Ejemplo n.º 4
0
  def testSuccessfulActivation(self):
    """Test that given a valid token and date, an AnonymousConnection will be
    used to activate a new Connection for the user."""
    org = org_utils.seedOrganization(self.program.key())
    profile = profile_utils.seedNDBProfile(self.program.key())

    connection_logic.createAnonymousConnection(
        '*****@*****.**', org, connection_model.ORG_ADMIN_ROLE)

    anonymous_connection = connection_model.AnonymousConnection.all().get()

    connection_logic.activateAnonymousConnection(
        profile, anonymous_connection.token)

    query = connection_model.Connection.query(
        connection_model.Connection.org_role == connection_model.ORG_ADMIN_ROLE,
        ancestor=profile.key)
    connection = query.get()

    self.assertEquals(connection.user_role, connection_model.NO_ROLE)
    self.assertEquals(connection.organization, org.key)

    anonymous_connection = connection_model.AnonymousConnection.all().get()
    self.assertIsNone(anonymous_connection)
Ejemplo n.º 5
0
 def testInvalidToken(self):
     """Test that the function will raise an error if the token does not
 correspond to an AnonymousConnection object."""
     profile = profile_utils.seedNDBProfile(self.program.key())
     with self.assertRaises(ValueError):
         connection_logic.activateAnonymousConnection(profile, 'bad token')
Ejemplo n.º 6
0
 def testInvalidToken(self):
   """Test that the function will raise an error if the token does not
   correspond to an AnonymousConnection object."""
   profile = profile_utils.seedNDBProfile(self.program.key())
   with self.assertRaises(ValueError):
     connection_logic.activateAnonymousConnection(profile, 'bad token')