blob: 5632d6be6632e277f77bb76625d7f1ab81555465 [file] [log] [blame]
# Copyright 2014 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Seeder functions for program model."""
import datetime
from google.appengine.ext import ndb
from codein import types as ci_types
from melange import types
from seeder import document as document_seeder
from seeder import sponsor as sponsor_seeder
from seeder import user as user_seeder
from seeder import utils as seeder_utils
from soc.models import program as program_model
from soc.modules.seeder.logic.providers import string as string_provider
from summerofcode import types as soc_types
def seedTimeline(models=types.MELANGE_MODELS,
timeline_id=None, sponsor_key=None, **kwargs):
"""Seeds a new timeline.
Args:
models: Instance of types.Models that represent appropriate models.
timeline_id: Identifier of the new timeline.
sponsor_key: Sponsor key to be used as scope for the timeline.
Returns:
Newly seeded timeline entity.
"""
timeline_id = timeline_id or string_provider.UniqueIDProvider().getValue()
sponsor_key = sponsor_key or sponsor_seeder.seedSponsor().key()
properties = {
'key_name': '%s/%s' % (sponsor_key.name(), timeline_id),
'link_id': timeline_id,
'program_start': seeder_utils.pastDateTime(),
'program_end': seeder_utils.futureDateTime(),
'scope': sponsor_key,
}
properties.update(kwargs)
timeline = models.timeline_model(**properties)
timeline.put()
return timeline
TEST_ACCEPTED_ORGS_MSG = '\n'.join(
('Accepted orgs message', seeder_utils.LOREM_IPSUM))
TEST_REJECTED_ORGS_MSG = '\n'.join(
('Rejected orgs message', seeder_utils.LOREM_IPSUM))
TEST_ORG_MEMBER_WELCOME_MSG = '\n'.join(
('Organization member welcome message', seeder_utils.LOREM_IPSUM))
def seedProgramMessages(
models=types.MELANGE_MODELS, program_key=None, **kwargs):
"""Seeds a new program messages for the specified program.
Args:
models: instance of types.Models that represent appropriate models.
program_key: ndb.Key of program entity.
Returns:
Newly seeded program messages entity.
"""
properties = {
'parent': program_key,
'accepted_orgs_msg': TEST_ACCEPTED_ORGS_MSG,
'rejected_orgs_msg': TEST_REJECTED_ORGS_MSG,
'mentor_welcome_msg': TEST_ORG_MEMBER_WELCOME_MSG,
}
properties.update(kwargs)
program_messages = models.program_messages_model(**properties)
program_messages.put()
return program_messages
TEST_ACCEPTED_STUDENTS_MSG = '\n'.join(
('Accepted students message', seeder_utils.LOREM_IPSUM))
TEST_ACCEPTED_STUDENTS_WELCOME_MSG = '\n'.join(
('Accepted students welcome message', seeder_utils.LOREM_IPSUM))
TEST_REJECTED_STUDENTS_MSG = '\n'.join(
('Rejected students message', seeder_utils.LOREM_IPSUM))
TEST_ACCEPTED_PROPOSAL_ADMIN_MSG = '\n'.join(
('Accepted proposal admin message', seeder_utils.LOREM_IPSUM))
def seedGSoCProgramMessages(program_key=None, **kwargs):
"""Seeds a new program messages for Summer Of Code.
Args:
program_key: Program key for messages.
Returns:
Newly seeded program messages entity.
"""
properties = {
'accepted_students_msg': TEST_ACCEPTED_STUDENTS_MSG,
'accepted_students_welcome_msg': TEST_ACCEPTED_STUDENTS_WELCOME_MSG,
'rejected_students_msg': TEST_REJECTED_STUDENTS_MSG,
'accepted_proposal_admin_msg': TEST_ACCEPTED_PROPOSAL_ADMIN_MSG,
}
properties.update(**kwargs)
return seedProgramMessages(
models=soc_types.SOC_MODELS, program_key=program_key, **properties)
def seedGCIProgramMessages(program_key=None, **kwargs):
"""Seeds a new program messages for Code In.
Args:
program_key: Program key for messages.
Returns:
Newly seeded program messages entity.
"""
return seedProgramMessages(
models=ci_types.CI_MODELS, program_key=program_key)
TEST_PROGRAM_DESCRIPTION = 'Test Program Description'
TEST_PROGRAM_NAME = 'Test Program'
TEST_PROGRAM_SHORT_NAME = 'Program'
TEST_PROGRAM_EVENTS_FRAME_URL = 'https://subdomain.example.tld/events.calendar'
TEST_DOCUMENT_PREFIX = 'program'
TEST_DOCUMENT_TITLE = 'Test Document'
def seedProgram(models=types.MELANGE_MODELS, program_id=None,
sponsor_key=None, timeline_key=None, host=None, **kwargs):
"""Seeds a new program.
Args:
models: instance of types.Models that represent appropriate models.
program_id: Identifier of the new program.
sponsor_key: Sponsor key for the new program.
timeline_key: Timeline key for the new program.
host: Optional user to be set as a host for the new program.
Returns:
Newly seeded program entity.
"""
program_id = program_id or string_provider.UniqueIDProvider().getValue()
sponsor_key = sponsor_key or sponsor_seeder.seedSponsor().key()
timeline_key = timeline_key or seedTimeline(
models=models, timeline_id=program_id, sponsor_key=sponsor_key).key()
properties = {
'scope': sponsor_key,
'sponsor': sponsor_key,
'link_id': program_id,
'program_id': program_id,
'key_name': '%s/%s' % (sponsor_key.name(), program_id),
'name': TEST_PROGRAM_NAME,
'short_name': TEST_PROGRAM_SHORT_NAME,
'description': TEST_PROGRAM_DESCRIPTION,
'timeline': timeline_key,
'status': program_model.STATUS_VISIBLE,
'events_frame_url': TEST_PROGRAM_EVENTS_FRAME_URL,
}
properties.update(kwargs)
program = models.program_model(**properties)
if host:
host.host_for.append(ndb.Key.from_old_key(program.key()))
host.put()
else:
host = user_seeder.seedUser(host_for=[program])
document = document_seeder.seedDocument(
program, prefix=kwargs.get('prefix', TEST_DOCUMENT_PREFIX), author=host)
program.about_page = document
program.events_page = document
program.help_page = document
program.connect_with_us_page = document
program.privacy_policy = document
program.student_forms_upload_header_document = document
program.student_agreement = document_seeder.seedDocument(
program, document_id='student_agreement',
prefix=kwargs.get('prefix', TEST_DOCUMENT_PREFIX), author=host)
program.mentor_agreement = document_seeder.seedDocument(
program, document_id='mentor_agreement',
prefix=kwargs.get('prefix', TEST_DOCUMENT_PREFIX), author=host)
program.org_admin_agreement = document_seeder.seedDocument(
program, document_id='organization_agreement',
prefix=kwargs.get('prefix', TEST_DOCUMENT_PREFIX), author=host)
program.put()
seedProgramMessages(
models=models, program_key=program.key(), **kwargs)
return program
TEST_APP_TASKS_LIMIT = 20
TEST_SLOTS = 1000
def seedGSoCProgram(program_id=None, sponsor_key=None,
timeline_key=None, **kwargs):
"""Seeds a new Summer Of Code program.
Args:
program_id: Identifier of the new program.
sponsor_key: Sponsor key for the new program.
timeline_key: Timeline key for the new program.
Returns:
Newly seeded program entity.
"""
properties = {
'apps_tasks_limit': TEST_APP_TASKS_LIMIT,
'slots': TEST_SLOTS,
'prefix': 'gsoc_program',
}
properties.update(kwargs)
return seedProgram(
models=soc_types.SOC_MODELS, program_id=program_id,
sponsor_key=sponsor_key, timeline_key=timeline_key, **properties)
TEST_MIN_AGE = 13
TEST_MAX_AGE = 17
def seedGCIProgram(program_id=None, sponsor_key=None,
timeline_key=None, **kwargs):
"""Seeds a new Code In program.
Args:
program_id: Identifier of the new program.
sponsor_key: Sponsor key for the new program.
timeline_key: Timeline key for the new program.
Returns:
Newly seeded program entity.
"""
properties = {
'prefix': 'gci_program',
'student_min_age': TEST_MIN_AGE,
'student_max_age': TEST_MAX_AGE,
'student_min_age_as_of': datetime.date.today(),
}
properties.update(kwargs)
return seedProgram(
models=ci_types.CI_MODELS, program_id=program_id,
sponsor_key=sponsor_key, timeline_key=timeline_key, **properties)