Esempio n. 1
0
    def test_organization_create_post(self):
        """Should create a new organization
        """
        admin_client = AdminClient()
        admin_client.login_as_admin()

        # Create new organization
        form_data = {
            'social_twitter': 'notreal',
            'social_facebook': 'notreal',
            'title': 'Test Organization Two',
            'description': 'Testing',
            'email': '*****@*****.**',
            'access': 'public',
            'date_joined': datetime.now(),
            'city': 'Cholula',
            'country': 'MEX',
            'keywords': 'test',
            'profile_type': 'org',
            'slug': 'Test-Organization-Two'
        }

        response = admin_client.post(reverse('organization_create'),
                                     data=form_data,
                                     follow=True)
        self.assertEqual(response.status_code, 200)

        # When the organization is created, a GroupProfile and Collection model pointing to it should be created
        group = GroupProfile.objects.all().first()
        collection = Collection.objects.all().first()
        self.assertEqual(collection.group, group)
        self.assertEqual(collection.name, group.title)
        self.assertEqual(collection.slug, group.slug)
        self.assertEqual(group.profile_type, 'org')
Esempio n. 2
0
    def setUp(self):
        self.username, self.password = self.create_user(
            'admin', 'admin', is_superuser=True)
        self.user = get_user_model().objects.filter(username='******')[0]

        self.username, self.password = self.create_user(
            'admin', 'admin', is_superuser=True)
        admin_client = AdminClient()
        admin_client.login_as_admin()
        response = admin_client.get(
            reverse('profile_detail', args=[self.username]))

        # Test for final status code = HTTP OK
        response = admin_client.get(
            reverse('profile_detail', args=[self.username]))
        self.assertTemplateUsed(response, 'people/profile_detail.html')

        # Should have all the tab names shown
        self.assertContains(response, 'Stories')
        self.assertContains(response, 'Layers')
        self.assertContains(response, 'Uploads')
        self.assertContains(response, 'Messages')
        self.assertContains(response, 'Activity Feed')
        self.assertContains(response, 'Journal Entries')
        self.assertContains(response, 'Favorites')
        self.assertContains(response, 'Icons')
        self.assertContains(response, 'Stories')
Esempio n. 3
0
 def test_access_with_admin_to_manager(self):
     c = AdminClient()
     c.login_as_admin()
     org = get_test_organization()
     r = c.get(reverse("organizations:manage", kwargs={'slug': org.slug}),
               follow=True)
     self.assertEqual(200, r.status_code)
Esempio n. 4
0
    def setUp(self):
        self.username, self.password = self.create_user('admin', 'admin', is_superuser=True)
        self.non_admin_username, self.non_admin_password = self.create_user('non_admin', 'non_admin')

        admin = AdminClient()
        admin.login_as_admin()

        form_data = {
            'social_twitter': 'notreal',
            'social_facebook': 'notreal',
            'title': 'Test Initiative',
            'description': 'Testing',
            'email': '*****@*****.**',
            'access': 'public',
            'date_joined': datetime.now(),
            'city': 'Victoria',
            'country': 'CAN',
            'keywords': 'test',
            'profile_type': 'org',
            'slug': 'Test-Initiative'
        }

        response = admin.post(reverse('initiative_create'), data=form_data, follow=True)
        self.assertEqual(response.status_code, 200)
        last_url, status_code = response.redirect_chain[-1]
        self.assertRedirects(response, '/initiatives/' + form_data['slug'], status_code=302, target_status_code=200)

        group = GroupProfile.objects.all().first()
        collection = Collection.objects.all().first()
        self.assertEqual(collection.group, group)
Esempio n. 5
0
    def setUp(self):
        self.username, self.password = self.create_user('admin',
                                                        'admin',
                                                        is_superuser=True)
        self.user = get_user_model().objects.filter(username='******')[0]

        self.username, self.password = self.create_user('admin',
                                                        'admin',
                                                        is_superuser=True)
        admin_client = AdminClient()
        admin_client.login_as_admin()
        response = admin_client.get(
            reverse('profile_detail', args=[self.username]))

        # Test for final status code = HTTP OK
        response = admin_client.get(
            reverse('profile_detail', args=[self.username]))
        self.assertTemplateUsed(response, 'people/profile_detail.html')

        # Should have all the tab names shown
        self.assertContains(response, 'Stories')
        self.assertContains(response, 'Layers')
        self.assertContains(response, 'Uploads')
        self.assertContains(response, 'Messages')
        self.assertContains(response, 'Activity Feed')
        self.assertContains(response, 'Journal Entries')
        self.assertContains(response, 'Favorites')
        self.assertContains(response, 'Icons')
        self.assertContains(response, 'Stories')
