blob: 9689b9552451a624cdd23c74ccefe953c60bf9bb [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.
""" Utilities to manipulate project data."""
from google.appengine.ext import ndb
from seeder import profile as profile_seeder
from soc.modules.gsoc.models import code_sample as code_sample_model
from summerofcode.models import project as project_model
from tests import org_utils
from tests.utils import proposal_utils
TEST_ABSTRACT = 'Test Abstract'
TEST_TITLE = 'Test Title'
TEST_CONTENT = 'Test Content'
def seedNDBProject(
student, program_key, proposal_key=None,
org_key=None, mentor_key=None, **kwargs):
"""Seeds a new project entity.
Args:
student: Profile entity of the student who is an author of the project.
program_key: Key of the program to which the project applies.
proposal_key: Key of the proposal corresponding to the project.
org_key: Key of the organization to which the project is submitted.
mentor_key: Key of the mentor assigned to the project.
Returns:
The newly seeded project entity.
"""
org_key = org_key or org_utils.seedSOCOrganization(program_key).key
mentor_key = mentor_key or profile_seeder.seedProfile(
program_key, mentor_for=[org_key]).key
proposal_key = proposal_key or proposal_utils.seedProposal(
student.key, program_key, org_key=org_key, mentor_key=mentor_key).key
properties = {
'program': ndb.Key.from_old_key(program_key),
'organization': org_key,
'status': project_model.Status.ACCEPTED,
'parent': student.key,
'mentors': [mentor_key],
'proposal': proposal_key,
'title': TEST_TITLE,
'abstract': TEST_ABSTRACT,
'content': TEST_CONTENT,
}
properties.update(**kwargs)
project = project_model.Project(**properties)
project.put()
student.student_data.number_of_projects += 1
student.student_data.project_for_orgs.append(org_key)
student.student_data.project_for_orgs = list(
set(student.student_data.project_for_orgs))
student.put()
return project
def seedCodeSample(project, upload_of_work, **kwargs):
"""Seeds code sample for the specified project.
Args:
project (summerofcode.models.project.Project): Project entity.
upload_of_work (blobstore.BlobKey): Key of the upload of work.
Returns (soc.modules.gsoc.models.code_sample.GSoCCodeSample):
The newly seeded code sample entity.
"""
properties = {
'parent': project.key.to_old_key(),
'user': project.key.parent().parent().to_old_key(),
'program': project.program.to_old_key(),
'org': project.organization.to_old_key(),
'upload_of_work': upload_of_work,
}
properties.update(**kwargs)
code_sample = code_sample_model.GSoCCodeSample(**properties)
code_sample.put()
return code_sample