def test_rest_defaultkml_url(self): self.client.login(username='******', password='******') link = self.stand1.options.get_link('KML') url = link.reverse(self.stand1) response = self.client.get(url) errors = kml_errors(response.content) self.assertFalse(errors,"invalid KML %s" % str(errors))
def test_rest_defaultkml_url(self): self.client.login(username="******", password="******") link = self.stand1.options.get_link("KML") url = link.reverse(self.stand1) response = self.client.get(url) errors = kml_errors(response.content) self.assertFalse(errors, "invalid KML %s" % str(errors))
def test_nonauth_user_kml(self): """ Tests that non-authenticated user can't retrieve any MPAs """ url = reverse('kmlapp-user-kml', kwargs={'session_key': 0, 'input_username': self.user.username}) response = self.client.get(url) errors = kml_errors(response.content) self.assertEquals(response.status_code, 401)
def test_sharedby_kml(self): """ Tests that user can view the sharedby_kml (mpas shared by a given group) """ self.client.login(username=self.user2.username, password=self.password) url = reverse('kmlapp-sharedby-kml', kwargs={'session_key':self.client.session.session_key, 'input_shareuser': self.user.pk, 'input_sharegroup':self.group1.pk}) response = self.client.get(url) self.assertEquals(response.status_code, 200, response) errors = kml_errors(response.content) self.assertFalse(errors,"invalid KML %s" % str(errors))
def test_shared_kml(self): """ Tests that another user can view the shared_kml (with network links the the sharedby-kmls) """ self.client.login(username=self.user2.username, password=self.password) url = reverse('kmlapp-sharedlinks-kml', kwargs={'session_key':self.client.session.session_key, 'input_username':self.user2.username}) response = self.client.get(url) self.assertEquals(response.status_code, 200, response) errors = kml_errors(response.content) self.assertFalse(errors,"invalid KML %s" % str(errors))
def test_public_kml_unauth(self): """ Tests that ANY user can retrieve valid KML file for public shared mpas and arrays """ # As anonymous user url = reverse('kmlapp-publicshared-kml', kwargs={'session_key': '0'}) response = self.client.get(url) self.assertEquals(response.status_code, 200) errors = kml_errors(response.content) self.assertFalse(errors,"invalid KML %s" % str(errors))
def test_public_kml_auth(self): """ Tests that user can retrieve valid KML file for public shared mpas and arrays """ # As authenticated user self.client.login(username=self.user.username, password=self.password) url = reverse('kmlapp-publicshared-kml', kwargs={'session_key':self.client.session.session_key}) response = self.client.get(url) self.assertEquals(response.status_code, 200, response) errors = kml_errors(response.content) self.assertFalse(errors,"invalid KML %s" % str(errors))
def test_invalid_kml(self): """ Tests that invalid KML gets noticed """ self.client.login(username=self.user.username, password=self.password) url = reverse('kmlapp-user-kml', kwargs={'session_key': 0, 'input_username': self.user.username}) response = self.client.get(url) self.assertEquals(response.status_code, 200) bad = str(response.content).replace("<Document>","<foobar /><Document>") errors = kml_errors(bad) self.assertEquals(errors[0][1]['element'],u'foobar')
def test_user_kml_links(self): """ Tests that user can retrieve valid KML file with network links to arrays """ self.client.login(username=self.user.username, password=self.password) url = reverse('kmlapp-userlinks-kml', kwargs={'session_key': '0', 'input_username': self.user.username}) response = self.client.get(url) self.assertEquals(response.status_code, 200) errors = kml_errors(response.content) self.assertFalse(errors,"invalid KML %s" % str(errors)) url = reverse('kmlapp-userlinks-kml', kwargs={'session_key': self.client.session.session_key, 'input_username': self.user.username}) response = self.other_client.get(url) self.assertEquals(response.status_code, 200)
def test_user_kml(self): """ Tests that user can retrieve valid KML file of their MPAs """ self.client.login(username=self.user.username, password=self.password) url = reverse('kmlapp-user-kml', kwargs={'session_key': 0, 'input_username': self.user.username}) response = self.client.get(url) self.assertEquals(response.status_code, 200) errors = kml_errors(response.content) self.assertFalse(errors,"invalid KML %s" % str(errors)) # test for session key url url = reverse('kmlapp-user-kml', kwargs={'session_key': self.client.session.session_key, 'input_username': self.user.username}) response = self.other_client.get(url) self.assertEquals(response.status_code, 200)
def test_single_kml(self): """ Tests that single MPA can be represented as valid KML """ self.client.login(username=self.user.username, password=self.password) url = reverse('kmlapp-feature-kml', kwargs={'session_key': '0', 'input_uid': self.mpa1.uid}) response = self.client.get(url) self.assertEquals(response.status_code, 200) errors = kml_errors(response.content) self.assertFalse(errors,"invalid KML %s" % str(errors)) # test session_key in url method url = reverse('kmlapp-feature-kml', kwargs={'session_key': self.client.session.session_key, 'input_uid': self.mpa1.uid}) response = self.other_client.get(url) self.assertEquals(response.status_code, 200)