Esempio n. 6
0
    def test_organization_members_add(self):
        """Organization member add
        url(r'^organizations/(?P<slug>[^/]*)/members_add/$', organization_members_add, name='organization_members_add'),
        """
        admin = AdminClient()
        admin.login_as_admin()

        # Should reject GET requests
        response = admin.get(reverse('organization_members_add',
                                     args=['Test-Organization']),
                             follow=True)
        self.assertEqual(response.status_code, 405)

        # TODO: Put good data in here
        form_data = {}

        # Should accept POST requests
        response = admin.post(reverse('organization_members_add',
                                      args=['Test-Organization']),
                              follow=True,
                              data=form_data)
        self.assertEqual(response.status_code, 200)

        # Should end up in 'organization_members'
        last_url, status_code = response.redirect_chain[-1]
        self.assertRedirects(response,
                             reverse('organization_detail',
                                     args=['Test-Organization']),
                             status_code=302,
                             target_status_code=200)
Esempio n. 7
0
 def test_access_with_admin_to_manager(self):
     c = AdminClient()
     c.login_as_admin()
     org = get_test_organization()
     r = c.get(reverse("organizations:manage", kwargs={
               'slug': org.slug}), follow=True)
     self.assertEqual(200, r.status_code)
Esempio n. 8
0
 def test_admin_access(self):
     """Admin should get access
     """
     admin_client = AdminClient()
     admin_client.login_as_admin()
     response = admin_client.get(reverse('organization_create'))
     self.assertEqual(response.status_code, 200)
     self.assertHasGoogleAnalytics(response)
Esempio n. 9
0
    def test_layer(self):
        layer = Layer.objects.first()
        c = AdminClient()
        c.login_as_admin()
        response = c.get(reverse('layer_detail', args=[layer.typename]))
        self.assertEqual(response.status_code, 200)

        response = c.get(reverse('layer_metadata', args=[layer.typename]))
        self.assertEqual(response.status_code, 200)
Esempio n. 10
0
    def test_organization_create_get(self):
        """Should return an empty form.
        """
        admin_client = AdminClient()
        admin_client.login_as_admin()

        response = admin_client.get(reverse('organization_create'),
                                    follow=True)
        self.assertEqual(response.status_code, 200)
Esempio n. 11
0
    def test_initiatives(self):
        admin = AdminClient()
        admin.login_as_admin()
        response = admin.get(reverse('initiative_create'))
        self.assertEqual(response.status_code, 200)
        self.assertHasGoogleAnalytics(response)

        # Create new organization
        form_data = {
            'social_twitter': 'notreal',
            'social_facebook': 'notreal',
            'title': 'Test Initiative',
            'description': 'Testing',
            'email': '*****@*****.**',
            'access': 'public',
            'date_joined': datetime.now(),
            'city': 'Victoria',
            'country': 'CAN',
            'keywords': 'test',
            'profile_type': 'ini',
            'slug': 'Test-Initiative'
        }
        response = admin.post(reverse('initiative_create'), data=form_data)
        # Redirect when form is submitted, therefore 302
        self.assertEqual(response.status_code, 302)

        # When the organization is created, a GroupProfile and Collection model pointing to it should be created
        group = GroupProfile.objects.all().first()
        collection = Collection.objects.all().first()
        self.assertEqual(collection.group, group)

        # Test editing the organization
        form_data = {
            'title': 'Test Initiative',
            'description': 'Edit',
            'keywords': 'edit',
            'profile_type': 'ini',
            'access': 'public',
            'slug': 'Test-Initiative',
            'date_joined': datetime.now()
        }
        response = admin.post(reverse('initiative_edit', args=[group.slug]),
                              data=form_data)
        # Redirect when form is submitted, therefore 302
        self.assertEqual(response.status_code, 302)

        group = GroupProfile.objects.all().first()
        self.assertEqual(group.description, 'Edit')
        group_keywords = []
        for keyword in group.keywords.all():
            group_keywords.append(keyword.name)
        self.assertEqual(group_keywords, ['edit'])

        # Make sure the detail page can be viewed by a regular user
        c = Client()
        response = c.get(reverse('initiative_detail', args=[group.slug]))
        self.assertEqual(response.status_code, 200)
Esempio n. 12
0
    def test_layer(self):
        layer = Layer.objects.first()
        c = AdminClient()
        c.login_as_admin()
        response = c.get(reverse('layer_detail', args=[layer.typename]))
        self.assertEqual(response.status_code, 200)

        response = c.get(reverse('layer_metadata', args=[layer.typename]))
        self.assertEqual(response.status_code, 200)
Esempio n. 13
0
 def test_organization_members(self):
     """Organization members
     url(r'^organizations/members/(?P<slug>[^/]*)$', organization_members, name='organization_members'),
     """
     admin = AdminClient()
     admin.login_as_admin()
     response = admin.get(reverse('organization_members',
                                  args=['Test-Organization']),
                          follow=True)
     self.assertEqual(response.status_code, 200)
