def test_merges(self): p1 = mkPlot(self.instance, self.user) p2 = mkPlot(self.instance, self.user) t1 = Tree(plot=p1, species=self.s1, instance=self.instance) t2 = Tree(plot=p2, species=self.s2, instance=self.instance) for tree in (t1, t2): tree.save_with_system_user_bypass_auth() r = HttpRequest() r.REQUEST = { 'species_to_delete': self.s1.pk, 'species_to_replace_with': self.s2.pk } r.user = self.user r.user.is_staff = True merge_species(r, self.instance) self.assertRaises(Species.DoesNotExist, Species.objects.get, pk=self.s1.pk) # Requery the Trees to assert that species has changed t1r = Tree.objects.get(pk=t1.pk) t2r = Tree.objects.get(pk=t2.pk) self.assertEqual(t1r.species.pk, self.s2.pk) self.assertEqual(t2r.species.pk, self.s2.pk)
def test_cant_merge_same_species(self): r = HttpRequest() r.REQUEST = {"species_to_delete": self.s1.pk, "species_to_replace_with": self.s1.pk} r.user = self.user r.user.is_staff = True spcnt = Species.objects.all().count() resp = merge_species(r, self.instance) self.assertEqual(Species.objects.all().count(), spcnt) self.assertEqual(resp.status_code, 400)
def test_cant_merge_same_species(self): r = HttpRequest() r.REQUEST = { 'species_to_delete': self.s1.pk, 'species_to_replace_with': self.s1.pk } r.user = self.user r.user.is_staff = True spcnt = Species.objects.all().count() resp = merge_species(r, self.instance) self.assertEqual(Species.objects.all().count(), spcnt) self.assertEqual(resp.status_code, 400)