Skip to content

Commit

Permalink
Merge branch '20-restrict-namedcmd-urls' of git://github.com/grooveco…
Browse files Browse the repository at this point in the history
…der/scrumbugz
  • Loading branch information
pmac committed Mar 27, 2012
2 parents 1096397 + 9050197 commit 6bf0a7c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
7 changes: 6 additions & 1 deletion scrum/forms.py
Expand Up @@ -5,6 +5,7 @@

class ProjectForm(forms.ModelForm):
template_title = 'Project'

class Meta:
model = Project

Expand Down Expand Up @@ -46,5 +47,9 @@ class Meta:
def clean_bz_url(self):
url = self.cleaned_data['bz_url']
if not url.startswith('https://bugzilla.mozilla.org/buglist.cgi?'):
raise forms.ValidationError('Must be a valid bugzilla.mozilla.org URL.')
raise forms.ValidationError('Must be a valid bugzilla.mozilla.org '
'URL.')
if 'cmdtype' in url or 'namedcmd' in url:
raise forms.ValidationError('Cannot use named commands or saved '
'searches.')
return url
10 changes: 7 additions & 3 deletions scrum/models.py
Expand Up @@ -96,9 +96,13 @@ def get_bugs(self):
if not hasattr(self, '_bugs'):
data = cache.get(self._bugs_cache_key)
if data is None:
data = BZAPI.bug.get(**self._get_bz_args())
data['date_received'] = datetime.now()
cache.set(self._bugs_cache_key, data, CACHE_BUGS_FOR)
try:
data = BZAPI.bug.get(**self._get_bz_args())
data['date_received'] = datetime.now()
cache.set(self._bugs_cache_key, data, CACHE_BUGS_FOR)
except:
raise Exception("Couldn't retrieve bugs from "
"Bugzilla")
self._bugs = [Bug(b) for b in data['bugs']]
self.date_cached = data.get('date_received', datetime.now())
return self._bugs
Expand Down
44 changes: 44 additions & 0 deletions scrum/tests.py
Expand Up @@ -4,13 +4,29 @@
Replace this with more appropriate tests for your application.
"""
from datetime import date

from nose.tools import eq_, ok_

from django.test import TestCase

from forms import SprintForm
from models import Sprint


GOOD_BZ_URL = "https://bugzilla.mozilla.org/buglist.cgi?list_id=2692959;"
"columnlist=opendate%2Cassigned_to%2Cbug_status%2Cresolution%2Cshort_desc"
"%2Cstatus_whiteboard%2Ckeywords;emailtype1=exact;query_based_on=mdn_20120410;"
"status_whiteboard_type=allwordssubstr;query_format=advanced;"
"status_whiteboard=s%3D2012-04-10;email1=nobody%40mozilla.org;"
"component=Administration;component=Deki%20Infrastructure;component=Demos;"
"component=Docs%20Platform;component=Documentation%20Requests;"
"component=Engagement;component=Evangelism;component=Forums;"
"component=Localization;component=Upload%20Requests;component=Website;"
"product=Mozilla%20Developer%20Network;target_milestone=---;"
"target_milestone=2.7;known_name=mdn_20120410"


class TestSprint(TestCase):
fixtures = ['test_data.json']

Expand All @@ -26,3 +42,31 @@ def test_get_components(self):
components = self.s.get_components()
eq_(11, len(components))
ok_('Website' in components)


class TestSprintForm(TestCase):

def setUp(self):
self.form_data = {
'project': '1',
'name': 'test',
'slug': 'test',
'start_date': date.today(),
'end_date': date.today(),
'bz_url': ''
}

def test_bugzilla_url(self):
self.form_data.update({"bz_url": "http://localhost/?bugs"})
form = SprintForm(self.form_data)
eq_(False, form.is_valid())
ok_('bz_url' in form.errors.keys())
self.form_data.update({"bz_url": "https://bugzilla.mozilla.org/"
"buglist.cgi?cmdtype=runnamed;"
"namedcmd=mdn_20120410;list_id=2693036"})
form = SprintForm(self.form_data)
eq_(False, form.is_valid())
ok_('bz_url' in form.errors.keys())
self.form_data.update({"bz_url": GOOD_BZ_URL})
form = SprintForm(self.form_data)
eq_(True, form.is_valid())

0 comments on commit 6bf0a7c

Please sign in to comment.