Skip to content
Browse files

made changes per carl comments in pull request

  • Loading branch information...
1 parent c194e92 commit 8bf78dcb74cf54705763fd290d20698bff6e1202 @camd camd committed
View
2 moztrap/view/lists/cases.py
@@ -8,7 +8,7 @@ class PrefixIDFilter(KeywordFilter):
across prefix and ID. Must match exactly the prefix or the ID, or both, if
both are provided.
- if more than one of these filters is used, they are ORed with each other.rbi
+ if more than one of these filters is used, they are ORed with each other.
"""
View
5 moztrap/view/manage/cases/forms.py
@@ -345,8 +345,9 @@ def save(self, user=None):
for k, v in version_kwargs.items():
setattr(self.instance, k, v)
- self.instance.case.idprefix = idprefix
- self.instance.case.save(force_update=True)
+ if self.instance.case.idprefix != idprefix:
+ self.instance.case.idprefix = idprefix
+ self.instance.case.save(force_update=True)
self.instance.save(force_update=True)
View
3 templates/lists/_case_byline.html
@@ -1,4 +1,3 @@
{% extends 'lists/_byline.html' %}
-{% block id %}<strong>
- <a href="{% url manage_case case_id=item.case.id %}">#{% if item.case.idprefix %}{{ item.case.idprefix }}-{% endif %}{{ item.case.id }}</a></strong>{% endblock id %}
+{% block id %}<strong><a href="{% url manage_case case_id=item.case.id %}">#{% if item.case.idprefix %}{{ item.case.idprefix }}-{% endif %}{{ item.case.id }}</a></strong>{% endblock id %}
View
73 tests/view/lists/test_cases.py
@@ -1,8 +1,8 @@
"""
-Tests for queryset-filtering.
+Tests for test case queryset-filtering by ID and with optional ID prefix.
"""
-
+from sets import Set
from tests import case
from moztrap.view.lists.cases import PrefixIDFilter
@@ -25,14 +25,19 @@ def create_testdata(self):
return testdata
- def test_prefix_and_id(self):
- """prefix and ID"""
- td = self.create_testdata()
+ def filter(self, criteria):
f = PrefixIDFilter("id")
res = f.filter(
self.model.CaseVersion.objects.all(),
- [u"pre-{0}".format(td["cv1"].case.id)],
+ criteria,
)
+ return res
+
+
+ def test_prefix_and_id(self):
+ """prefix and ID"""
+ td = self.create_testdata()
+ res = self.filter([u"pre-{0}".format(td["cv1"].case.id)])
self.assertEqual(res.get().name, "CV 1")
@@ -40,8 +45,7 @@ def test_prefix_and_id(self):
def test_prefix_only(self):
"""prefix only"""
self.create_testdata()
- f = PrefixIDFilter("id")
- res = f.filter(self.model.CaseVersion.objects.all(), [u"pre"])
+ res = self.filter([u"pre"])
self.assertEqual(res.get().name, "CV 1")
@@ -49,58 +53,49 @@ def test_prefix_only(self):
def test_id_only(self):
"""ID only"""
td = self.create_testdata()
- f = PrefixIDFilter("id")
- res = f.filter(
- self.model.CaseVersion.objects.all(),
- [unicode(td["cv1"].case.id)],
- )
+ res = self.filter([unicode(td["cv1"].case.id)])
self.assertEqual(res.get().name, "CV 1")
- def test_id_from_cv1_prefix_from_cv2(self):
- """ID from cv 1, prefix from cv2 gets both"""
+ def test_id_and_prefix_from_different_cases_gets_both(self):
+ """ID from one case and prefix from a different case gets both"""
td = self.create_testdata()
- f = PrefixIDFilter("id")
- res = f.filter(
- self.model.CaseVersion.objects.all(),
- [u"pre", unicode(td["cv2"].case.id)],
- )
+ res = self.filter([u"pre", unicode(td["cv2"].case.id)])
- self.assertEqual([x.name for x in res.all()], ["CV 1", "CV 2"])
+ self.assertEqual(
+ Set([x.name for x in res.all()]),
+ Set(["CV 1", "CV 2"]),
+ )
def test_id_case_without_prefix(self):
"""id when case has no prefix"""
td = self.create_testdata()
- f = PrefixIDFilter("id")
- res = f.filter(
- self.model.CaseVersion.objects.all(),
- [unicode(td["cv2"].case.id)],
- )
+ res = self.filter([unicode(td["cv2"].case.id)])
self.assertEqual(res.get().name, "CV 2")
def test_cases_different_prefix_return_both(self):
- """3 cases have 2 different prefixes OR'ed"""
+ """
+ 3 cases have 2 different prefixes returns cases from both prefixes.
+ """
self.create_testdata()
- f = PrefixIDFilter("id")
- res = f.filter(
- self.model.CaseVersion.objects.all(),
- [u"pre", u"moz"],
- )
+ res = self.filter([u"pre", u"moz"])
- self.assertEqual([x.name for x in res.all()], ["CV 1", "CV 3", "CV 4"])
+ self.assertEqual(
+ Set([x.name for x in res.all()]),
+ Set(["CV 1", "CV 3", "CV 4"]),
+ )
def test_cases_same_prefix_return_both(self):
"""2 cases with no prefixes, IDs OR'ed"""
self.create_testdata()
- f = PrefixIDFilter("id")
- res = f.filter(
- self.model.CaseVersion.objects.all(),
- [u"moz"],
- )
+ res = self.filter([u"moz"])
- self.assertEqual([x.name for x in res.all()], ["CV 3", "CV 4"])
+ self.assertEqual(
+ Set([x.name for x in res.all()]),
+ Set(["CV 3", "CV 4"]),
+ )
View
7 tests/view/manage/cases/test_forms.py
@@ -474,9 +474,12 @@ def form(self):
def test_initial(self):
"""Initial data is populated accurately."""
- c = self.F.CaseFactory.create(idprefix="pref")
cv = self.F.CaseVersionFactory.create(
- case=c, name="a name", description="a desc", status="active")
+ case__prefix="pref",
+ name="a name",
+ description="a desc",
+ status="active",
+ )
self.F.CaseStepFactory.create(
caseversion=cv, instruction="do this", expected="see that")
View
7 tests/view/manage/cases/test_views.py
@@ -228,16 +228,15 @@ def url(self):
def test_id_prefix(self):
- """Details includes description, markdownified safely."""
- c = self.F.CaseFactory.create(idprefix="moo")
- self.cv = self.F.CaseVersionFactory.create(case=c)
+ """Details shows the id prefix"""
+ self.cv = self.F.CaseVersionFactory.create(case__idprefix="moo")
res = self.get(ajax=True)
res.mustcontain("#moo-{0}".format(c.id))
def test_id_no_prefix(self):
- """Details includes description, markdownified safely."""
+ """Details show the id properly when no prefix is specified."""
self.cv = self.F.CaseVersionFactory.create()
res = self.get(ajax=True)

0 comments on commit 8bf78dc

Please sign in to comment.
Something went wrong with that request. Please try again.