def test_run(self): r = Run(num_agents=100, ticks=10) out = r.run() self.assertTrue(r is not None) self.assertEqual(out.ticks, 10) self.assertEqual(out.params['num_agents'], 100) self.assertEqual(len(out.data), out.ticks) r = Run(num_agents=10, ticks=100) out = r.run() self.assertEqual(out.ticks, 100) self.assertEqual(out.params['num_agents'], 10) self.assertEqual(len(out.data), out.ticks)
def test_serialization(self): u = User.objects.create(username='******') rr = RunRecord.objects.create(user=u) r = Run(ticks=100) rr.from_run(r) out = r.run() ror = RunOutputRecord.objects.create(run=rr) ror.from_runoutput(out) out2 = ror.get_runoutput() self.assertEqual(out.ticks, out2.ticks)
def test_run_json(self): u = User.objects.create(username='******') rr = RunRecord.objects.create(user=u) r = Run(ticks=10, number_agents=10) rr.from_run(r) ror = RunOutputRecord.objects.create(run=rr) out = r.run() ror.from_runoutput(out) response = self.c.get("/run/%d/json/" % rr.id) self.assertEquals(response.status_code, 200) self.assertTrue("agents_mass" in response.content)
def test_compare_runs(self): u = User.objects.create(username='******') rr = RunRecord.objects.create(user=u) r = Run(ticks=10, number_agents=10) rr.from_run(r) ror = RunOutputRecord.objects.create(run=rr) out = r.run() ror.from_runoutput(out) response = self.c.get("/run/compare/?run_%d=on" % rr.id) self.assertEquals(response.status_code, 200) self.assertTrue("makeGraph" in response.content)
def test_run(self): u = User.objects.create(username='******') rr = RunRecord.objects.create(user=u) r = Run(ticks=10, number_agents=10) rr.from_run(r) ror = RunOutputRecord.objects.create(run=rr) out = r.run() ror.from_runoutput(out) response = self.c.get("/run/%d/" % rr.id) self.assertEquals(response.status_code, 200) self.assertContains(response, "<h2>Saved Run: ")
def test_run_json(self): u = User.objects.create(username='******') rr = RunRecord.objects.create(user=u) r = Run(ticks=10, number_agents=10) rr.from_run(r) ror = RunOutputRecord.objects.create(run=rr) out = r.run() ror.from_runoutput(out) response = self.c.get("/run/%d/json/" % rr.id) self.assertEquals(response.status_code, 200) self.assertContains(response, "agents_mass")
def test_compare_runs(self): u = User.objects.create(username='******') rr = RunRecord.objects.create(user=u) r = Run(ticks=10, number_agents=10) rr.from_run(r) ror = RunOutputRecord.objects.create(run=rr) out = r.run() ror.from_runoutput(out) response = self.c.get("/run/compare/?run_%d=on" % rr.id) self.assertEquals(response.status_code, 200) self.assertContains(response, "makeGraph")
def test_run(self): u = User.objects.create(username='******') rr = RunRecord.objects.create(user=u) r = Run(ticks=10, number_agents=10) rr.from_run(r) ror = RunOutputRecord.objects.create(run=rr) out = r.run() ror.from_runoutput(out) response = self.c.get("/run/%d/" % rr.id) self.assertEquals(response.status_code, 200) self.assertTrue("<h2>Saved Run: " in response.content)
def post(self, request): form = RunForm(request.POST) if form.is_valid(): parameters = dict() for f in ALL_FIELDS: parameters[f] = form.cleaned_data[f] r = Run(**parameters) rr = RunRecord() rr.user = request.user rr.from_run(r) out = r.run() ror = RunOutputRecord(run=rr) skew_params = dict(mass=0., intake=0., expenditure=0.) if waffle.flag_is_active(request, 'demo_mode'): skew_params = apply_skews(request, skew_params) ror.from_runoutput(out, skew_params) return HttpResponseRedirect(rr.get_absolute_url()) return render( request, self.template_name, dict(form=form, interventions=Intervention.objects.all(), parameters=Parameter.objects.all()))
def test_runoutputserialization(self): r = Run(num_agents=100, ticks=10) out = r.run() d = out.to_dict() self.assertTrue('data' in d) self.assertEqual(d['ticks'], 10)