def boss(request, server_id, boss_id): server = get_object_or_404(Server, pk=server_id) boss = get_object_or_404(Boss, pk=boss_id) form = DeathCountForm # If the user is posting a form, try to submit it if request.method == 'POST' and request.user.is_authenticated(): form = DeathCountForm(request.POST) # IF the form is valid, redirect # otherwise, continue and draw the form with errors if form.is_valid(): messages.success(request, 'Thanks for making Tyria a safer place.') form.save(request.user, boss, server) return HttpResponseRedirect(reverse('server-boss', args=[server.pk, boss.pk])) return render(request, 'boss_details.html', { 'server': server, 'boss': boss, 'deaths': DeathCount.objects.in_spawn_range(boss, server), 'death_form': form, 'server_time': now().astimezone(server.tz) })
def test_matching_submittions_dont_dupe(self): # Submit once form = DeathCountForm(self.data) data = form.save(self.user, self.boss, self.server) self.assertIsNotNone(data) self.assertIsInstance(data, DeathCount) # SUbmit twice form = DeathCountForm(self.data) data = form.save(self.user, self.boss, self.server) self.assertIsNotNone(data) self.assertIsInstance(data, DeathCount) self.assertEqual( DeathCount.objects.count(), 1, "Second matching submission should not create DeathCount") # SUbmit a new time self.data['death_time'] = self.data['death_time'].replace("38", "39") form = DeathCountForm(self.data) data = form.save(self.user, self.boss, self.server) self.assertEqual(DeathCount.objects.count(), 2, "Non-existing submission should create DeathCount")
def test_matching_submittions_dont_dupe(self): # Submit once form = DeathCountForm(self.data) data = form.save(self.user, self.boss, self.server) self.assertIsNotNone(data) self.assertIsInstance(data, DeathCount) # SUbmit twice form = DeathCountForm(self.data) data = form.save(self.user, self.boss, self.server) self.assertIsNotNone(data) self.assertIsInstance(data, DeathCount) self.assertEqual(DeathCount.objects.count(), 1, "Second matching submission should not create DeathCount") # SUbmit a new time self.data['death_time'] = self.data['death_time'].replace("38", "39") form = DeathCountForm(self.data) data = form.save(self.user, self.boss, self.server) self.assertEqual(DeathCount.objects.count(), 2, "Non-existing submission should create DeathCount")
def test_form_save(self): form = DeathCountForm(self.data) data = form.save(self.user, self.boss, self.server) self.assertIsNotNone(data) self.assertIsInstance(data, DeathCount)