def test_save_form_when_topology_has_not_changed(self): topo = TrailFactory() form = TrailForm(instance=topo) self.assertEqual(topo, form.instance) form.cleaned_data = {'topology': topo} form.save() self.assertEqual(topo, form.instance)
def test_document_export(self, get_attributes_html): get_attributes_html.return_value = '<p>mock</p>' self.login() trail = TrailFactory() with open(trail.get_map_image_path(), 'w') as f: f.write('***' * 1000) response = self.client.get(trail.get_document_url()) self.assertEqual(response.status_code, 200)
def test_add_trail_from_existing_topology_does_not_use_pk(self): import bs4 self.login() trail = TrailFactory(offset=3.14) response = self.client.get(Trail.get_add_url() + '?topology=%s' % trail.pk) soup = bs4.BeautifulSoup(response.content) textarea_field = soup.find(id="id_topology") self.assertIn('"kind": "TOPOLOGY"', textarea_field.text) self.assertIn('"offset": 3.14', textarea_field.text) self.assertNotIn('"pk": %s' % trail.pk, textarea_field.text)
def test_add_trail_from_existing_topology(self): self.login() trail = TrailFactory() form_data = self.get_good_data() form_data['topology'] = trail.serialize(with_pk=False) response = self.client.post(Trail.get_add_url(), form_data) self.assertEqual(response.status_code, 302) # success, redirects to detail view p = re.compile(r"http://testserver/trail/(\d+)/") m = p.match(response['Location']) new_pk = int(m.group(1)) new_trail = Trail.objects.get(pk=new_pk) self.assertIn(trail, new_trail.trails.all())
def test_detail_page(self): self.login() trail = TrailFactory() response = self.client.get(trail.get_detail_url()) self.assertEqual(response.status_code, 200)
def setUp(self): self.trail1 = TrailFactory(no_path=True) self.trail2 = TrailFactory(no_path=True) self.path = PathFactory() self.trail1.add_path(self.path) self.trail2.add_path(self.path)
def setUp(self): self.path = PathFactory() self.trail = TrailFactory(paths=[(self.path, 0, 1)])
def setUp(self): self.path = PathFactory() self.trail1 = TrailFactory(paths=[self.path]) self.trail2 = TrailFactory(paths=[self.path])