Esempio n. 14
0
    def test_manager_post_social_media_changes(self):
        # Create an organization without social media.
        org = get_test_organization()

        # Check the details page for links.
        response = self.client.get(org.get_absolute_url())
        self.assertEqual(200, response.status_code)
        self.assertContains(response, org.name)

        management_url = reverse(
            "organizations:manage", kwargs={'slug': org.slug})

        # Try to manage anonymously and get denied
        response = self.client.get(management_url, follow=True)
        self.assertEqual(200, response.status_code)
        self.assertContains(response, "Log in to an existing account")

        # Try to post anonymously and get denied
        response = self.client.post(
            management_url,
            {'facebook': 'unodostre'},
            follow=True
        )
        self.assertEqual(200, response.status_code)
        self.assertContains(response, "Log in to an existing account")

        # Create user without permissions
        non_admin_user = User.objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******'
        )
        non_admin_user.save()
        # Login as
        c = AdminClient()
        c.login_as_admin()

        # Should not get the management button
        response = c.get(org.get_absolute_url())
        self.assertNotContains(response, "MANAGE")

        # Try to manage as someone who is not and admin and get denied
        response = c.get(reverse("organizations:manage", kwargs={
                         'slug': org.slug}), follow=True)
        self.assertEqual(200, response.status_code)
        self.assertTemplateUsed("organiazation_detail.html")

        # Try to post changes as someone who is not admin and get denied
        response = c.post(management_url, {
            'facebook': 'onetwothree'
        }, follow=True)
        self.assertEqual(200, response.status_code)
        self.assertTemplateUsed("organiazation_detail.html")
Esempio n. 15
0
    def test_organization_form(self):
        admin = AdminClient()
        admin.login_as_admin()

        # Get an empty form
        response = admin.get(reverse('organization_create'))
        self.assertEqual(response.status_code, 200)

        soup = BeautifulSoup(response.content)

        # Should have 28 fields total
        self.assertEqual(len(soup.find_all('input')), 28)
Esempio n. 16
0
    def test_organization_edit(self):
        """Organization Edit

        """
        admin_client = AdminClient()
        admin_client.login_as_admin()

        group = GroupProfile.objects.all().first()
        collection = Collection.objects.all().first()
        self.assertEqual(collection.group, group)

        # Test editing the organization
        form_data = {
            'title': 'Test Organization',
            'description': 'Edit',
            'keywords': 'edit',
            'profile_type': 'org',
            'access': 'public',
            'slug': 'Test-Organization',
            'date_joined': datetime.now()
        }

        response = admin_client.post(reverse('organization_edit',
                                             args=[group.slug]),
                                     data=form_data,
                                     follow=True)
        self.assertEqual(response.status_code, 200)
        # Redirect when form is submitted, therefore 302
        last_url, status_code = response.redirect_chain[-1]
        self.assertRedirects(response,
                             '/organizations/' + form_data['slug'],
                             status_code=302,
                             target_status_code=200)

        group = GroupProfile.objects.all().first()
        self.assertEqual(group.description, 'Edit')

        group_keywords = []
        for keyword in group.keywords.all():
            group_keywords.append(keyword.name)

        self.assertEqual(group_keywords, ['edit'])

        # Make sure the detail page can be viewed by a regular user
        client = Client()
        response = client.get(reverse('organization_detail',
                                      args=[group.slug]))
        self.assertEqual(response.status_code, 200)

        response = client.get(
            reverse('organization_members', args=[group.slug]))
        self.assertEqual(response.status_code, 200)
Esempio n. 17
0
 def test_organization_create(self):
     """Organization create
     url(r'^organizations/create/$', organization_create, name='organization_create'),
     """
     admin_client = AdminClient()
     admin_client.login_as_admin()
     group = GroupProfile.objects.all().first()
     collection = Collection.objects.all().first()
     self.assertEqual(collection.group, group)
     manager = group.get_managers().all()
     # Should only have 1 manager
     self.assertEqual(len(manager), 1)
     self.assertEqual(group.profile_type, 'org')
Esempio n. 18
0
    def test_detail_page_forms(self):
        c = AdminClient()
        c.login_as_admin()
        layer = Layer.objects.first()
        response = c.get(reverse('layer_detail', args=[layer.typename]))
        self.assertEqual(response.status_code, 200)

        # keywords_form test
        old_keywords = layer.keywords.all()
        old_keywords_names = []
        for okeyword in old_keywords:
            old_keywords_names.append(okeyword.name)

        form_data = {'keywords': 'test, test2'}
        response = c.post(reverse('layer_detail', args=[layer.typename]), data=form_data)
        self.assertEqual(response.status_code, 200)
        # Make sure the layer's keywords are updated
        layer = Layer.objects.filter(id=layer.id)[0]
        new_keywords = layer.keywords.all()
        new_keywords_names = []
        for nkeyword in new_keywords:
            new_keywords_names.append(nkeyword.name)
        self.assertFalse(old_keywords_names == new_keywords_names)

        # metadata_form test
        old_metadata = {'title': layer.title, 'category': layer.category, 'language': layer.language,
        'distribution_url': layer.distribution_url, 'data_quality_statement': layer.data_quality_statement,
        'purpose': layer.purpose, 'is_published': layer.is_published}
        # distribution url doesn't seem to be modifiable
        form_data = {'title': 'New title', 'category': '1', 'language': 'fra', 'distribution_url': layer.distribution_url,
        'data_quality_statement': 'This is quality', 'purpose': 'To educate', 'is_published': 'on'}
        # The submitted data as it will appear in the model is slightly different
        submitted_data = {'title': unicode('New title'), 'category': TopicCategory.objects.first(), 'language': unicode('fra'),
        'distribution_url': unicode(layer.distribution_url), 'data_quality_statement': unicode('This is quality'),
        'purpose': unicode('To educate'), 'is_published': True}

        response = c.post(reverse('layer_detail', args=[layer.typename]), data=form_data)
        self.assertEqual(response.status_code, 200)
        layer = Layer.objects.filter(id=layer.id)[0]
        new_metadata = {'title': layer.title, 'category': layer.category, 'language': layer.language,
        'distribution_url': layer.distribution_url, 'data_quality_statement': layer.data_quality_statement,
        'purpose': layer.purpose, 'is_published': layer.is_published}

        self.assertFalse(new_metadata == old_metadata)
        self.assertEqual(submitted_data, new_metadata)

        # Make sure the keywords have been retained
        layer_keywords_names = []
        for lkeyword in layer.keywords.all():
            layer_keywords_names.append(lkeyword.name)
        self.assertEqual(layer_keywords_names, new_keywords_names)
