Skip to content

Commit

Permalink
Merge PR codalab#305
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Poulain committed Jan 25, 2014
1 parent ea8dff4 commit 6dbfeba
Show file tree
Hide file tree
Showing 38 changed files with 657 additions and 543 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
exclude: venv,scripts
ignore: E501,F403
28 changes: 16 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
language: python
python:
- "2.7"
branches:
only:
- master
install:
- pip install -r codalab/requirements/dev_azure_nix.txt --use-mirrors
script:
- cd codalab
- python manage.py test

language: python
python:
- "2.7"
branches:
only:
- master
install:
- "pip install -r codalab/requirements/dev_azure_nix.txt --use-mirrors"
# - "pip install -q flake8 pylint django-nose --use-mirrors"
before_script:
# - "flake8 --config=.flake8 ."
# - "pylint --rcfile=pylint.rc tests"
# - "pylint --rcfile=pylint.rc setup.py"
script:
- "cd codalab"
- "python manage.py test"
2 changes: 0 additions & 2 deletions codalab/apps/api/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from django.db import models

# Create your models here.
67 changes: 37 additions & 30 deletions codalab/apps/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
"""
test for competition creation via api
"""
import sys, os.path, os, random, datetime
import sys
import os.path
import os
import datetime
from django.utils import timezone
from django.core import management

# This is a really, really long way around saying that if the script is in
# codalab\scripts\users.py, we need to add, ../../../codalab to the sys.path to find the settings
root_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "codalab")
# codalab\scripts\users.py, we need to add, ../../../codalab to the
# sys.path to find the settings
root_dir = os.path.join(os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "codalab")
sys.path.append(root_dir)

# Set things for django configurations
Expand All @@ -19,11 +23,8 @@
from configurations import importer
importer.install()

from django.core.files import File
from django.contrib.auth import get_user_model
from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
from django.core import management

from apps.web.models import *

Expand All @@ -34,17 +35,20 @@
current_time = timezone.now()
start_date = current_time - datetime.timedelta(days=1)


class CompetitionsPhase(TestCase):

def setUp(self):
# Get a user to be the creator
self.guest1 = User.objects.create(username="apiguest1")

def create_base_competition(self):
title = "Single-phase competition example"
description = "This is an example of a single-phase competition."
competition,created = Competition.objects.get_or_create(title=title, creator=self.guest1, modified_by=self.guest1, description=description)
return competition;

competition, created = Competition.objects.get_or_create(
title=title, creator=self.guest1, modified_by=self.guest1, description=description)
return competition

# Create a 3 phase test
def test_three_phase_existance(self):
competition = self.create_base_competition()
Expand All @@ -53,12 +57,13 @@ def test_three_phase_existance(self):
day_delta = datetime.timedelta(days=30)
phases = []
for phase in [1, 2, 3]:
phase_start = start_date + (day_delta * (phase-2))
p, created = CompetitionPhase.objects.get_or_create(competition=competition, phasenumber=phase, label="Phase %d" % phase, start_date=phase_start, max_submissions=4)
phases.append(p);

phase_start = start_date + (day_delta * (phase - 2))
p, created = CompetitionPhase.objects.get_or_create(
competition=competition, phasenumber=phase, label="Phase %d" % phase, start_date=phase_start, max_submissions=4)
phases.append(p)

self.assertEqual(len(phases), 3)

# Create three phases, the middle phase should be active
def test_three_phase_middle_active(self):
competition = self.create_base_competition()
Expand All @@ -67,32 +72,34 @@ def test_three_phase_middle_active(self):
day_delta = datetime.timedelta(days=30)
phases = []
for phase in [1, 2, 3]:
phase_start = start_date + (day_delta * (phase-2))
p, created = CompetitionPhase.objects.get_or_create(competition=competition, phasenumber=phase, label="Phase %d" % phase,
start_date=phase_start, max_submissions=4)
phases.append(p);

phase_start = start_date + (day_delta * (phase - 2))
p, created = CompetitionPhase.objects.get_or_create(
competition=competition, phasenumber=phase, label="Phase %d" % phase,
start_date=phase_start, max_submissions=4)
phases.append(p)

self.assertEqual(phases[0].is_active, False)
self.assertEqual(phases[1].is_active, True)
self.assertEqual(phases[2].is_active, False)

# Create two phases, the last phase should be active
def test_two_phase_last_active(self):
competition = self.create_base_competition()

# Phases for the competition
day_delta = datetime.timedelta(days = 30)
day_delta = datetime.timedelta(days=30)
phases = []
for phase in [1, 2]:
phase_start = start_date + (day_delta * (phase-2))
p, created = CompetitionPhase.objects.get_or_create(competition=competition, phasenumber=phase, label="Phase %d" % phase,
start_date=phase_start, max_submissions=4)
phases.append(p);
for phase in [1, 2]:
phase_start = start_date + (day_delta * (phase - 2))
p, created = CompetitionPhase.objects.get_or_create(
competition=competition, phasenumber=phase, label="Phase %d" % phase,
start_date=phase_start, max_submissions=4)
phases.append(p)
print phase_start

self.assertEqual(phases[0].is_active, False);
self.assertEqual(phases[1].is_active, True);
self.assertEqual(phases[0].is_active, False)
self.assertEqual(phases[1].is_active, True)

# Publish / Unpublish Test
# Create a competition
# Get the list of competitions (The new one should not be in it, and the new one should have the published flag set to false)
Expand Down
7 changes: 1 addition & 6 deletions codalab/apps/authenz/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import re

from django.core import validators
from django.core.mail import send_mail
from django.db import models
from django.contrib.auth import models as auth_models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _


