Permalink
Browse files

added tests to 100% coverate

  • Loading branch information...
1 parent 8772543 commit c8916d3fd320174762d3670b8726c30b453ed1b0 @camd camd committed Mar 22, 2013
Showing with 28 additions and 6 deletions.
  1. +3 −6 moztrap/view/manage/suites/forms.py
  2. +25 −0 tests/view/manage/suites/test_forms.py
@@ -61,7 +61,7 @@ def clean_cases(self):
clean_cases.append(case)
# if number is different, then add this to changed data
- if len(self.cleaned_data) is not len(clean_cases):
+ if len(self.cleaned_data["cases"]) is not len(clean_cases):
self.changed_data.append("cases")
return clean_cases
@@ -76,12 +76,9 @@ def save(self, user=None):
if "cases" in self.changed_data:
suite.suitecases.all().delete(permanent=True)
- already_added = []
for i, case in enumerate(self.cleaned_data["cases"]):
- if case.id not in already_added:
- model.SuiteCase.objects.create(
- suite=suite, case=case, order=i, user=user)
- already_added.append(case.id)
+ model.SuiteCase.objects.create(
+ suite=suite, case=case, order=i, user=user)
return suite
@@ -150,6 +150,31 @@ def test_edit_cases(self):
self.assertEqual(set(suite.cases.all()), set([c]))
+ def test_remove_dup_cases(self):
+ """Can edit cases of a suite."""
+ s = self.F.SuiteFactory.create()
+ c = self.F.CaseFactory.create(product=s.product)
+ self.F.SuiteCaseFactory.create(suite=s, case=c)
+ self.F.SuiteCaseFactory.create(suite=s, case=c)
+
+ f = self.form(
+ {
+ "product": str(s.product.id),
+ "name": s.name,
+ "description": s.description,
+ "status": s.status,
+ "cases": [str(c.id), str(c.id)],
+ "cc_version": str(s.cc_version),
+ },
+ instance=s,
+ )
+
+ self.assertTrue(f.is_valid())
+ suite = f.save()
+
+ self.assertEqual(set(suite.cases.all()), set([c]))
+
+
class AddSuiteFormTest(case.DBTestCase):
"""Tests for AddSuiteForm."""

0 comments on commit c8916d3

Please sign in to comment.