Exemplo n.º 1
0
    def testContainsAll(self):
        """Tests if a correct boolean value is returned.
    """
        target = {"wan": 1, "too": 2, "tree": 3}
        keys = ["wan", "too"]
        self.assertTrue(dicts.containsAll(target, keys))

        keys = ["wan", "fore"]
        self.assertFalse(dicts.containsAll(target, keys))

        keys = []
        self.assertTrue(dicts.containsAll(target, keys))
Exemplo n.º 2
0
  def testContainsAll(self):
    """Tests if a correct boolean value is returned.
    """
    target = {'wan': 1, 'too': 2, 'tree': 3}
    keys = ['wan', 'too']
    self.assertTrue(dicts.containsAll(target, keys))

    keys = ['wan', 'fore']
    self.assertFalse(dicts.containsAll(target, keys))

    keys = []
    self.assertTrue(dicts.containsAll(target, keys))
Exemplo n.º 3
0
    def testContainsAll(self):
        """Tests if a correct boolean value is returned.
    """
        target = {'wan': 1, 'too': 2, 'tree': 3}
        keys = ['wan', 'too']
        self.assertTrue(dicts.containsAll(target, keys))

        keys = ['wan', 'fore']
        self.assertFalse(dicts.containsAll(target, keys))

        keys = []
        self.assertTrue(dicts.containsAll(target, keys))
Exemplo n.º 4
0
def seed_many(request, *args, **kwargs):
  """Seeds many instances of the specified type.

    Understands the following GET args:
    start: where to start adding new users at
    end: where to stop adding new users at
    goal: how many users to add in total, implies user_only
    step: how many users to add per request, defaults to 15
    seed_type: the type of entity to seed, should be one of:
      user, org, mentor, student_proposal

    Redirects if end < goal, incrementing both start and end with step.
  """

  get_args = request.GET

  if not dicts.containsAll(get_args, ['goal', 'start', 'end', 'seed_type']):
    return http.HttpResponse('Missing get args.')

  seed_types = {
    'user': (seed_user, User),
    'org': (seed_org, GSoCOrganization),
    'mentor': (seed_mentor, GSoCMentor),
    'student': (seed_student, GSoCStudent),
    'student_proposal': (seed_student_proposal, StudentProposal),
    'survey': (seed_survey, Survey),
    'survey_answer': (seed_survey_answer, SurveyRecord),
    }

  goal = int(get_args['goal'])
  start = int(get_args['start'])
  end = int(get_args['end'])
  step = int(get_args.get('step', '15'))
  seed_type = get_args['seed_type']

  if not seed_type in seed_types:
    return http.HttpResponse('Unknown seed_type: "%s".' % seed_type)

  action, model = seed_types[seed_type]

  for i in range(start, end):
    try:
      props = action(request, i)
    except Error, error:
      return http.HttpResponse(error.message)

    for properties in props if isinstance(props, list) else [props]:
      entity = model(**properties)
      entity.put()
Exemplo n.º 5
0
def seed_many(request, *args, **kwargs):
    """Seeds many instances of the specified type.

    Understands the following GET args:
    start: where to start adding new users at
    end: where to stop adding new users at
    goal: how many users to add in total, implies user_only
    step: how many users to add per request, defaults to 15
    seed_type: the type of entity to seed, should be one of:
      user, org, mentor, student_proposal

    Redirects if end < goal, incrementing both start and end with step.
  """

    get_args = request.GET

    if not dicts.containsAll(get_args, ['goal', 'start', 'end', 'seed_type']):
        return http.HttpResponse('Missing get args.')

    seed_types = {
        'user': (seed_user, User),
        'org': (seed_org, GSoCOrganization),
        'mentor': (seed_mentor, GSoCMentor),
        'student': (seed_student, GSoCStudent),
        'student_proposal': (seed_student_proposal, StudentProposal),
        'survey': (seed_survey, Survey),
        'survey_answer': (seed_survey_answer, SurveyRecord),
    }

    goal = int(get_args['goal'])
    start = int(get_args['start'])
    end = int(get_args['end'])
    step = int(get_args.get('step', '15'))
    seed_type = get_args['seed_type']

    if not seed_type in seed_types:
        return http.HttpResponse('Unknown seed_type: "%s".' % seed_type)

    action, model = seed_types[seed_type]

    for i in range(start, end):
        try:
            props = action(request, i)
        except Error, error:
            return http.HttpResponse(error.message)

        for properties in props if isinstance(props, list) else [props]:
            entity = model(**properties)
            entity.put()