Exemplo 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)
Exemplo n.º 2
0
  def testQueryForAnonymousConnection(self):
    """Test that the function will correctly fetch AnonymousConnection objects
    given a valid token."""
    program = program_utils.seedProgram()
    org = org_utils.seedOrganization(program.key())

    connection_logic.createAnonymousConnection(org=org,
        org_role=connection_model.MENTOR_ROLE, email='*****@*****.**')
    token = connection_model.AnonymousConnection.all().get().token
    connection = connection_logic.queryAnonymousConnectionForToken(token)
    self.assertIsNotNone(connection)
Exemplo n.º 3
0
    def testQueryForAnonymousConnection(self):
        """Test that the function will correctly fetch AnonymousConnection objects
    given a valid token."""
        program = program_utils.seedProgram()
        org = org_utils.seedOrganization(program.key())

        connection_logic.createAnonymousConnection(
            org=org,
            org_role=connection_model.MENTOR_ROLE,
            email='*****@*****.**')
        token = connection_model.AnonymousConnection.all().get().token
        connection = connection_logic.queryAnonymousConnectionForToken(token)
        self.assertIsNotNone(connection)
Exemplo n.º 4
0
  def testCreateAnonymousConnection(self):
    """Test that an AnonymousConnection can be created successfully."""
    program = program_utils.seedProgram()
    org = org_utils.seedSOCOrganization(program.key())

    connection_logic.createAnonymousConnection(org=org,
        org_role=connection_model.MENTOR_ROLE, email='*****@*****.**')
    expected_expiration = datetime.today() + timedelta(7)

    connection = connection_model.AnonymousConnection.all().get()
    self.assertEquals(expected_expiration.date(),
        connection.expiration_date.date())
    self.assertEquals(connection_model.MENTOR_ROLE, connection.org_role)
    self.assertEquals('*****@*****.**', connection.email)
Exemplo n.º 5
0
    def testCreateAnonymousConnection(self):
        """Test that an AnonymousConnection can be created successfully."""
        program = program_utils.seedProgram()
        org = org_utils.seedSOCOrganization(program.key())

        connection_logic.createAnonymousConnection(
            org=org,
            org_role=connection_model.MENTOR_ROLE,
            email='*****@*****.**')
        expected_expiration = datetime.today() + timedelta(7)

        connection = connection_model.AnonymousConnection.all().get()
        self.assertEquals(expected_expiration.date(),
                          connection.expiration_date.date())
        self.assertEquals(connection_model.MENTOR_ROLE, connection.org_role)
        self.assertEquals('*****@*****.**', connection.email)
Exemplo n.º 6
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')
Exemplo n.º 7
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')
Exemplo n.º 8
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)