示例#1
0
def challenge_setup():
    """Set up some sample data to test with.
    
    This is a bit clearer and hopefully more flexible than using fixtures.
    
    """
    challenge_teardown()  # In case other tests didn't clean up
    
    p = Project()
    p.name = 'My Project'
    p.slug = getattr(settings, 'IGNITE_PROJECT_SLUG', 'my-project')
    p.description = 'My super awesome project of awesomeness.'
    p.long_description = 'Did I mention how awesome it was?'
    p.allow_participation = True
    p.save()
    
    c = Challenge()
    c.project = p
    c.title, 'My Challenge'
    c.slug = getattr(settings, 'IGNITE_CHALLENGE_SLUG', 'my-challenge')
    c.summary = 'Are you up to it?'
    c.description = 'This is a challenge of supreme challengingness.'
    c.end_date = datetime.utcnow() + timedelta(days=365)
    c.save()
    
    ph = Phase()
    ph.challenge = c
    ph.name = 'Ideation'
    ph.order = 1
    ph.save()

    cat = Category()
    cat.name = 'Beer'
    cat.slug = 'beer'
    cat.save()
def challenge_setup():
    """Set up some sample data to test with.
    
    This is a bit clearer and hopefully more flexible than using fixtures.
    
    """
    challenge_teardown()  # In case other tests didn't clean up

    p = Project()
    p.name = 'My Project'
    p.slug = getattr(settings, 'IGNITE_PROJECT_SLUG', 'my-project')
    p.description = 'My super awesome project of awesomeness.'
    p.long_description = 'Did I mention how awesome it was?'
    p.allow_participation = True
    p.save()

    c = Challenge()
    c.project = p
    c.title, 'My Challenge'
    c.slug = getattr(settings, 'IGNITE_CHALLENGE_SLUG', 'my-challenge')
    c.summary = 'Are you up to it?'
    c.description = 'This is a challenge of supreme challengingness.'
    c.end_date = datetime.utcnow() + timedelta(days=365)
    c.save()

    ph = Phase()
    ph.challenge = c
    ph.name = 'Ideation'
    ph.order = 1
    ph.save()

    cat = Category()
    cat.name = 'Beer'
    cat.slug = 'beer'
    cat.save()
示例#3
0
def create_challenge(
    title,
    start_date,
    end_date,
    host_team,
    participant_host_team,
    anon_leaderboard=False,
    is_featured=False,
):
    """
    Creates a challenge.
    """
    evaluation_script = open(
        os.path.join(
            settings.BASE_DIR,
            "examples",
            "example1",
            "sample_evaluation_script.zip",
        ),
        "rb",
    )
    queue = "".join(random.choice(string.ascii_letters) for _ in range(75))
    year = datetime.date.today().year
    # add UUID here
    uuid_stamp = uuid.uuid4().hex[0:10]
    slug = "{t}-{y}-{z}".format(t=title, y=year, z=uuid_stamp)
    slug = slug.lower().replace(" ", "-")[:198]
    image_file = ContentFile(get_file_content(CHALLENGE_IMAGE_PATH, "rb"),
                             "logo.png")
    challenge = Challenge(
        title=title,
        short_description=fake.paragraph(),
        description=fake.paragraph(),
        terms_and_conditions=fake.paragraph(),
        submission_guidelines=fake.paragraph(),
        evaluation_details=fake.paragraph(),
        evaluation_script=SimpleUploadedFile(evaluation_script.name,
                                             evaluation_script.read()),
        approved_by_admin=True,
        leaderboard_description=fake.paragraph(),
        creator=host_team,
        published=True,
        enable_forum=True,
        anonymous_leaderboard=anon_leaderboard,
        start_date=start_date,
        end_date=end_date,
        queue=queue,
        featured=is_featured,
        image=image_file,
    )
    challenge.save()

    challenge.slug = slug
    challenge.participant_teams.add(participant_host_team)
    challenge.save()

    print(
        "Challenge created with title: {} creator: {} start_date: {} end_date: {}"
        .format(title, host_team.team_name, start_date, end_date))