示例#1
0
  def testForTheSameOrgIdAndProgram(self):
    """Tests that two orgs cannot have the same id for the same program."""
    # create one organization with the given org ID
    org_properties = {
        'description': TEST_DESCRIPTION,
        'name': TEST_ORG_NAME
        }
    result = org_logic.createOrganization(
        TEST_ORG_ID, self.program.key(), org_properties)
    self.assertTrue(result)

    # try creating another organization with the same org ID but different name
    org_properties = {
        'description': TEST_DESCRIPTION,
        'name': TEST_ORG_NAME[::-1]
        }
    result = org_logic.createOrganization(
        TEST_ORG_ID, self.program.key(), org_properties)
    self.assertFalse(result)

    # check that the organization has old name
    org = ndb.Key(
        org_model.Organization._get_kind(),
        '%s/%s' % (self.program.key().name(), TEST_ORG_ID)).get()
    self.assertEqual(org.name, TEST_ORG_NAME)
示例#2
0
 def testForMissingProperty(self):
   """Tests that org is not created when a required property is missing."""
   # no description property
   org_properties = {'name': TEST_ORG_NAME}
   result = org_logic.createOrganization(
       TEST_ORG_ID, self.program.key(), org_properties)
   self.assertFalse(result)
示例#3
0
  def testForTheSameOrgIdAndDifferentProgram(self):
    """Tests that two orgs cannot have the same id for different programs."""
    # create one organization with the given org ID
    org_properties = {
        'description': TEST_DESCRIPTION,
        'name': TEST_ORG_NAME
        }
    result = org_logic.createOrganization(
        TEST_ORG_ID, self.program.key(), org_properties)
    self.assertTrue(result)

    # create another organization with the given org ID for different program
    other_program = seeder_logic.seed(program_model.Program)
    result = org_logic.createOrganization(
        TEST_ORG_ID, other_program.key(), org_properties)
    self.assertTrue(result)
示例#4
0
 def testForInvalidLogoUrl(self):
   """Tests that org is not created when a link property has invalid values."""
   org_properties = {
       'logo_url': 'http://invalid',
       'name': TEST_ORG_NAME
       }
   result = org_logic.createOrganization(
       TEST_ORG_ID, self.program.key(), org_properties)
   self.assertFalse(result)
示例#5
0
 def testForInvalidIdeasPage(self):
   """Tests that org is not created when a link property has invalid values."""
   org_properties = {
       'ideas_page': 'http://invalid',
       'name': TEST_ORG_NAME
       }
   result = org_logic.createOrganization(
       TEST_ORG_ID, self.program.key(), org_properties,
       models=types.SOC_MODELS)
   self.assertFalse(result)
示例#6
0
  def testPropertiesAreSet(self):
    """Tests that Summer Of Code-specific properties are set correctly."""
    org_properties = {
       'description': TEST_DESCRIPTION,
       'ideas_page': TEST_IDEAS_PAGE,
       'name': TEST_ORG_NAME,
       }
    result = org_logic.createOrganization(
        TEST_ORG_ID, self.program.key(), org_properties,
        models=types.SOC_MODELS)
    self.assertTrue(result)

    # check that organization is created and persisted
    org = ndb.Key(
        org_model.SOCOrganization._get_kind(),
        '%s/%s' % (self.program.key().name(), TEST_ORG_ID)).get()
    self.assertIsNotNone(org)
    self.assertEqual(org.ideas_page, TEST_IDEAS_PAGE)
示例#7
0
  def testOrgAndApplicationCreated(self):
    """Tests that org entity and application are created successfully."""
    org_properties = {
        'description': TEST_DESCRIPTION,
        'logo_url': TEST_LOGO_URL,
        'name': TEST_ORG_NAME
        }
    result = org_logic.createOrganization(
        TEST_ORG_ID, self.program.key(), org_properties)
    self.assertTrue(result)

    # check that organization is created and persisted
    org = ndb.Key(
        org_model.Organization._get_kind(),
        '%s/%s' % (self.program.key().name(), TEST_ORG_ID)).get()
    self.assertIsNotNone(org)
    self.assertEqual(org.org_id, TEST_ORG_ID)
    self.assertEqual(org.description, TEST_DESCRIPTION)
    self.assertEqual(org.logo_url, TEST_LOGO_URL)
    self.assertEqual(org.name, TEST_ORG_NAME)
    self.assertEqual(org.status, org_model.Status.APPLYING)
示例#8
0
def createOrganizationTxn(data, org_id, program_key, org_properties, admin_keys, models):
    """Creates a new organization profile based on the specified properties.

  This function simply calls organization logic's function to do actual job
  but ensures that the entire operation is executed within a transaction.

  Args:
    data: request_data.RequestData for the current request.
    org_id: Identifier of the new organization. Must be unique on
      'per program' basis.
    program_key: Program key.
    org_properties: A dict mapping organization properties to their values.
    admin_keys: List of profile keys of organization administrators for
      this organization.
    models: instance of types.Models that represent appropriate models.

  Returns:
    RichBool whose value is set to True if organization has been successfully
    created. In that case, extra part points to the newly created organization
    entity. Otherwise, RichBool whose value is set to False and extra part is
    a string that represents the reason why the action could not be completed.
  """
    result = org_logic.createOrganization(org_id, program_key, org_properties, models)
    if not result:
        raise exception.BadRequest(message=result.extra)

    for admin_key in admin_keys:
        connection_view.createConnectionTxn(
            data,
            admin_key,
            data.program,
            result.extra,
            conversation_updater.CONVERSATION_UPDATER,
            org_role=connection_model.ORG_ADMIN_ROLE,
            user_role=connection_model.ROLE,
            seen_by_org=True,
            seen_by_user=True,
        )

    return result