Example #1
0
    def test_kml_upload_form_with_with_valid_single_layer_data(self):
        """
        Test the import kml form. This test uses a sample kmz file with one placemark.
        This code based on stack overflow question at
        http://stackoverflow.com/questions/7304248/writing-tests-for-forms-in-django
        :return:
        """
        upload_file = open('san_francisco/fixtures/Occurrence.kmz', 'rb')
        post_dict = {}
        file_dict = {'kmlfileUpload': SimpleUploadedFile(upload_file.name, upload_file.read())}
        upload_file.close()
        form = UploadKMLForm(post_dict, file_dict)
        self.assertTrue(form.is_valid())

        # get current number of occurrence records in DB and verify count
        occurrence_starting_record_count = Occurrence.objects.count()

        # follow redirect to confirmation page
        response = self.client.post('/projects/san_francisco/upload/', file_dict, follow=True)

        # test redirect to confirmation page
        self.assertRedirects(response, '/projects/san_francisco/confirmation/')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'upload was successful!')  # test message in conf page

        # test that new occurrence was added to DB
        self.assertEqual(Occurrence.objects.count(), occurrence_starting_record_count+3)
Example #2
0
    def test_kml_upload_form_with_with_valid_single_layer_data(self):
        """
        Test the import kml form. This test uses a sample kmz file with one placemark.
        This code based on stack overflow question at
        http://stackoverflow.com/questions/7304248/writing-tests-for-forms-in-django
        :return:
        """
        upload_file = open('san_francisco/fixtures/Occurrence.kmz', 'rb')
        post_dict = {}
        file_dict = {
            'kmlfileUpload':
            SimpleUploadedFile(upload_file.name, upload_file.read())
        }
        upload_file.close()
        form = UploadKMLForm(post_dict, file_dict)
        self.assertTrue(form.is_valid())

        # get current number of occurrence records in DB and verify count
        occurrence_starting_record_count = Occurrence.objects.count()
        self.assertEqual(occurrence_starting_record_count, 20)

        # follow redirect to confirmation page
        response = self.client.post('/san_francisco/upload/',
                                    file_dict,
                                    follow=True)

        # test redirect to confirmation page
        self.assertRedirects(response, '/san_francisco/confirmation/')
        self.assertEqual(response.status_code, 200)
        self.assertContains(
            response, 'upload was successful!')  # test message in conf page

        # test that new occurrence was added to DB
        self.assertEqual(Occurrence.objects.count(),
                         occurrence_starting_record_count + 3)
Example #3
0
    def test_kml_upload_form_with_no_data(self):
        # get starting count of records in DB
        occurrence_starting_record_count = Occurrence.objects.count()

        # create an empty form
        post_dict = {}
        file_dict = {}
        form = UploadKMLForm(post_dict, file_dict)

        # test that form is not valid with empty data
        self.assertFalse(form.is_valid())

        # get the post response and test page reload and error message
        response = self.client.post(reverse('projects:san_francisco:san_francisco_upload_kml'),
                                    file_dict, follow=True)
        self.assertEqual(response.status_code, 200)  # test reload
        self.assertContains(response, 'Upload a')
        self.assertContains(response, 'This field is required')

        # test nothing is saved to DB
        self.assertEqual(Occurrence.objects.count(), occurrence_starting_record_count)
Example #4
0
    def test_kml_upload_form_with_no_data(self):
        # get starting count of records in DB
        occurrence_starting_record_count = Occurrence.objects.count()
        self.assertEqual(occurrence_starting_record_count, 20)

        # create an empty form
        post_dict = {}
        file_dict = {}
        form = UploadKMLForm(post_dict, file_dict)

        # test that form is not valid with empty data
        self.assertFalse(form.is_valid())

        # get the post response and test page reload and error message
        response = self.client.post(reverse('mlp:mlp_upload_kml'),
                                    file_dict,
                                    follow=True)
        self.assertEqual(response.status_code, 200)  # test reload
        self.assertContains(response, 'Upload a')
        self.assertContains(response, 'This field is required')

        # test nothing is saved to DB
        self.assertEqual(Occurrence.objects.count(),
                         occurrence_starting_record_count)