Esempio n. 19
0
    def test_manager_post_social_media_changes(self):
        # Create an organization without social media.
        org = get_test_organization()

        # Check the details page for links.
        response = self.client.get(org.get_absolute_url())
        self.assertEqual(200, response.status_code)
        self.assertContains(response, org.title)

        management_url = reverse("organizations:manage",
                                 kwargs={'slug': org.slug})

        # Try to manage anonymously and get denied
        response = self.client.get(management_url, follow=True)
        self.assertEqual(200, response.status_code)
        self.assertContains(response, "Log in to an existing account")

        # Try to post anonymously and get denied
        response = self.client.post(management_url, {'facebook': 'unodostre'},
                                    follow=True)
        self.assertEqual(200, response.status_code)
        self.assertContains(response, "Log in to an existing account")

        # Create user without permissions
        non_admin_user = User.objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******')
        non_admin_user.save()
        # Login as
        c = AdminClient()
        c.login_as_admin()

        # Should not get the management button
        response = c.get(org.get_absolute_url())
        self.assertNotContains(response, "MANAGE")

        # Try to manage as someone who is not and admin and get denied
        response = c.get(reverse("organizations:manage",
                                 kwargs={'slug': org.slug}),
                         follow=True)
        self.assertEqual(200, response.status_code)
        self.assertTemplateUsed("organiazation_detail.html")

        # Try to post changes as someone who is not admin and get denied
        response = c.post(management_url, {'facebook': 'onetwothree'},
                          follow=True)
        self.assertEqual(200, response.status_code)
        self.assertTemplateUsed("organiazation_detail.html")
Esempio n. 20
0
    def test_social_page_renders(self):
        admin_client = AdminClient()
        admin_client.login_as_admin()
        response = admin_client.get(reverse('profile_detail', args=[self.username]))

        # Test for final status code = HTTP OK
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'people/profile_detail.html')

        # Should have all the tab names shown
        self.assertContains(response, 'Stories')
        self.assertContains(response, 'Layers')
        self.assertContains(response, 'Uploads')
        self.assertContains(response, 'Messages')
        self.assertContains(response, 'Activity Feed')
        self.assertContains(response, 'Journal Entries')
        self.assertContains(response, 'Favorites')
        self.assertContains(response, 'Icons')
        self.assertContains(response, 'Stories')
Esempio n. 21
0
    def setUp(self):
        self.username, self.password = self.create_user('admin',
                                                        'admin',
                                                        is_superuser=True)
        self.non_admin_username, self.non_admin_password = self.create_user(
            'non_admin', 'non_admin')

        admin_client = AdminClient()
        admin_client.login_as_admin()

        form_data = {
            'social_twitter': 'notreal',
            'social_facebook': 'notreal',
            'title': 'Test Organization',
            'description': 'Testing',
            'email': '*****@*****.**',
            'access': 'public',
            'date_joined': datetime.now(),
            'city': 'Victoria',
            'country': 'CAN',
            'keywords': 'test',
            'profile_type': 'org',
            'slug': 'Test-Organization'
        }

        response = admin_client.post(reverse('organization_create'),
                                     data=form_data,
                                     follow=True)
        # Test for final status code = HTTP OK
        self.assertEqual(response.status_code, 200)

        # Test for correct redirect
        last_url, status_code = response.redirect_chain[-1]
        self.assertRedirects(response,
                             '/organizations/' + form_data['slug'],
                             status_code=302,
                             target_status_code=200)

        # When the organization is created, a GroupProfile and Collection model pointing to it should be created
        group = GroupProfile.objects.all().first()
        collection = Collection.objects.all().first()
        self.assertEqual(collection.group, group)