class ClUser(auth_models.AbstractUser):
pass
1 change: 1 addition & 0 deletions codalab/apps/authenz/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


class SimpleTest(TestCase):

def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2 (authenz).
Expand Down
4 changes: 2 additions & 2 deletions codalab/apps/web/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
class CompetitionForm(forms.ModelForm):
class Meta:
model = models.Competition
fields = ['title', 'description', 'image', 'has_registration', 'end_date', 'published']
fields = ('title', 'description', 'image', 'has_registration', 'end_date', 'published')

class CompetitionPhaseForm(forms.ModelForm):
class Meta:
model = models.CompetitionPhase
fields = ['phasenumber', 'label', 'start_date', 'max_submissions', 'scoring_program', 'reference_data']
fields = ('phasenumber', 'label', 'start_date', 'max_submissions', 'scoring_program', 'reference_data')

class CompetitionDatasetForm(forms.ModelForm):
class Meta:
Expand Down
33 changes: 16 additions & 17 deletions codalab/apps/web/management/commands/add_participant.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.core.management.base import BaseCommand, CommandError
from apps.web.models import Competition,CompetitionParticipant,ParticipantStatus
from django.core.management.base import BaseCommand
from apps.web.models import Competition, CompetitionParticipant, ParticipantStatus
from django.contrib.auth import get_user_model
User = get_user_model()
User = get_user_model()
from optparse import make_option


class Command(BaseCommand):
help = "Adds a particpant to a competition. If the user does not exist, it will create one."

Expand All @@ -16,28 +17,31 @@ class Command(BaseCommand):
default=None,
help="ID of the competition"),
make_option('--status',
choices=(ParticipantStatus.UNKNOWN,ParticipantStatus.PENDING,ParticipantStatus.APPROVED,ParticipantStatus.DENIED),
choices=(
ParticipantStatus.UNKNOWN, ParticipantStatus.PENDING,
ParticipantStatus.APPROVED, ParticipantStatus.DENIED),
dest='status',
default=ParticipantStatus.PENDING,
help="The initial status of the created participant"
)
)
)

def handle(self, *args, **options):
competition_id = options['competition']
competition = None
if not options['email']:
print " ... Email Required ... "
exit(1)

user,cr = User.objects.get_or_create(email=options['email'], defaults={'username': options['email']})
user, cr = User.objects.get_or_create(
email=options['email'], defaults={'username': options['email']})
if cr:
user.set_password('testing')
user.save()
print "\nNew User Created. Password: testing\n"
while not competition:
if competition_id:
try:
try:
competition = Competition.objects.get(pk=competition_id)
competition_id = competition.pk
break
Expand All @@ -50,21 +54,16 @@ def handle(self, *args, **options):
print " ... There are no competitions ..."
exit(1)
for c in clist:
print " %d) %s" % (c.pk,c.title)
print " %d) %s" % (c.pk, c.title)
try:
competition_id = int(raw_input("\n Enter number --> "))
except ValueError:
print " ... Bad Input ... "
competition_id = None
continue
pstatus = ParticipantStatus.objects.get(codename=options['status'])
part,cr = CompetitionParticipant.objects.get_or_create(user=user,
competition=competition,
defaults={'status':pstatus})
part, cr = CompetitionParticipant.objects.get_or_create(user=user,
competition=competition,
defaults={'status': pstatus})
if not cr:
print " ... Participant already exists ... "





36 changes: 17 additions & 19 deletions codalab/apps/web/management/commands/add_submission.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.core.management.base import BaseCommand, CommandError
from apps.web.models import Competition,CompetitionPhase,CompetitionParticipant,CompetitionSubmission
from django.core.management.base import BaseCommand
from apps.web.models import Competition, CompetitionPhase, CompetitionParticipant, CompetitionSubmission
from django.contrib.auth import get_user_model
User = get_user_model()
User = get_user_model()
from optparse import make_option

from django.core.files.base import File


class Command(BaseCommand):
help = "Creates a submission for a participant"

Expand All @@ -26,8 +27,8 @@ class Command(BaseCommand):
default=None,
help="Path to the submission file"),

)
)

def handle(self, *args, **options):
competition_id = options['competition']
phase_id = options['phase']
Expand All @@ -44,26 +45,27 @@ def handle(self, *args, **options):
user = User.objects.get(email=options['email'])
while not competition and not phase:
if competition_id and phase_id:
try:
phase = CompetitionPhase.objects.get(pk=phase_id, competition__pk=competition_id)
try:
phase = CompetitionPhase.objects.get(
pk=phase_id, competition__pk=competition_id)
break
except Competition.DoesNotExist:
pass
else:
print "Competition/Phase not specified or not valid:\n"

clist = CompetitionPhase.objects.order_by('competition__pk').all()
if not clist:
print " ... There are no competitions ..."
exit(1)
sel = []
i = 0
for c in clist:
sel.append((c.competition,c))
sel.append((c.competition, c))
i = i + 1
print "%d) %s %s" % (i,c.competition,c)
print "%d) %s %s" % (i, c.competition, c)
try:
inp = int(raw_input("\n Enter number --> "))
inp = int(raw_input("\n Enter number --> "))
idx = inp - 1
competition = sel[idx][0]
phase = sel[idx][1]
Expand All @@ -76,12 +78,8 @@ def handle(self, *args, **options):

part = CompetitionParticipant.objects.get(user=user,
competition=competition
)
submission_file = File(open(options['submission'],'rb'))
s = CompetitionSubmission(participant=part, phase=phase, file=submission_file)
)
submission_file = File(open(options['submission'], 'rb'))
s = CompetitionSubmission(
participant=part, phase=phase, file=submission_file)
s.save()





Loading

0 comments on commit 6dbfeba

Please sign in to comment.