Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Tests amended

  • Loading branch information...
commit f1c0a265bfaa609ce7e35e9bcc9a19ebd08056a1 1 parent b68a2e6
@alfredo alfredo authored
View
2  .gitmodules
@@ -15,7 +15,7 @@
url = git://github.com/jsocol/django-waffle.git
[submodule "vendor-local/src/pyelasticsearch"]
path = vendor-local/src/pyelasticsearch
- url = git://github.com/rhec/pyelasticsearch.git
+ url = git://github.com/toastdriven/pyelasticsearch.git
[submodule "vendor-local/src/django-haystack"]
path = vendor-local/src/django-haystack
url = git://github.com/toastdriven/django-haystack.git
View
6 apps/badges/tests/view_tests.py
@@ -22,7 +22,8 @@ def test_submission_badges(self):
}
entry = SubmissionBadge.objects.create(**data)
self.assertTrue(entry.is_published)
- url = reverse('entry_show', args=[self.submission.id])
+ url = reverse('entry_show', kwargs={'entry_id': self.submission.id,
+ 'phase': 'ideas'})
response = self.client.get(url)
self.assertEqual(len(response.context['badge_list']), 1)
@@ -34,6 +35,7 @@ def test_hidden_submission_badges(self):
'is_published': False,
}
SubmissionBadge.objects.create(**data)
- url = reverse('entry_show', args=[self.submission.id])
+ url = reverse('entry_show', kwargs={'entry_id': self.submission.id,
+ 'phase': 'ideas'})
response = self.client.get(url)
self.assertEqual(len(response.context['badge_list']), 0)
View
5 apps/challenges/context_processors.py
@@ -36,7 +36,6 @@ def phases_context_processor(request):
"""Makes the ``Phases`` available in context when templates are rendered"""
context = {}
for slug in ['ideation', 'development']:
- if hasattr(request, slug):
- phase = getattr(request, slug)
- context[slug] = phase if phase else ClosedPhase()
+ phase = getattr(request, slug) if hasattr(request, slug) else None
+ context[slug] = phase if phase else ClosedPhase()
return context
View
29 apps/challenges/models.py
@@ -92,10 +92,6 @@ def get_absolute_url(self):
"""Return this challenge's URL."""
return self._lookup_url('challenge_show')
- def get_entries_url(self):
- """Return the URL for this challenge's entry list."""
- return self._lookup_url('entries_all')
-
def in_six_months():
return datetime.utcnow() + relativedelta(months=6)
@@ -149,7 +145,10 @@ def get_absolute_url(self):
@cached_property
def days_remaining(self):
- time_remaining = self.end_date - datetime.utcnow()
+ now = datetime.utcnow()
+ if not self.is_open:
+ return -1
+ time_remaining = self.end_date - now
return time_remaining.days if time_remaining.days >= 0 else -1
@cached_property
@@ -171,7 +170,9 @@ def current_judging_round(self):
"""Determines what is the current ``PhaseRound`` being judged"""
now = datetime.utcnow()
for item in self.phase_rounds:
- if item.judging_start_date < now and item.judging_end_date > now:
+ if item.judging_start_date and item.judging_end_date \
+ and item.judging_start_date < now \
+ and item.judging_end_date > now:
return item
return None
@@ -200,6 +201,10 @@ def is_open(self):
return False
return self.start_date < now and now < self.end_date
+ @property
+ def is_closed(self):
+ return not self.is_open
+
@cached_property
def has_started(self):
return datetime.utcnow() > self.start_date
@@ -600,12 +605,6 @@ class Meta:
unique_together = (('submission', 'judge'),)
-@receiver(signals.post_save, sender=JudgeAssignment)
-def judgement_flush_cache(instance, **kwargs):
- """Flush the cache for any submissions related to this instance."""
- Submission.objects.invalidate(instance.submission)
-
-
class PhaseRound(models.Model):
"""Rounds for a given ``Phase``"""
name = models.CharField(max_length=255)
@@ -671,7 +670,11 @@ def save(self, *args, **kwargs):
@models.permalink
def get_absolute_url(self):
- return ('entry_show', [self.slug])
+ kwargs = {
+ 'entry_id': self.slug,
+ 'phase': self.submission.phase_slug,
+ }
+ return ('entry_show', [], kwargs)
def update_version(self, new_submission):
"""Updates the current ``SubmissionParent`` version"""
View
3  apps/challenges/tests/fixtures/ignite_fixtures.py
@@ -104,6 +104,9 @@ def create_submission(with_parent=True, **kwargs):
'phase': kwargs['phase'] if 'phase' in kwargs else create_phase(),
'category': kwargs['category'] if 'category' in kwargs else create_category(),
'title': 'My Awesome submission',
+ 'brief_description': 'This is a quick description',
+ 'description': 'Lorem Ipsum long description',
+ 'life_improvements': 'This will benefit mandkind',
}
if kwargs:
defaults.update(kwargs)
View
2  apps/challenges/tests/fixtures/project_fixtures.py
@@ -37,7 +37,7 @@ def challenge_setup():
ph = Phase()
ph.challenge = c
- ph.name = 'Phase 1'
+ ph.name = 'Ideation'
ph.order = 1
ph.save()
View
34 apps/challenges/tests/test_assignment.py
@@ -8,12 +8,12 @@
from django.conf import settings
from challenges.tests.test_judging import judging_setup
-from challenges.management.commands.assign import (get_judge_profiles,
- get_submissions,
- get_assignments)
+from challenges.judging import (get_judge_profiles, get_submissions,
+ get_assignments)
from challenges.models import (Submission, Judgement, JudgeAssignment,
ExclusionFlag, Phase)
from ignite.tests.decorators import ignite_only
+from nose.tools import eq_, ok_
def assignment_setup():
@@ -25,24 +25,24 @@ def assignment_setup():
class AssignmentTest(TestCase):
-
+
+ def setUp(self):
+ assignment_setup()
+ self.phase = Phase.objects.get()
+ self.judging_permission = Permission.objects.get(
+ codename='judge_submission')
+
def assertEvenAssignment(self, assignments):
counts = defaultdict(lambda: 0)
for assignment in assignments:
counts[assignment.judge] += 1
# No judge has more than one submission more than any other
self.assertTrue(max(counts.values()) - min(counts.values()) <= 1)
-
- def setUp(self):
- assignment_setup()
- self.phase = Phase.objects.get()
- self.judging_permission = Permission.objects.get(
- codename='judge_submission')
-
+
def test_get_judges(self):
self.assertEqual(set([j.user.username for j in get_judge_profiles()]),
set(['alex', 'charlie']))
-
+
def test_get_judges_superuser(self):
"""Test superusers aren't automatically returned as judges."""
User.objects.filter(username='bob').update(is_superuser=True)
@@ -103,7 +103,7 @@ def test_no_assigned_judged_submissions(self):
def test_assignments(self):
assignments = get_assignments(submissions=get_submissions(self.phase),
judge_profiles=get_judge_profiles(),
- commit=False)
+ commit=False, judges_per_submission=2)
self.assertEvenAssignment(assignments)
# Check nothing has been saved
self.assertEqual(JudgeAssignment.objects.count(), 0)
@@ -111,7 +111,7 @@ def test_assignments(self):
def test_assignment_commit(self):
assignments = get_assignments(submissions=get_submissions(self.phase),
judge_profiles=get_judge_profiles(),
- commit=True)
+ commit=True, judges_per_submission=2)
self.assertEvenAssignment(assignments)
expected_submissions = (settings.JUDGES_PER_SUBMISSION *
Submission.objects.count())
@@ -128,6 +128,8 @@ def setUp(self):
date = datetime.utcnow() - timedelta(hours=1)
self.phase.start_date = date
self.phase.end_date = date
+ self.phase.judging_start_date = date
+ self.phase.judging_end_date = date + timedelta(days=1)
self.phase.save()
self.judge_profile = User.objects.get(username='alex').get_profile()
@@ -135,6 +137,8 @@ def open_phase(self):
date = datetime.utcnow() + timedelta(hours=1)
self.phase.start_date = datetime.utcnow() - timedelta(hours=1)
self.phase.end_date = date
+ self.phase.judging_start_date = date + timedelta(days=1)
+ self.phase.judging_end_date = date + timedelta(days=2)
self.phase.save()
@ignite_only
@@ -165,7 +169,7 @@ def test_assigned_phase_open(self):
judge=self.judge_profile)
assert self.client.login(username='alex', password='alex')
response = self.client.get('/')
- assert response.context.get('assignment_count') is None
+ eq_(response.context.get('assignment_count'), 0)
@ignite_only
def test_assigned_and_judged(self):
View
6 apps/challenges/tests/test_integration_ignite.py
@@ -395,7 +395,8 @@ def setUp(self):
self.initial_data = setup_development_phase(**setup_ignite_challenge())
category = self.initial_data['category']
self.valid_data = self._get_valid_data(category=category.id,
- repository_url='http://mozilla.com')
+ repository_url='http://mozilla.com',
+ blog_url='http://blog.mozilla.com')
self.client.login(username='bob', password='bob')
def tearDown(self):
@@ -516,7 +517,8 @@ def setUp(self):
self.initial_data = setup_development_rounds_phase(**setup_ignite_challenge())
category = self.initial_data['category']
self.valid_data = self._get_valid_data(category=category.id,
- repository_url='http://mozilla.com')
+ repository_url='http://mozilla.com',
+ blog_url='http://blog.mozilla.com')
del self.valid_data['terms_and_conditions']
# Create a proposal ``Submission`` on the open ``PhaseRound``
self.submission = create_submission(
View
13 apps/challenges/tests/test_judging.py
@@ -220,11 +220,16 @@ def setUp(self):
date = datetime.utcnow() - timedelta(hours=1)
self.phase.start_date = date
self.phase.end_date = date
+ self.phase.judging_start_date = date
+ self.phase.judging_end_date = date + timedelta(hours=3)
self.phase.save()
def open_phase(self):
- date = datetime.utcnow() + timedelta(hours=1)
- self.phase.end_date = date
+ """Open the phase and close the judging period"""
+ now = datetime.utcnow() + timedelta(hours=1)
+ self.phase.end_date = now
+ self.phase.judging_start_date = now + timedelta(days=1)
+ self.phase.judging_end_date = now + timedelta(days=1)
self.phase.save()
@ignite_only
@@ -297,7 +302,7 @@ def test_submit_judge_form(self):
self.assertEqual(answer.rating, 5)
@ignite_only
- def test_submit_judge_form_with_closed_phase(self):
+ def test_submit_judge_form_with_closed_judging_phase(self):
"""Test judging when the Phase has been closed"""
self.open_phase()
submission = Submission.objects.get()
@@ -306,7 +311,7 @@ def test_submit_judge_form_with_closed_phase(self):
post_data = {'notes': 'This submission is acceptable to me.'}
response = self.client.post(submission.get_judging_url(),
data=post_data, follow=True)
- self.assertEqual(response.status_code, 403)
+ self.assertEqual(response.status_code, 404)
@ignite_only
def test_judge_not_assigned(self):
View
93 apps/challenges/tests/test_middleware.py
@@ -8,6 +8,7 @@
from django.conf import settings
from django.test.client import RequestFactory
from test_utils import TestCase
+from nose.tools import ok_, eq_
class TestPhaseMiddleware(TestCase):
@@ -31,54 +32,66 @@ def setUp(self):
def test_ideation_phase_open(self):
PhaseStatusMiddleware().process_view(self.request)
- expected = {
- 'is_open': True,
- 'name': settings.IGNITE_IDEATION_NAME,
- 'days_remaining': 9,
- 'phase_round': None,
- }
- for k, v in expected.items():
- self.assertEqual(self.request.phase[k], v)
- return
-
+ ideation = self.request.ideation
+ ok_(ideation)
+ ok_(ideation.is_open)
+ eq_(ideation.name, settings.IGNITE_IDEATION_NAME)
+ eq_(ideation.days_remaining, 9)
+ eq_(ideation.current_round, None)
+ development = self.request.development
+ eq_(development, self.development)
+ eq_(development.is_open, False)
+ eq_(development.name, settings.IGNITE_DEVELOPMENT_NAME)
+ eq_(development.days_remaining, -1)
+ eq_(development.current_round, None)
class TestIdeationClosedMiddleware(TestPhaseMiddleware):
def setUp(self):
self.initial_data = setup_ideation_phase(is_open=False,
**setup_ignite_challenge())
+ self.ideation = self.initial_data['ideation_phase']
+ self.development = self.initial_data['dev_phase']
super(TestIdeationClosedMiddleware, self).setUp()
def test_ideation_phase_closed(self):
PhaseStatusMiddleware().process_view(self.request)
- expected = {
- 'is_open': False,
- 'name': None,
- 'days_remaining': -1,
- 'phase_round': None,
- }
- for k, v in expected.items():
- self.assertEqual(self.request.phase[k], v)
- return
+ ideation = self.request.ideation
+ ok_(ideation)
+ eq_(ideation.is_open, False)
+ eq_(ideation.name, settings.IGNITE_IDEATION_NAME)
+ eq_(ideation.days_remaining, -1)
+ eq_(ideation.current_round, None)
+ development = self.request.development
+ eq_(development, self.development)
+ eq_(development.is_open, False)
+ eq_(development.name, settings.IGNITE_DEVELOPMENT_NAME)
+ eq_(development.days_remaining, -1)
+ eq_(development.current_round, None)
class TestDevelopmentPhaseMiddleware(TestPhaseMiddleware):
def setUp(self):
self.initial_data = setup_development_phase(**setup_ignite_challenge())
+ self.ideation = self.initial_data['ideation_phase']
+ self.development = self.initial_data['dev_phase']
super(TestDevelopmentPhaseMiddleware, self).setUp()
def test_development_phase_open(self):
PhaseStatusMiddleware().process_view(self.request)
- phase = self.request.phase
- expected = {
- 'is_open': True,
- 'name': settings.IGNITE_DEVELOPMENT_NAME,
- 'days_remaining': 9,
- 'phase_round': 'Round A',
- }
- for k, v in expected.items():
- self.assertEqual(phase[k], v)
+ ideation = self.request.ideation
+ eq_(ideation, self.ideation)
+ eq_(ideation.is_open, False)
+ eq_(ideation.name, settings.IGNITE_IDEATION_NAME)
+ eq_(ideation.days_remaining, -1)
+ eq_(ideation.current_round, None)
+ development = self.request.development
+ eq_(development, self.development)
+ eq_(development.is_open, True)
+ eq_(development.name, settings.IGNITE_DEVELOPMENT_NAME)
+ eq_(development.days_remaining, 9)
+ ok_(development.current_round)
class DevelopmentPhaseClosedMiddleware(TestPhaseMiddleware):
@@ -86,17 +99,21 @@ class DevelopmentPhaseClosedMiddleware(TestPhaseMiddleware):
def setUp(self):
self.initial_data = setup_development_phase(is_round_open=False,
**setup_ignite_challenge())
+ self.ideation = self.initial_data['ideation_phase']
+ self.development = self.initial_data['dev_phase']
super(DevelopmentPhaseClosedMiddleware, self).setUp()
def test_development_phase_closed(self):
PhaseStatusMiddleware().process_view(self.request)
- phase = self.request.phase
- expected = {
- 'is_open': False,
- 'name': settings.IGNITE_DEVELOPMENT_NAME,
- 'days_remaining': -1,
- 'phase_round': None,
- }
- for k, v in expected.items():
- self.assertEqual(phase[k], v)
- return
+ ideation = self.request.ideation
+ eq_(ideation, self.ideation)
+ eq_(ideation.is_open, False)
+ eq_(ideation.name, settings.IGNITE_IDEATION_NAME)
+ eq_(ideation.days_remaining, -1)
+ eq_(ideation.current_round, None)
+ development = self.request.development
+ eq_(development, self.development)
+ eq_(development.is_open, False)
+ eq_(development.name, settings.IGNITE_DEVELOPMENT_NAME)
+ eq_(development.days_remaining, -1)
+ eq_(development.current_round, None)
View
243 apps/challenges/tests/test_views.py
@@ -1,11 +1,9 @@
# Note: not using cStringIO here because then we can't set the "filename"
from StringIO import StringIO
-
from copy import copy
from datetime import datetime, timedelta
-from django.conf import settings
-from django.contrib.auth.models import User
+from django.contrib.auth.models import User, AnonymousUser
from django.contrib.messages import SUCCESS
from django.core.urlresolvers import reverse
from django.db.models import Max
@@ -25,6 +23,12 @@
from challenges.tests.fixtures import (challenge_setup, challenge_teardown,
create_users, create_submissions,
BLANK_EXTERNALS)
+from challenges.tests.fixtures.ignite_fixtures import (setup_ignite_challenge,
+ teardown_ignite_challenge,
+ setup_ideation_phase,
+ create_submission,
+ create_user)
+
from ignite.tests.decorators import ignite_skip, ignite_only
from projects.models import Project
@@ -35,6 +39,8 @@
'process_request',
lambda *args: None)
+development_mock = MagicMock
+development_mock.has_started = False
def _build_request(path=None):
request = Mock()
@@ -57,8 +63,8 @@ class MessageTestCase(TestCase):
def assertSuccessMessage(self, response):
"""Assert that there is a success message in the given response."""
- self.assertEqual(len(response.context['messages']), 1)
- self.assertEqual(list(response.context['messages'])[0].level, SUCCESS)
+ eq_(len(response.context['messages']), 1)
+ eq_(list(response.context['messages'])[0].level, SUCCESS)
class ChallengeEntryTest(TestCase):
@@ -99,7 +105,8 @@ def test_entries_view(self):
"""
submission_titles = create_submissions(4)
- response = self.client.get(Challenge.objects.get().get_entries_url())
+ phase = Phase.objects.get()
+ response = self.client.get(phase.get_absolute_url())
assert_equal(response.status_code, 200)
# Make sure the entries are present and in reverse creation order
assert_equal([s.title for s in response.context['entries'].object_list],
@@ -113,8 +120,8 @@ def test_hidden_entries(self):
hidden_submission = submissions[0]
hidden_submission.is_draft = True
hidden_submission.save()
-
- response = self.client.get(Challenge.objects.get().get_entries_url())
+ phase = Phase.objects.get()
+ response = self.client.get(phase.get_absolute_url())
# Check the draft submission is hidden
assert_equal(set(response.context['entries'].object_list),
set(submissions[1:]))
@@ -129,7 +136,7 @@ def test_winning_entries(self):
entry.save()
response = self.client.get(reverse('entries_winning'))
- self.assertEqual(set(e.title for e in response.context['entries']),
+ eq_(set(e.title for e in response.context['entries']),
set(e.title for e in winners))
@@ -288,24 +295,25 @@ class ShowEntryTest(TestCase):
"""Test functionality of the single entry view."""
def setUp(self):
- challenge_setup()
- create_users()
- self.alex_profile = User.objects.get(username='alex').get_profile()
- s = self.create_submission()
- self.submission = s
- # Entries require a SubmissionParent which acts as a proxy for versions
- self.parent = SubmissionParent.objects.create(submission=s)
- self.submission_path = s.get_absolute_url()
+ self.initial_data = setup_ideation_phase(**setup_ignite_challenge())
+ self.profile = create_user('bob')
+ self.submission = create_submission(created_by=self.profile,
+ phase=self.initial_data['ideation_phase'])
+ self.parent = self.submission.parent
+ self.submission_path = self.submission.get_absolute_url()
+
+ def tearDown(self):
+ teardown_ignite_challenge()
def create_submission(self, **kwargs):
"""Helper to create a ``Submission``"""
defaults = {
- 'phase': Phase.objects.get(),
+ 'phase': self.initial_data['ideation_phase'],
'title': 'A submission',
'brief_description': 'My submission',
'description': 'My wonderful submission',
- 'created_by': self.alex_profile,
- 'category': Category.objects.get()
+ 'created_by': self.profile,
+ 'category': self.initial_data['category'],
}
if kwargs:
defaults.update(kwargs)
@@ -313,7 +321,8 @@ def create_submission(self, **kwargs):
@suppress_locale_middleware
def test_show_entry(self):
- url = reverse('entry_show', args=[self.submission.id])
+ url = reverse('entry_show', kwargs={'entry_id': self.submission.id,
+ 'phase': 'ideas',})
response = self.client.get(url)
assert_equal(response.status_code, 200)
@@ -331,7 +340,7 @@ def test_old_versioned_entry(self):
self.parent.update_version(new_submission)
response = self.client.get(self.submission_path)
assert_equal(response.status_code, 200)
- self.assertEqual(response.context['entry'].title, 'Updated Submission!')
+ eq_(response.context['entry'].title, 'Updated Submission!')
@suppress_locale_middleware
def test_new_versioned_entry(self):
@@ -339,14 +348,15 @@ def test_new_versioned_entry(self):
self.parent.update_version(new_submission)
response = self.client.get(new_submission.get_absolute_url())
assert_equal(response.status_code, 200)
- self.assertEqual(response.context['entry'].title, 'Updated Submission!')
+ eq_(response.context['entry'].title, 'Updated Submission!')
@suppress_locale_middleware
def test_failed_versioned_entry(self):
"""New versioned entries shouldn't change the url"""
new_submission = self.create_submission(title='Updated Submission!')
self.parent.update_version(new_submission)
- url = reverse('entry_show', args=[new_submission.id])
+ url = reverse('entry_show', kwargs={'entry_id': new_submission.id,
+ 'phase': 'ideas'})
response = self.client.get(url)
assert_equal(response.status_code, 404)
@@ -356,6 +366,9 @@ class EditEntryTest(MessageTestCase):
def setUp(self):
challenge_setup()
+ phase = Phase.objects.get()
+ phase.name = 'Ideation'
+ phase.save()
create_users()
admin = User.objects.create_user('admin', 'admin@example.com',
password='admin')
@@ -371,6 +384,9 @@ def setUp(self):
self.view_path = entry.get_absolute_url()
self.edit_path = entry.get_edit_url()
+ def tearDown(self):
+ teardown_ignite_challenge()
+
def open_phase(self):
phase = Phase.objects.get()
@@ -417,7 +433,7 @@ def test_edit_closed_phase(self):
data = self._edit_data()
data.update(BLANK_EXTERNALS)
response = self.client.post(self.edit_path, data, follow=True)
- self.assertEqual(response.status_code, 403)
+ eq_(response.status_code, 404)
@suppress_locale_middleware
def test_anonymous_access(self):
@@ -471,25 +487,25 @@ def test_admin_edit(self):
class EditLinkTest(TestCase):
-
+
def setUp(self):
- challenge_setup()
- create_users()
-
- alex_profile = User.objects.get(username='alex').get_profile()
- create_submissions(1, creator=alex_profile)
-
- submission = Submission.objects.get()
- self.view_path = submission.get_absolute_url()
- self.edit_path = submission.get_edit_url()
-
- ExternalLink.objects.create(submission=submission, name='Foo',
+ self.initial_data = setup_ideation_phase(**setup_ignite_challenge())
+ self.profile = create_user('bob')
+ self.submission = create_submission(created_by=self.profile,
+ phase=self.initial_data['ideation_phase'])
+ self.view_path = self.submission.get_absolute_url()
+ self.edit_path = self.submission.get_edit_url()
+ ExternalLink.objects.create(submission=self.submission, name='Foo',
url='http://example.com/')
- ExternalLink.objects.create(submission=submission, name='Foo',
+ ExternalLink.objects.create(submission=self.submission, name='Foo',
url='http://example.net/')
-
- self.client.login(username='alex', password='alex')
-
+ self.client.login(username='bob', password='bob')
+
+ def tearDown(self):
+ teardown_ignite_challenge()
+ ExternalLink.objects.all().delete()
+ self.client.logout()
+
def _base_form(self):
submission = Submission.objects.get()
return {'title': submission.title,
@@ -497,53 +513,44 @@ def _base_form(self):
'description': submission.description,
'life_improvements': 'This will benefit mankind',
'category': submission.category.id}
-
+
@suppress_locale_middleware
def test_preserve_links(self):
"""Test submission when the links are not changed."""
form_data = self._base_form()
links = ExternalLink.objects.all()
form_data.update(_build_links(2, *map(_form_from_link, links)))
-
response = self.client.post(self.edit_path, form_data)
-
self.assertRedirects(response, self.view_path)
- self.assertEqual(ExternalLink.objects.count(), 2)
-
+ eq_(ExternalLink.objects.count(), 2)
+
@suppress_locale_middleware
def test_remove_links(self):
"""Test submission with blank link boxes.
-
- All the links should be deleted, as the forms are blank.
-
- """
+
+ All the links should be deleted, as the forms are blank."""
form_data = self._base_form()
links = ExternalLink.objects.all()
link_forms = [{'id': link.id} for link in links]
form_data.update(_build_links(2, *link_forms))
-
response = self.client.post(self.edit_path, form_data)
self.assertRedirects(response, self.view_path)
- self.assertEqual(ExternalLink.objects.count(), 0)
-
+ eq_(ExternalLink.objects.count(), 0)
+
@suppress_locale_middleware
def test_add_links(self):
"""Test adding links to a submission without any."""
ExternalLink.objects.all().delete()
-
form_data = self._base_form()
link_forms = [{'name': 'Cheese', 'url': 'http://cheese.com/'},
{'name': 'Pie', 'url': 'http://en.wikipedia.org/wiki/Pie'}]
form_data.update(_build_links(0, *link_forms))
-
response = self.client.post(self.edit_path, form_data)
-
self.assertRedirects(response, self.view_path)
- self.assertEqual(ExternalLink.objects.count(), 2)
-
+ eq_(ExternalLink.objects.count(), 2)
cheese_link = ExternalLink.objects.get(name='Cheese')
- self.assertEqual(cheese_link.url, 'http://cheese.com/')
- self.assertEqual(cheese_link.submission, Submission.objects.get())
+ eq_(cheese_link.url, 'http://cheese.com/')
+ eq_(cheese_link.submission, Submission.objects.get())
class DeleteEntryTest(MessageTestCase):
@@ -551,6 +558,9 @@ class DeleteEntryTest(MessageTestCase):
def setUp(self):
challenge_setup()
create_users()
+ phase = Phase.objects.get()
+ phase.name = 'Ideation'
+ phase.save()
self.alex_profile = User.objects.get(username='alex').get_profile()
submission = self.create_submission()
self.parent = SubmissionParent.objects.create(submission=submission)
@@ -591,14 +601,14 @@ def test_non_owner_access(self):
"""Check that non-owners cannot see the delete form."""
self.client.login(username='bob', password='bob')
response = self.client.get(self.delete_path)
- assert_equal(response.status_code, 403)
+ assert_equal(response.status_code, 404)
@suppress_locale_middleware
def test_non_owner_delete(self):
"""Check that users cannot delete each other's submissions."""
self.client.login(username='bob', password='bob')
response = self.client.post(self.delete_path, {})
- assert_equal(response.status_code, 403)
+ assert_equal(response.status_code, 404)
assert Submission.objects.exists()
@suppress_locale_middleware
@@ -650,7 +660,7 @@ def test_delete_versioned_submission(self):
submission_b = self.create_submission(title='b')
self.parent.update_version(submission_b)
self.client.login(username='alex', password='alex')
- self.client.post(submission_b.get_delete_url(), {})
+ result = self.client.post(submission_b.get_delete_url(), {})
assert_equal((Submission.objects.filter(created_by=self.alex_profile)
.count()), 0)
assert_equal((SubmissionParent.objects
@@ -661,80 +671,6 @@ def test_delete_versioned_submission(self):
.count()), 0)
-class EditEntryPhaseTest(MessageTestCase):
- """Test functionality of the edit entry view for new versions."""
-
- def setUp(self):
- challenge_setup()
- create_users()
- admin = User.objects.create_user('admin', 'admin@example.com',
- password='admin')
- admin.is_superuser = True
- admin.save()
- # Fill in the profile name to stop nag redirects
- admin_profile = admin.get_profile()
- admin_profile.name = 'Admin Adminson'
- admin_profile.save()
- alex_profile = User.objects.get(username='alex').get_profile()
- create_submissions(1, creator=alex_profile)
- self.close_phase()
- entry = Submission.objects.get()
- self.view_path = entry.get_absolute_url()
- self.edit_path = entry.get_edit_url()
- # create new active phase
- challenge = Challenge.objects.get()
- start_date = datetime.utcnow() - timedelta(hours=1)
- end_date = datetime.utcnow() + timedelta(hours=1)
- self.phase = Phase.objects.create(challenge=challenge,
- name='New Phase',
- start_date=start_date,
- end_date=end_date, order=2)
-
- def open_phase(self):
- phase = Phase.objects.get()
- phase.start_date = datetime.utcnow() - timedelta(hours=1)
- phase.end_date = datetime.utcnow() + timedelta(hours=1)
- phase.save()
-
- def close_phase(self):
- phase = Phase.objects.get()
- phase.start_date = datetime.utcnow() - timedelta(hours=1)
- phase.end_date = datetime.utcnow() - timedelta(hours=1)
- phase.save()
-
- def _edit_data(self, submission=None):
- if submission is None:
- submission = Submission.objects.get()
- return dict(title=submission.title,
- brief_description='Versioned Submission',
- description='A really, seriously good submission',
- category=submission.category.id,
- life_improvements='A lot of improvement')
-
- @suppress_locale_middleware
- def test_edit_form(self):
- self.client.login(username='alex', password='alex')
- response = self.client.get(self.edit_path)
- assert_equal(response.status_code, 200)
-
- @suppress_locale_middleware
- def test_edit(self):
- """Test an edit when there is a new Phase"""
- self.client.login(username='alex', password='alex')
- data = self._edit_data()
- data.update(BLANK_EXTERNALS)
- response = self.client.post(self.edit_path, data, follow=True)
- self.assertRedirects(response, self.view_path)
- # Check for a success message
- self.assertSuccessMessage(response)
- parent = SubmissionParent.objects.get()
- self.assertEqual(parent.name, data['title'])
- # Make sure it was cloned
- assert_equal(parent.submission.brief_description, data['brief_description'])
- assert_equal(parent.submission.phase, self.phase)
- assert_equal(Submission.objects.count(), 2)
-
-
class SubmissionHelpViewTest(TestCase):
def setUp(self):
challenge_setup()
@@ -766,43 +702,40 @@ def create_submission_help(self, **kwargs):
def test_submission_help_anon(self):
response = self.client.get(self.help_url)
- self.assertEqual(response.status_code, 302)
+ eq_(response.status_code, 302)
self.assertTrue(reverse('login') in response['Location'])
response = self.client.post(self.help_url, self.valid_data)
- self.assertEqual(response.status_code, 302)
+ eq_(response.status_code, 302)
self.assertTrue(reverse('login') in response['Location'])
def test_submission_help_not_owner(self):
self.client.login(username='bob', password='bob')
response = self.client.get(self.help_url)
- self.assertEqual(response.status_code, 404)
+ eq_(response.status_code, 404)
response = self.client.post(self.help_url, self.valid_data)
- self.assertEqual(response.status_code, 404)
+ eq_(response.status_code, 404)
def test_submission_published_help(self):
self.client.login(username='alex', password='alex')
response = self.client.get(self.help_url)
- self.assertEqual(response.status_code, 200)
- response = self.client.post(self.help_url, self.valid_data,
- follow=True)
- self.assertRedirects(response, self.submission_a.get_absolute_url())
- for item in list(response.context['messages']):
- self.assertEqual(item.tags, 'success')
- self.assertEqual(SubmissionHelp.objects.get_active().count(), 1)
+ eq_(response.status_code, 200)
+ response = self.client.post(self.help_url, self.valid_data)
+ ok_(self.submission_a.get_absolute_url() in response['Location'])
+ eq_(SubmissionHelp.objects.get_active().count(), 1)
def test_submission_help_listing(self):
self.create_submission_help()
response = self.client.get(reverse('entry_help_list'))
- self.assertEqual(response.status_code, 200)
+ eq_(response.status_code, 200)
page = response.context['page']
- self.assertEqual(page.paginator.count, 1)
+ eq_(page.paginator.count, 1)
def test_submission_help_list_hidden(self):
self.create_submission_help(status=SubmissionHelp.DRAFT)
response = self.client.get(reverse('entry_help_list'))
- self.assertEqual(response.status_code, 200)
+ eq_(response.status_code, 200)
page = response.context['page']
- self.assertEqual(page.paginator.count, 0)
+ eq_(page.paginator.count, 0)
def store_rendered_templates(store, signal, sender, template, context, **kwargs):
@@ -834,10 +767,14 @@ def setUp(self):
def test_add_submission_get(self):
request = self.factory.get('/')
+ request.user = AnonymousUser()
+ request.development = development_mock
response = views.add_submission(request, self.ideation)
eq_(response.status_code, 200)
def test_invalid_form(self):
- request = self.factory.post('/', {})
+ request = self.factory.post('/', BLANK_EXTERNALS)
+ request.user = AnonymousUser()
+ request.development = development_mock
response = views.add_submission(request, self.ideation)
eq_(response.status_code, 200)
View
19 apps/challenges/views.py
@@ -174,7 +174,7 @@ def entries_assigned(request, project, challenge):
def entries_judged(request, project, challenge):
submissions = (Submission.objects
.select_related('judgement__judginganswer__criterion')
- .filter(judgement__isnull=False))
+ .filter(judgement__isnull=False).distinct())
for submission in submissions:
judgements = [j for j in submission.judgement_set.all() if j.complete]
total = sum(j.get_score() for j in judgements)
@@ -484,6 +484,7 @@ def submission_edit(request, submission, phase, form_class=EntryForm,
# it is duplicated and archived
submission = archive_submission(submission, form, link_form,
phase)
+ messages.success(request, "Your submission has been updated.")
return HttpResponseRedirect(submission.get_absolute_url())
else:
error_count = get_list_count(form.errors,
@@ -506,10 +507,10 @@ def submission_edit(request, submission, phase, form_class=EntryForm,
def entry_edit(request, project, challenge, pk, phase):
"""Edit ``Submission`` ideas mechanics"""
phase = get_phase_or_404(phase)
- form_class = EntryForm if phase.is_ideation else DevelopmentEntryForm
# Ideation phase must be open
if not phase or not phase.is_open:
raise Http404
+ form_class = EntryForm if phase.is_ideation else DevelopmentEntryForm
extra_context = {
'project': project,
'challenge': challenge,
@@ -522,8 +523,7 @@ def entry_edit(request, project, challenge, pk, phase):
# Ideas ``Submissions`` can't be turned into Proposals
if not submission.phase == phase:
raise Http404
- return submission_edit(request, submission, phase,
- form_class=form_class,
+ return submission_edit(request, submission, phase, form_class=form_class,
extra_context=extra_context)
@@ -535,7 +535,7 @@ def entry_delete(request, project, challenge, pk, phase):
profile = request.user.get_profile()
try:
parent = (SubmissionParent.objects.select_related('submission')
- .get(slug=pk, submission__phase__challenge=challenge,
+ .get(submission__pk=pk, submission__phase__challenge=challenge,
submission__phase=phase,
submission__created_by=profile))
except SubmissionParent.DoesNotExist:
@@ -544,6 +544,9 @@ def entry_delete(request, project, challenge, pk, phase):
# Remove all the versioned content from the Parent, since
# the User don't want to keep any versions of this ``Submission``
for old_submission in parent.submissionversion_set.all():
+ # remove submissoin
+ old_submission.submission.delete()
+ # remove version
old_submission.delete()
# Remove the current ``Submission``
parent.submission.delete()
@@ -568,12 +571,10 @@ def entry_help(request, project, challenge, entry_id):
# and it only shows the current revision
try:
parent = (SubmissionParent.objects.select_related('submission')
- .get(slug=entry_id, submission__phase__challenge=challenge))
+ .get(slug=entry_id, submission__phase__challenge=challenge,
+ submission__created_by=request.user.get_profile()))
except SubmissionParent.DoesNotExist:
raise Http404
- # Make sure the user can edit the submission
- if not parent.submission.editable_by(request.user):
- raise Http404
try:
help_instance = parent.submissionhelp
except SubmissionHelp.DoesNotExist:
View
14 apps/innovate/tests/test_views.py
@@ -1,7 +1,9 @@
from django.core.urlresolvers import reverse
+from django.contrib.auth.models import AnonymousUser
from django.test import Client
from django.test.client import RequestFactory
+from mock import MagicMock
from projects.models import Project
from ignite.tests.decorators import ignite_skip
from innovate import urls
@@ -34,13 +36,21 @@ def test_featured():
assert response.status_code == 200
assert project.name in response.content
+development = MagicMock
+development.has_started = False
def test_404_handler():
"""Test that the 404 error handler renders and gives the correct code."""
- response = handle404(RequestFactory().get('/not/a/real/path/'))
+ request = RequestFactory().get('/not/a/real/path/')
+ request.user = AnonymousUser()
+ request.development = development
+ response = handle404(request)
assert response.status_code == 404
def test_500_handler():
"""Test that the 500 error handler renders and gives the correct code."""
- response = handle500(RequestFactory().get('/not/a/real/path/'))
+ request = RequestFactory().get('/not/a/real/path/')
+ request.user = AnonymousUser()
+ request.development = development
+ response = handle500(request)
assert response.status_code == 500
View
4 apps/innovate/views.py
@@ -30,9 +30,9 @@ def about(request):
def handle404(request):
"""Handle 404 responses."""
- return jingo.render(request, 'handlers/404.html', status=404)
+ return jingo.render(request, 'handlers/404.html', {}, status=404)
def handle500(request):
"""Handle server errors."""
- return jingo.render(request, 'handlers/500.html', status=500)
+ return jingo.render(request, 'handlers/500.html', {}, status=500)
View
2  apps/search/tests/tests_views.py
@@ -16,7 +16,7 @@ class SearchTest(TestCase):
def setUp(self):
self.profile = create_user('bob')
- self.url = reverse('create_entry')
+ self.url = reverse('create_entry', args=['ideas'])
self.initial_data = setup_development_phase(**setup_ignite_challenge())
self.ideation = self.initial_data['ideation_phase']
self.development = self.initial_data['dev_phase']
View
5 apps/search/views.py
@@ -44,8 +44,3 @@ def create_response(self):
context['suggestion'] = self.form.get_suggestion()
context.update(self.extra_context())
return jingo.render(self.request, self.template, context)
-
- def extra_context(self):
- extra = super(CustomSearchView, self).extra_context()
- extra['days_remaining'] = self.request.phase['days_remaining']
- return extra
View
2  apps/timeslot/tests/tests_views.py
@@ -18,7 +18,7 @@ class TimeSlotBaseTest(TestCase):
def setUp(self):
self.profile = create_user('bob')
- self.url = reverse('create_entry')
+ self.url = reverse('create_entry', args=['ideas'])
def tearDown(self):
teardown_ignite_challenge()
View
2  apps/webcast/tests/test_views.py
@@ -19,7 +19,7 @@ class WebcastTestBase(TestCase):
def setUp(self):
self.profile = create_user('bob')
- self.url = reverse('create_entry')
+ self.url = reverse('create_entry', args=['ideas'])
def tearDown(self):
teardown_ignite_challenge()
View
3  templates_ignite/base.html
@@ -32,7 +32,8 @@
<nav>
<ul>
<li><a href="{{ url('about_ignite') }}">{{ _('About the challenge') }}</a></li>
- <li><a href="{{ url('entries_all') }}">{{ _('Ideas') }}</a></li>
+ <li><a href="{{ url('entries_all', phase='ideas') }}">{{ _('Ideas') }}</a></li>
+ {% if development.has_started %}<li><a href="{{ url('entries_all', phase='proposals') }}">{{ _('Proposals') }}</a></li>{% endif %}
{% if waffle.switch('show_judges') %}
<li><a href="{{ url('our_judges') }}">{{ _('Judges') }}</a></li>
{% endif %}
View
9 templates_ignite/search/search.html
@@ -1,6 +1,13 @@
{% extends "challenges/all.html" %}
-{% block title_listing %}Search Ideas{% endblock title_listing %}
+
+{% block header %}
+<header class="busta">
+<h1 class="shout">
+Search submissions
+</h1>
+</header>
+{% endblock %}
{% block content %}
<div class="content_columns columns with_nav">
View
2  urls_ignite.py
@@ -59,7 +59,7 @@
'challenges.views',
url(r'^ideas/v/(?P<entry_id>\d+)/$', 'entry_version',
kwargs=_ignite_kwargs, name='entry_version'),
- url(r'^ideas/(?P<entry_id>\d+)/help/$', 'entry_help',
+ url(r'^submissions/(?P<entry_id>\d+)/help/$', 'entry_help',
kwargs=_ignite_kwargs, name='entry_help'),
url(r'^ideas/help-wanted/$', 'entry_help_list',
kwargs=_ignite_kwargs, name='entry_help_list'),
2  vendor-local/src/pyelasticsearch
@@ -1 +1 @@
-Subproject commit bf72826a3fc768f3fe0238b42f33c4fb450c6261
+Subproject commit 3bfe1a90eab6c2dfb0989047212f4bc9fb814803
Please sign in to comment.
Something went wrong with that request. Please try again.