Esempio n. 22
0
    def test_social_page_renders(self):
        admin_client = AdminClient()
        admin_client.login_as_admin()
        response = admin_client.get(
            reverse('profile_detail', args=[self.username]))

        # Test for final status code = HTTP OK
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'people/profile_detail.html')

        # Should have all the tab names shown
        self.assertContains(response, 'Stories')
        self.assertContains(response, 'Layers')
        self.assertContains(response, 'Uploads')
        self.assertContains(response, 'Messages')
        self.assertContains(response, 'Activity Feed')
        self.assertContains(response, 'Journal Entries')
        self.assertContains(response, 'Favorites')
        self.assertContains(response, 'Icons')
        self.assertContains(response, 'Stories')
Esempio n. 23
0
    def test_organization_member_remove(self):
        """Organization member remove
        url(r'^organizations/(?P<slug>[^/]*)/member_remove/(?P<username>.+)$', organization_member_remove, name='organization_member_remove'),
        """
        admin = AdminClient()
        admin.login_as_admin()

        # Should reject GET requests
        response = admin.get(reverse('organization_member_remove',
                                     args=['Test-Organization', 'admin']),
                             follow=True)
        self.assertEqual(response.status_code, 200)

        # TODO: Put good data in here
        form_data = {}

        # Should accept POST requests
        response = admin.post(reverse('organization_member_remove',
                                      args=['Test-Organization', 'admin']),
                              follow=True,
                              data=form_data)
        self.assertEqual(response.status_code, 403)
Esempio n. 24
0
class LayerTests(MapStoryTestMixin):

    def setUp(self):
        self.admin_client = AdminClient()

    def login_admin(self):
        """
        Convenience method for loging in as a superuser.
        """
        try:
            user = User.objects.get(username='******')
            self.assertIsNotNone(user)
        except User.DoesNotExist:
            create_admin_user("admin", "admin")

        self.admin_client.login_as_admin("admin", "admin")

    @skip("Fix this")
    def test_create_layer(self):

        filename = generate_testname(prefix='layer_', size=5)
        payload = {
            "featureType": {
                "attributes": {
                    "attribute": [
                        {"name": "geometry", "binding": "com.vividsolutions.jts.geom.Point", "minOccurs": 0,
                         "nillable": True},
                        {"name": "time", "binding": "org.geotools.data.postgis.BigDate", "nillable": True,
                         "minOccurs": 0}
                    ]
                },
                "nativeCRS": "EPSG:4326",
                "srs": "EPSG:4326",
                "store": {"name": "mapstory_geogig"},
                "namespace": {"name": "geonode"},
                "configureTime": True,
                "editable": True,
                "name": filename,
                "start_date": "time",
                "permissions": {
                    "users": {
                        "AnonymousUser": ["change_layer_data", "download_resourcebase", "view_resourcebase"]
                    },
                    "groups": {
                        "registered": ["change_layer_data", "download_resourcebase", "view_resourcebase"]
                    }
                },
                "storeCreateGeogig": True
            }
        }

        self.login_admin()
        response = self.admin_client.post(
            reverse('layer_create'),
            data=json.dumps(payload),
            content_type='application/json',
            HTTP_X_REQUESTED_WITH='XMLHttpRequest',
        )

        self.assertEqual(201, response.status_code)
        json_response = json.loads(response.content)
        self.assertTrue(u'layers' in json_response.keys())

        self.assertTrue(len(json_response[u'layers']) > 0)

    def test_layer_upload_needs_login(self):
        # Should not be authorized to upload things
        with open(test_layer_file_path) as fp:
            response = self.client.post('/uploads/new/json', {'name': 'file', 'attachment': fp}, follow=True)
            self.assertEquals(response.status_code, 200)
            self.assertTemplateUsed(response, 'account/login.html')

    def test_csv_layer_upload(self):
        self.login_admin()

        with open(test_layer_file_path) as fp:
            response = self.admin_client.post(
                '/uploads/new/json',
                {'name': 'file', 'attachment': fp},
                follow=True
            )
            self.assertEqual(response.status_code, 200)
            self.assertTemplateNotUsed(response, 'account/login.html')

    def test_layer_import_wizard_views(self):
        # Should have 0 Layers stored
        response = self.admin_client.get('/maps/new', follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTemplateNotUsed(response, 'account/login.html')
        self.assertEquals(0, len(Layer.objects.all()))

        self.login_admin()
        with open(test_layer_file_path) as fp:
            # ---------------
            # 1. Upload file
            # ---------------
            response = self.admin_client.post('/uploads/new/json', {'name': 'testlayer', 'file': fp}, follow=True)
            self.assertEquals(response.status_code, 200)

            # Should Respond with JSON
            response_json = json.loads(response.content)
            self.assertIsNotNone(response_json)

            # Should not have any errors
            self.assertFalse(u'errors' in response_json.keys())

            # State should be 'UPLOADED;
            self.assertTrue(u'state' in response_json.keys())
            self.assertEquals(u'UPLOADED', response_json[u'state'])

            # Should have an upload ID
            self.assertIsNotNone(response_json[u'id'])

            # --------------------------
            # 2. Get Upload detail info
            # --------------------------
            url = "/importer-api/data/%s" % (response_json[u'id'],)
            detail_response = self.admin_client.get(url, follow=True)
            self.assertEquals(200, detail_response.status_code)

            # Should respond with JSON
            detail_json = json.loads(detail_response.content)
            self.assertIsNotNone(detail_json)

            # Should have upload detail information
            self.assertTrue(u'name' in detail_json.keys())
            self.assertEquals(True, detail_json[u'complete'])
            self.assertIsNotNone(detail_json[u'date'])
            self.assertEquals('CSV', detail_json[u'file_type'])
            self.assertIsNotNone(detail_json[u'resource_uri'])
            self.assertIsNotNone(detail_json[u'name'])

            # Get the uploaded details
            upload_name = detail_json[u'name']

            # ----------------------
            # 3. POST configuration
            # ----------------------
            json_str = json.dumps({
                "always_geogig": True,
                "configureTime": True,
                "editable": True,
                "convert_to_date": ["e_date", "fdate"],
                "index": 0,
                "name": upload_name,
                "permissions": {
                    "users": {
                        "AnonymousUser": [
                            "change_layer_data",
                            "download_resourcebase",
                            "view_resourcebase"]
                    },
                    "groups": {
                        "registered": [
                            "change_layer_data",
                            "download_resourcebase",
                            "view_resourcebase"
                        ]
                    }
                },
                "start_date": "e_date",
                "end_date": "fdate",
                "geoserver_store": {
                    "type": "geogig"
                }
            })
            url = "/importer-api/data-layers/%s/configure/" % (response_json[u'id'],)
            config_response = self.admin_client.post(url, json_str, content_type="application/json")
            self.assertEquals(config_response.status_code, 200)

            # Should receive a JSON task
            json_task = json.loads(config_response.content)
            self.assertIsNotNone(json_task)
            self.assertTrue(u'task' in json_task.keys())
            taskid = json_task[u'task']
            self.assertIsNotNone(taskid)

            # -------------------
            # 4. Get data layers
            url = "/importer-api/data-layers/%s/" % (response_json[u'id'],)
            response = self.admin_client.get(url, follow=True)
            self.assertEquals(response.status_code, 200)
            self.assertTemplateNotUsed(response, 'account/login.html')

            # Should get JSON back
            json_response = json.loads(response.content)
            self.assertIsNotNone(json_response)

            retries = 0
            while retries < 5:
                time.sleep(2)

                # Try again
                retry_response = self.admin_client.get(url, follow=True)
                self.assertEquals(retry_response.status_code, 200)
                json_response = json.loads(retry_response.content)
                self.assertIsNotNone(json_response)

                if json_response[u'status'] == u'SUCCESS':
                    break
                else:
                    retries += 1
Esempio n. 25
0
class LayerTests(MapStoryTestMixin):
    def setUp(self):
        self.admin_client = AdminClient()

    def login_admin(self):
        """
        Convenience method for loging in as a superuser.
        """
        try:
            user = User.objects.get(username='******')
            self.assertIsNotNone(user)
        except User.DoesNotExist:
            create_admin_user("admin", "admin")

        self.admin_client.login_as_admin("admin", "admin")

    @skip("Fix this")
    def test_create_layer(self):

        filename = generate_testname(prefix='layer_', size=5)
        payload = {
            "featureType": {
                "attributes": {
                    "attribute": [{
                        "name": "geometry",
                        "binding": "com.vividsolutions.jts.geom.Point",
                        "minOccurs": 0,
                        "nillable": True
                    }, {
                        "name": "time",
                        "binding": "org.geotools.data.postgis.BigDate",
                        "nillable": True,
                        "minOccurs": 0
                    }]
                },
                "nativeCRS": "EPSG:4326",
                "srs": "EPSG:4326",
                "store": {
                    "name": "mapstory_geogig"
                },
                "namespace": {
                    "name": "geonode"
                },
                "configureTime": True,
                "editable": True,
                "name": filename,
                "start_date": "time",
                "permissions": {
                    "users": {
                        "AnonymousUser": [
                            "change_layer_data", "download_resourcebase",
                            "view_resourcebase"
                        ]
                    },
                    "groups": {
                        "registered": [
                            "change_layer_data", "download_resourcebase",
                            "view_resourcebase"
                        ]
                    }
                },
                "storeCreateGeogig": True
            }
        }

        self.login_admin()
        response = self.admin_client.post(
            reverse('layer_create'),
            data=json.dumps(payload),
            content_type='application/json',
            HTTP_X_REQUESTED_WITH='XMLHttpRequest',
        )

        self.assertEqual(201, response.status_code)
        json_response = json.loads(response.content)
        self.assertTrue(u'layers' in json_response.keys())

        self.assertTrue(len(json_response[u'layers']) > 0)

    def test_layer_upload_needs_login(self):
        # Should not be authorized to upload things
        with open(test_layer_file_path) as fp:
            response = self.client.post('/uploads/new/json', {
                'name': 'file',
                'attachment': fp
            },
                                        follow=True)
            self.assertEquals(response.status_code, 200)
            self.assertTemplateUsed(response, 'account/login.html')

    def test_csv_layer_upload(self):
        self.login_admin()

        with open(test_layer_file_path) as fp:
            response = self.admin_client.post('/uploads/new/json', {
                'name': 'file',
                'attachment': fp
            },
                                              follow=True)
            self.assertEqual(response.status_code, 200)
            self.assertTemplateNotUsed(response, 'account/login.html')

    def test_layer_import_wizard_views(self):
        # Should have 0 Layers stored
        response = self.admin_client.get('/maps/new', follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTemplateNotUsed(response, 'account/login.html')
        self.assertEquals(0, len(Layer.objects.all()))

        self.login_admin()
        with open(test_layer_file_path) as fp:
            # ---------------
            # 1. Upload file
            # ---------------
            response = self.admin_client.post('/uploads/new/json', {
                'name': 'testlayer',
                'file': fp
            },
                                              follow=True)
            self.assertEquals(response.status_code, 200)

            # Should Respond with JSON
            response_json = json.loads(response.content)
            self.assertIsNotNone(response_json)

            # Should not have any errors
            self.assertFalse(u'errors' in response_json.keys())

            # State should be 'UPLOADED;
            self.assertTrue(u'state' in response_json.keys())
            self.assertEquals(u'UPLOADED', response_json[u'state'])

            # Should have an upload ID
            self.assertIsNotNone(response_json[u'id'])

            # --------------------------
            # 2. Get Upload detail info
            # --------------------------
            url = "/importer-api/data/%s" % (response_json[u'id'], )
            detail_response = self.admin_client.get(url, follow=True)
            self.assertEquals(200, detail_response.status_code)

            # Should respond with JSON
            detail_json = json.loads(detail_response.content)
            self.assertIsNotNone(detail_json)

            # Should have upload detail information
            self.assertTrue(u'name' in detail_json.keys())
            self.assertEquals(True, detail_json[u'complete'])
            self.assertIsNotNone(detail_json[u'date'])
            self.assertEquals('CSV', detail_json[u'file_type'])
            self.assertIsNotNone(detail_json[u'resource_uri'])
            self.assertIsNotNone(detail_json[u'name'])

            # Get the uploaded details
            upload_name = detail_json[u'name']

            # ----------------------
            # 3. POST configuration
            # ----------------------
            json_str = json.dumps({
                "always_geogig": True,
                "configureTime": True,
                "editable": True,
                "convert_to_date": ["e_date", "fdate"],
                "index": 0,
                "name": upload_name,
                "permissions": {
                    "users": {
                        "AnonymousUser": [
                            "change_layer_data", "download_resourcebase",
                            "view_resourcebase"
                        ]
                    },
                    "groups": {
                        "registered": [
                            "change_layer_data", "download_resourcebase",
                            "view_resourcebase"
                        ]
                    }
                },
                "start_date": "e_date",
                "end_date": "fdate",
                "geoserver_store": {
                    "type": "geogig"
                }
            })
            url = "/importer-api/data-layers/%s/configure/" % (
                response_json[u'id'], )
            config_response = self.admin_client.post(
                url, json_str, content_type="application/json")
            self.assertEquals(config_response.status_code, 200)

            # Should receive a JSON task
            json_task = json.loads(config_response.content)
            self.assertIsNotNone(json_task)
            self.assertTrue(u'task' in json_task.keys())
            taskid = json_task[u'task']
            self.assertIsNotNone(taskid)

            # -------------------
            # 4. Get data layers
            url = "/importer-api/data-layers/%s/" % (response_json[u'id'], )
            response = self.admin_client.get(url, follow=True)
            self.assertEquals(response.status_code, 200)
            self.assertTemplateNotUsed(response, 'account/login.html')

            # Should get JSON back
            json_response = json.loads(response.content)
            self.assertIsNotNone(json_response)

            retries = 0
            while retries < 5:
                time.sleep(2)

                # Try again
                retry_response = self.admin_client.get(url, follow=True)
                self.assertEquals(retry_response.status_code, 200)
                json_response = json.loads(retry_response.content)
                self.assertIsNotNone(json_response)

                if json_response[u'status'] == u'SUCCESS':
                    break
                else:
                    retries += 1
Esempio n. 26
0
    def test_detail_page_forms(self):
        c = AdminClient()
        c.login_as_admin()
        layer = Layer.objects.first()
        response = c.get(reverse('layer_detail', args=[layer.typename]))
        self.assertEqual(response.status_code, 200)

        # keywords_form test
        old_keywords = layer.keywords.all()
        old_keywords_names = []
        for okeyword in old_keywords:
            old_keywords_names.append(okeyword.name)

        form_data = {'keywords': 'test, test2'}
        response = c.post(reverse('layer_detail', args=[layer.typename]),
                          data=form_data)
        self.assertEqual(response.status_code, 200)
        # Make sure the layer's keywords are updated
        layer = Layer.objects.filter(id=layer.id)[0]
        new_keywords = layer.keywords.all()
        new_keywords_names = []
        for nkeyword in new_keywords:
            new_keywords_names.append(nkeyword.name)
        self.assertFalse(old_keywords_names == new_keywords_names)

        # metadata_form test
        old_metadata = {
            'title': layer.title,
            'category': layer.category,
            'language': layer.language,
            'distribution_url': layer.distribution_url,
            'data_quality_statement': layer.data_quality_statement,
            'purpose': layer.purpose,
            'is_published': layer.is_published
        }
        # distribution url doesn't seem to be modifiable
        form_data = {
            'title': 'New title',
            'category': '1',
            'language': 'fra',
            'distribution_url': layer.distribution_url,
            'data_quality_statement': 'This is quality',
            'purpose': 'To educate',
            'is_published': 'on'
        }
        # The submitted data as it will appear in the model is slightly different
        submitted_data = {
            'title': unicode('New title'),
            'category': TopicCategory.objects.first(),
            'language': unicode('fra'),
            'distribution_url': unicode(layer.distribution_url),
            'data_quality_statement': unicode('This is quality'),
            'purpose': unicode('To educate'),
            'is_published': True
        }

        response = c.post(reverse('layer_detail', args=[layer.typename]),
                          data=form_data)
        self.assertEqual(response.status_code, 200)
        layer = Layer.objects.filter(id=layer.id)[0]
        new_metadata = {
            'title': layer.title,
            'category': layer.category,
            'language': layer.language,
            'distribution_url': layer.distribution_url,
            'data_quality_statement': layer.data_quality_statement,
            'purpose': layer.purpose,
            'is_published': layer.is_published
        }

        self.assertFalse(new_metadata == old_metadata)
        self.assertEqual(submitted_data, new_metadata)

        # Make sure the keywords have been retained
        layer_keywords_names = []
        for lkeyword in layer.keywords.all():
            layer_keywords_names.append(lkeyword.name)
        self.assertEqual(layer_keywords_names, new_keywords_names)
Esempio n. 27
0
class MapStoryOrganizationTests(MapStoryTestMixin):
    def setUp(self):
        self.username, self.password = self.create_user('admin',
                                                        'admin',
                                                        is_superuser=True)
        self.non_admin_username, self.non_admin_password = self.create_user(
            'non_admin', 'non_admin')

        self.admin_client = AdminClient()
        self.admin_client.login_as_admin()

        self.form_data = {
            'social_twitter': 'notreal',
            'social_facebook': 'notreal',
            'title': 'Test Organization',
            'description': 'Testing',
            'email': '*****@*****.**',
            'access': 'public',
            'date_joined': datetime.now(),
            'city': 'Victoria',
            'country': 'CAN',
            'keywords': 'test',
            'profile_type': 'org',
            'slug': 'Test-Organization'
        }

        response = self.admin_client.post(reverse('organization_create'),
                                          data=self.form_data,
                                          follow=True)
        # Test for final status code = HTTP OK
        self.assertEqual(response.status_code, 200)

        # Test for correct redirect
        last_url, status_code = response.redirect_chain[-1]
        self.assertRedirects(response,
                             '/organizations/' + self.form_data['slug'],
                             status_code=302,
                             target_status_code=200)

        # When the organization is created, a GroupProfile and Collection model pointing to it should be created
        group = GroupProfile.objects.all().first()
        collection = Collection.objects.all().first()
        self.assertEqual(collection.group, group)

    def test_organization_create(self):
        # When the organization is created, a GroupProfile and Collection model pointing to it should be created
        group = GroupProfile.objects.all().first()
        collection = Collection.objects.all().first()
        self.assertEqual(collection.group, group)
        manager = group.get_managers().all()
        # Should only have 1 manager
        self.assertEqual(len(manager), 1)
        self.assertEqual(group.profile_type, 'org')

    def test_organization_create_get(self):
        """Should return an empty form.
        """
        response = self.admin_client.get(reverse('organization_create'),
                                         follow=True)
        self.assertEqual(response.status_code, 200)

    def test_organization_create_post(self):
        """Should create a new organization
        """
        admin_client = AdminClient()
        admin_client.login_as_admin()

        # Create new organization
        form_data = {
            'social_twitter': 'notreal',
            'social_facebook': 'notreal',
            'title': 'Test Organization Two',
            'description': 'Testing',
            'email': '*****@*****.**',
            'access': 'public',
            'date_joined': datetime.now(),
            'city': 'Cholula',
            'country': 'MEX',
            'keywords': 'test',
            'profile_type': 'org',
            'slug': 'Test-Organization-Two'
        }

        response = admin_client.post(reverse('organization_create'),
                                     data=form_data,
                                     follow=True)
        self.assertEqual(response.status_code, 200)

        # When the organization is created, a GroupProfile and Collection model pointing to it should be created
        group = GroupProfile.objects.all().first()
        collection = Collection.objects.all().first()
        self.assertEqual(collection.group, group)
        self.assertEqual(collection.name, group.title)
        self.assertEqual(collection.slug, group.slug)
        self.assertEqual(group.profile_type, 'org')
Esempio n. 28
0
    def setUp(self):
        self.username, self.password = self.create_user('admin', 'admin', is_superuser=True)
        self.non_admin_username, self.non_admin_password = self.create_user('non_admin', 'non_admin')

        admin_client = AdminClient()
        admin_client.login_as_admin()