def test_project_users__private_project(self):
        import transaction
        from osmtm.models import Project, DBSession
        project_id = self.create_project()
        project = DBSession.query(Project).get(project_id)
        project.name = u'private_project'
        project.private = True
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        # access forbidden if not allowed user or project_manager
        res = self.testapp.get('/project/%d/users' % project_id,
                               status=403, xhr=True)

        headers = self.login_as_project_manager()
        res = self.testapp.get('/project/%d/users' % project_id,
                               headers=headers,
                               status=200, xhr=True)
        self.assertEqual(len(res.json), 0)

        # add a user to allowed_users
        self.testapp.put('/project/%d/user/user1' % project_id,
                         headers=headers, status=200)
        res = self.testapp.get('/project/%d/users' % project_id,
                               headers=headers,
                               status=200, xhr=True)
        self.assertEqual(len(res.json), 1)
Example #2
0
    def test_task_random__bordering_busy_tasks(self):
        import geoalchemy2
        import shapely
        import transaction
        from osmtm.models import Area, Project, DBSession

        shape = shapely.geometry.Polygon(
            [(7.23, 41.25), (7.23, 41.12), (7.41, 41.20)])
        geometry = geoalchemy2.shape.from_shape(shape, 4326)
        area = Area(geometry)
        project = Project(u'test project')
        project.area = area
        project.auto_fill(12)

        DBSession.add(project)
        DBSession.flush()
        project_id = project.id

        task = project.tasks[0]
        task.locked = True

        transaction.commit()

        headers = self.login_as_user1()
        res = self.testapp.get('/project/%d/random' % project_id, status=200,
                               headers=headers,
                               xhr=True)
        self.assertTrue(res.json['success'])
    def test_project_task_users(self):
        import transaction
        from osmtm.models import Task, TaskState, TaskLock, User, DBSession
        from . import USER1_ID, USER2_ID

        project_id = self.create_project()

        ''' No contributions, users sorted alphabetically '''
        res = self.testapp.get('/project/%d/task/2/users' % project_id,
                               status=200, xhr=True)
        self.assertEqual(res.json[0], u'admin_user')

        task_id = 2
        task = DBSession.query(Task).get((project_id, task_id))

        user1 = DBSession.query(User).get(USER1_ID)
        task.states.append(TaskState(state=TaskState.state_done, user=user1))

        user2 = DBSession.query(User).get(USER2_ID)
        task.locks.append(TaskLock(lock=True, user=user2))

        DBSession.add(task)
        transaction.commit()

        ''' Contributors and then lockers should appear first '''
        res = self.testapp.get('/project/%d/task/2/users' % project_id,
                               status=200, xhr=True)
        self.assertEqual(res.json[0], u'user1')
        self.assertEqual(res.json[1], u'user2')
    def test_home__my_projects(self):
        import transaction
        from osmtm.models import Project, DBSession
        project_id = self.create_project()

        project = DBSession.query(Project).get(project_id)
        name = "project_not_worked_on_by_user"
        project.name = u"" + name
        project.status = Project.status_published
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        headers = self.login_as_user1()
        res = self.testapp.get('/', status=200, headers=headers)
        self.assertTrue(name in res.body)

        res = self.testapp.get('/',
                               status=200,
                               headers=headers,
                               params={'my_projects': 'on'})
        self.assertFalse(name in res.body)

        self.testapp.get('/project/%d/task/1/lock' % project_id,
                         status=200,
                         headers=headers,
                         xhr=True)

        res = self.testapp.get('/',
                               status=200,
                               headers=headers,
                               params={'my': 'on'})
        self.assertTrue(name in res.body)
    def test_home__my_projects(self):
        import transaction
        from osmtm.models import Project, DBSession
        project_id = self.create_project()

        project = DBSession.query(Project).get(project_id)
        name = "project_not_worked_on_by_user"
        project.name = u"" + name
        project.status = Project.status_published
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        headers = self.login_as_user1()
        res = self.testapp.get('/', status=200, headers=headers)
        self.assertTrue(name in res.body)

        res = self.testapp.get('/', status=200, headers=headers,
                               params={
                                   'my_projects': 'on'
                               })
        self.assertFalse(name in res.body)

        self.testapp.get('/project/%d/task/1/lock' % project_id, status=200,
                         headers=headers,
                         xhr=True)

        res = self.testapp.get('/', status=200, headers=headers,
                               params={
                                   'my': 'on'
                               })
        self.assertTrue(name in res.body)
    def test_project_users__private_project(self):
        import transaction
        from osmtm.models import Project, DBSession
        project_id = self.create_project()
        project = DBSession.query(Project).get(project_id)
        project.name = u'private_project'
        project.private = True
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        # access forbidden if not allowed user or project_manager
        res = self.testapp.get('/project/%d/users' % project_id,
                               status=403,
                               xhr=True)

        headers = self.login_as_project_manager()
        res = self.testapp.get('/project/%d/users' % project_id,
                               headers=headers,
                               status=200,
                               xhr=True)
        self.assertEqual(len(res.json), 0)

        # add a user to allowed_users
        self.testapp.put('/project/%d/user/user1' % project_id,
                         headers=headers,
                         status=200)
        res = self.testapp.get('/project/%d/users' % project_id,
                               headers=headers,
                               status=200,
                               xhr=True)
        self.assertEqual(len(res.json), 1)
Example #7
0
    def test_project_task_users(self):
        import transaction
        from osmtm.models import Task, TaskState, TaskLock, User, DBSession
        from . import USER1_ID, USER2_ID

        project_id = self.create_project()
        ''' No contributions, users sorted alphabetically '''
        res = self.testapp.get('/project/%d/task/2/users' % project_id,
                               status=200,
                               xhr=True)
        self.assertEqual(res.json[0], u'admin_user')

        task_id = 2
        task = DBSession.query(Task).get((project_id, task_id))

        user1 = DBSession.query(User).get(USER1_ID)
        task.states.append(TaskState(state=TaskState.state_done, user=user1))

        user2 = DBSession.query(User).get(USER2_ID)
        task.locks.append(TaskLock(lock=True, user=user2))

        DBSession.add(task)
        transaction.commit()
        ''' Contributors and then lockers should appear first '''
        res = self.testapp.get('/project/%d/task/2/users' % project_id,
                               status=200,
                               xhr=True)
        self.assertEqual(res.json[0], u'user1')
        self.assertEqual(res.json[1], u'user2')
    def test_task_random__bordering_busy_tasks(self):
        import geoalchemy2
        import shapely
        import transaction
        from osmtm.models import Area, Project, DBSession

        shape = shapely.geometry.Polygon(
            [(7.23, 41.25), (7.23, 41.12), (7.41, 41.20)])
        geometry = geoalchemy2.shape.from_shape(shape, 4326)
        area = Area(geometry)
        project = Project(u'test project')
        project.area = area
        project.auto_fill(12)

        DBSession.add(project)
        DBSession.flush()
        project_id = project.id

        task = project.tasks[0]
        task.locked = True

        transaction.commit()

        headers = self.login_as_user1()
        res = self.testapp.get('/project/%d/random' % project_id, status=200,
                               headers=headers,
                               xhr=True)
        self.assertTrue(res.json['success'])
    def test_project_edit__submitted_priority_areas(self):
        headers = self.login_as_admin()
        project_id = self.create_project()
        self.testapp.post(
            '/project/%d/edit' % project_id,
            headers=headers,
            params={
                'form.submitted':
                True,
                'priority':
                2,
                'status':
                2,
                'priority_areas':
                '{"type":"FeatureCollection","features":[{"geometry":{"type":"Polygon","coordinates":[[[85.31424522399902,27.70260377553105],[85.31424522399902,27.70419959861825],[85.31639099121094,27.70419959861825],[85.31639099121094,27.70260377553105],[85.31424522399902,27.70260377553105]]]},"type":"Feature","id":null,"properties":{}}]}'  # noqa
            },
            status=302)

        from osmtm.models import Project, DBSession
        project = DBSession.query(Project).get(project_id)
        self.assertEqual(len(project.priority_areas), 1)

        self.testapp.post(
            '/project/%d/edit' % project_id,
            headers=headers,
            params={
                'form.submitted':
                True,
                'priority':
                2,
                'status':
                2,
                'priority_areas':
                '{"type":"FeatureCollection","features":[{"geometry":{"type":"Polygon","coordinates":[[[85.31,27.702],[85.31,27.7],[85.31,27.704],[85.31,27.702],[85.31,27.702]]]},"type":"Feature","id":null,"properties":{}}, {"geometry":{"type":"Polygon","coordinates":[[[85.31,27.702],[85.31,27.7],[85.31,27.704],[85.31,27.702],[85.31,27.702]]]},"type":"Feature","id":null,"properties":{}}]}'  # noqa
            },
            status=302)

        from osmtm.models import Project, DBSession
        project = DBSession.query(Project).get(project_id)
        self.assertEqual(len(project.priority_areas), 2)

        self.testapp.post(
            '/project/%d/edit' % project_id,
            headers=headers,
            params={
                'form.submitted':
                True,
                'priority':
                2,
                'status':
                2,
                'priority_areas':
                '{"type":"FeatureCollection","features":[{"geometry":{"type":"Polygon","coordinates":[[[85.3,27.702],[85.31,27.7],[85.31,27.704],[85.31,27.702],[85.3,27.702]]]},"type":"Feature","id":null,"properties":{}}, {"geometry":{"type":"Polygon","coordinates":[[[85.31,27.702],[85.31,27.7],[85.31,27.704],[85.31,27.702],[85.31,27.702]]]},"type":"Feature","id":null,"properties":{}}]}'  # noqa
            },
            status=302)

        from osmtm.models import Project, DBSession
        project = DBSession.query(Project).get(project_id)
        self.assertEqual(len(project.priority_areas), 2)
Example #10
0
    def tearDown(self):
        del self.testapp
        from osmtm.models import DBSession
        DBSession.bind.dispose()  # dispose engine
        DBSession.remove()

        # forget any remembered authentication
        self.__forget()
Example #11
0
    def tearDown(self):
        del self.testapp
        from osmtm.models import DBSession
        DBSession.bind.dispose()  # dispose engine
        DBSession.remove()

        # forget any remembered authentication
        self.__forget()
    def test_project_preset(self):
        import transaction
        from osmtm.models import Project, DBSession
        project_id = self.create_project()

        project = DBSession.query(Project).get(project_id)
        project.josm_preset = u'blah'
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        res = self.testapp.get('/project/%d/preset' % project_id, status=200)
        self.assertTrue('blah' in res)
    def test_project_preset(self):
        import transaction
        from osmtm.models import Project, DBSession
        project_id = self.create_project()

        project = DBSession.query(Project).get(project_id)
        project.josm_preset = u'blah'
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        res = self.testapp.get('/project/%d/preset' % project_id, status=200)
        self.assertTrue('blah' in res)
    def test_task_random__bordering_busy_tasks(self):
        import geoalchemy2
        import shapely
        import transaction
        from osmtm.models import Task, TaskLock, Area, Project, User, DBSession

        shape = shapely.geometry.Polygon([(7.23, 41.25), (7.23, 41.12),
                                          (7.41, 41.20)])
        geometry = geoalchemy2.shape.from_shape(shape, 4326)
        area = Area(geometry)
        project = Project(u'test project')
        project.area = area
        project.auto_fill(12)

        DBSession.add(project)
        DBSession.flush()
        project_id = project.id

        user2 = DBSession.query(User).filter(User.id == self.user2_id).one()
        task = DBSession.query(Task).filter(Task.project_id == project_id) \
            .first()
        task.locks.append(TaskLock(user=user2, lock=True))
        DBSession.add(task)

        transaction.commit()

        headers = self.login_as_user1()
        res = self.testapp.get('/project/%d/random' % project_id,
                               status=200,
                               headers=headers,
                               xhr=True)
        self.assertTrue(res.json['success'])
Example #15
0
    def test_task_random__bordering_busy_tasks(self):
        import geoalchemy2
        import shapely
        import transaction
        from osmtm.models import Task, TaskLock, Area, Project, User, DBSession

        shape = shapely.geometry.Polygon(
            [(7.23, 41.25), (7.23, 41.12), (7.41, 41.20)])
        geometry = geoalchemy2.shape.from_shape(shape, 4326)
        area = Area(geometry)
        project = Project(u'test project')
        project.area = area
        project.auto_fill(12)

        DBSession.add(project)
        DBSession.flush()
        project_id = project.id

        user2 = DBSession.query(User).filter(User.id == self.user2_id).one()
        task = DBSession.query(Task).filter(Task.project_id == project_id) \
            .first()
        task.locks.append(TaskLock(user=user2, lock=True))
        DBSession.add(task)

        transaction.commit()

        headers = self.login_as_user1()
        res = self.testapp.get('/project/%d/random' % project_id, status=200,
                               headers=headers,
                               xhr=True)
        self.assertTrue(res.json['success'])
    def test_license_delete(self):
        import transaction
        from osmtm.models import DBSession, License
        license = License()
        DBSession.add(license)
        DBSession.flush()
        license_id = license.id
        transaction.commit()

        headers = self.login_as_admin()
        self.testapp.get('/license/%d/delete' % license_id,
                         headers=headers, status=302)

        self.assertEqual(DBSession.query(License).count(), 1)
Example #17
0
    def test_license_delete(self):
        import transaction
        from osmtm.models import DBSession, License
        license = License()
        DBSession.add(license)
        DBSession.flush()
        license_id = license.id
        transaction.commit()

        headers = self.login_as_admin()
        self.testapp.get('/license/%d/delete' % license_id,
                         headers=headers,
                         status=302)

        self.assertEqual(DBSession.query(License).count(), 1)
    def test_project__draft_not_allowed(self):
        import transaction
        from osmtm.models import Project, DBSession
        project_id = self.create_project()

        project = DBSession.query(Project).get(project_id)
        project.status = Project.status_draft
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        headers_user1 = self.login_as_user1()
        self.testapp.get('/project/%d' % project_id,
                         status=403,
                         headers=headers_user1)
    def test_project__draft_not_allowed(self):
        import transaction
        from osmtm.models import Project, DBSession
        project_id = self.create_project()

        project = DBSession.query(Project).get(project_id)
        project.status = Project.status_draft
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        headers_user1 = self.login_as_user1()
        self.testapp.get('/project/%d' % project_id,
                         status=403,
                         headers=headers_user1)
    def test_label_delete(self):
        import transaction
        from osmtm.models import DBSession, Label
        label = Label()
        label.name = 'some name'
        DBSession.add(label)
        DBSession.flush()
        label_id = label.id
        transaction.commit()

        headers = self.login_as_admin()
        self.testapp.get('/label/%d/delete' % label_id,
                         headers=headers, status=302)

        self.assertEqual(DBSession.query(Label).count(), 2)
    def test_task_invalidation__msg(self):
        from osmtm.models import Message, DBSession

        user1_before_msgs = DBSession.query(Message) \
            .filter(Message.to_user_id == self.user1_id).all()

        user2_before_msgs = DBSession.query(Message) \
            .filter(Message.to_user_id == self.user2_id).all()

        headers = self.login_as_user1()
        self.testapp.get('/project/1/task/5/lock',
                         headers=headers,
                         xhr=True)
        self.testapp.get('/project/1/task/5/done', status=200,
                         headers=headers,
                         xhr=True)

        headers = self.login_as_user2()
        self.testapp.get('/project/1/task/5/lock',
                         headers=headers,
                         xhr=True)
        self.testapp.get('/project/1/task/5/validate', status=200,
                         params={
                             'comment': 'a comment',
                             'validate': True
                         },
                         headers=headers,
                         xhr=True)

        headers = self.login_as_project_manager()
        self.testapp.get('/project/1/task/5/lock',
                         headers=headers,
                         xhr=True)
        self.testapp.get('/project/1/task/5/validate', status=200,
                         params={
                             'comment': 'a comment',
                             'invalidate': True
                         },
                         headers=headers,
                         xhr=True)

        user1_after_msgs = DBSession.query(Message) \
            .filter(Message.to_user_id == self.user1_id).all()
        user2_after_msgs = DBSession.query(Message) \
            .filter(Message.to_user_id == self.user2_id).all()

        self.assertEqual(len(user1_after_msgs), (len(user1_before_msgs) + 1))
        self.assertEqual(len(user2_after_msgs), (len(user2_before_msgs) + 1))
Example #22
0
    def test_user__username_change(self):
        httpretty.enable()

        from osmtm.models import User, DBSession
        import transaction

        userid = 11
        username = u'new_user'
        user = User(userid, username)
        DBSession.add(user)
        DBSession.flush()
        transaction.commit()

        new_username = username + '_changed'
        httpretty.register_uri(
            httpretty.GET,
            "http://www.openstreetmap.org/api/0.6/user/%s" % userid,
            body='<?xml version="1.0" encoding="UTF-8"?>' +
            '<osm> <user display_name="%s"></user></osm>' % new_username,
            content_type='application/xml; charset=utf-8')

        self.testapp.get('/user/%s' % username, status=302)

        user = DBSession.query(User).get(userid)
        self.assertEqual(user.username, new_username)

        DBSession.delete(user)
        transaction.commit()
Example #23
0
    def test_user__username_change(self):
        httpretty.enable()

        from osmtm.models import User, DBSession
        import transaction

        userid = 11
        username = u'new_user'
        user = User(userid, username)
        DBSession.add(user)
        DBSession.flush()
        transaction.commit()

        new_username = username + '_changed'
        httpretty.register_uri(
            httpretty.GET,
            "http://www.openstreetmap.org/api/0.6/user/%s" % userid,
            body='<?xml version="1.0" encoding="UTF-8"?>' +
                 '<osm> <user display_name="%s"></user></osm>' % new_username,
            content_type='application/xml; charset=utf-8')

        self.testapp.get('/user/%s' % username, status=302)

        user = DBSession.query(User).get(userid)
        self.assertEqual(user.username, new_username)

        DBSession.delete(user)
        transaction.commit()
Example #24
0
    def test_project_user_add(self):
        from osmtm.models import Project, DBSession
        project_id = self.create_project()

        headers = self.login_as_admin()
        self.testapp.put('/project/%d/user/user1' % project_id,
                         headers=headers, status=200)
        project = DBSession.query(Project).get(project_id)
        self.assertEqual(len(project.allowed_users), 1)
    def test_project_user_add(self):
        from osmtm.models import Project, DBSession
        project_id = self.create_project()

        headers = self.login_as_admin()
        self.testapp.put('/project/%d/user/user1' % project_id,
                         headers=headers, status=200)
        project = DBSession.query(Project).get(project_id)
        self.assertEqual(len(project.allowed_users), 1)
    def test_project_edit__submitted_priority_areas(self):
        headers = self.login_as_admin()
        project_id = self.create_project()
        self.testapp.post('/project/%d/edit' % project_id,
                          headers=headers,
                          params={
                              'form.submitted': True,
                              'priority': 2,
                              'status': 2,
                              'priority_areas': '{"type":"FeatureCollection","features":[{"geometry":{"type":"Polygon","coordinates":[[[85.31424522399902,27.70260377553105],[85.31424522399902,27.70419959861825],[85.31639099121094,27.70419959861825],[85.31639099121094,27.70260377553105],[85.31424522399902,27.70260377553105]]]},"type":"Feature","id":null,"properties":{}}]}'  # noqa
                          },
                          status=302)

        from osmtm.models import Project, DBSession
        project = DBSession.query(Project).get(project_id)
        self.assertEqual(len(project.priority_areas), 1)

        self.testapp.post('/project/%d/edit' % project_id,
                          headers=headers,
                          params={
                              'form.submitted': True,
                              'priority': 2,
                              'status': 2,
                              'priority_areas': '{"type":"FeatureCollection","features":[{"geometry":{"type":"Polygon","coordinates":[[[85.31,27.702],[85.31,27.7],[85.31,27.704],[85.31,27.702],[85.31,27.702]]]},"type":"Feature","id":null,"properties":{}}, {"geometry":{"type":"Polygon","coordinates":[[[85.31,27.702],[85.31,27.7],[85.31,27.704],[85.31,27.702],[85.31,27.702]]]},"type":"Feature","id":null,"properties":{}}]}'  # noqa
                          },
                          status=302)

        from osmtm.models import Project, DBSession
        project = DBSession.query(Project).get(project_id)
        self.assertEqual(len(project.priority_areas), 2)

        self.testapp.post('/project/%d/edit' % project_id,
                          headers=headers,
                          params={
                              'form.submitted': True,
                              'priority': 2,
                              'status': 2,
                              'priority_areas': '{"type":"FeatureCollection","features":[{"geometry":{"type":"Polygon","coordinates":[[[85.3,27.702],[85.31,27.7],[85.31,27.704],[85.31,27.702],[85.3,27.702]]]},"type":"Feature","id":null,"properties":{}}, {"geometry":{"type":"Polygon","coordinates":[[[85.31,27.702],[85.31,27.7],[85.31,27.704],[85.31,27.702],[85.31,27.702]]]},"type":"Feature","id":null,"properties":{}}]}'  # noqa
                          },
                          status=302)

        from osmtm.models import Project, DBSession
        project = DBSession.query(Project).get(project_id)
        self.assertEqual(len(project.priority_areas), 2)
    def test_task_difficulty(self):
        from osmtm.models import Task, DBSession
        headers = self.login_as_project_manager()
        self.testapp.put('/project/1/task/1/difficulty/3',
                         headers=headers,
                         status=200,
                         xhr=True)

        task = DBSession.query(Task).get((1, 1))
        self.assertEqual(task.difficulty, task.difficulty_hard)
Example #28
0
    def test_license__accept_or_reject(self):
        from osmtm.models import DBSession, User, License
        from . import USER1_ID
        headers = self.login_as_user1()
        self.testapp.post('/license/%d' % 1,
                          headers=headers,
                          params={'accepted_terms': 'I AGREE'},
                          status=302)

        user = DBSession.query(User).get(USER1_ID)
        license = DBSession.query(License).get(1)
        self.assertTrue(license in user.accepted_licenses)

        self.testapp.post('/license/1',
                          headers=headers,
                          params={'accepted_terms': 'blah'},
                          status=302)
        user = DBSession.query(User).get(USER1_ID)
        self.assertFalse(license in user.accepted_licenses)
    def test_project_priority_areas(self):
        import transaction
        project_id = self.create_project()

        from osmtm.models import Project, PriorityArea, DBSession
        project = DBSession.query(Project).get(project_id)

        import shapely
        import geoalchemy2
        shape = shapely.geometry.Polygon([(7.23, 41.25), (7.23, 41.12),
                                          (7.41, 41.20)])
        geometry = geoalchemy2.shape.from_shape(shape, 4326)
        priority_area = PriorityArea(geometry)
        project.priority_areas.append(priority_area)
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        self.testapp.get('/project/%d' % project_id, status=200)
Example #30
0
    def test_task_difficulty(self):
        from osmtm.models import Task, DBSession
        headers = self.login_as_project_manager()
        self.testapp.put('/project/1/task/1/difficulty/3',
                         headers=headers,
                         status=200,
                         xhr=True)

        task = DBSession.query(Task).get((1, 1))
        self.assertEqual(task.difficulty, task.difficulty_hard)
    def test_project_priority_areas(self):
        import transaction
        project_id = self.create_project()

        from osmtm.models import Project, PriorityArea, DBSession
        project = DBSession.query(Project).get(project_id)

        import shapely
        import geoalchemy2
        shape = shapely.geometry.Polygon(
            [(7.23, 41.25), (7.23, 41.12), (7.41, 41.20)])
        geometry = geoalchemy2.shape.from_shape(shape, 4326)
        priority_area = PriorityArea(geometry)
        project.priority_areas.append(priority_area)
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        self.testapp.get('/project/%d' % project_id, status=200)
    def test_project__archive_allowed(self):
        import transaction
        from osmtm.models import Project, DBSession
        project_id = self.create_project()

        project = DBSession.query(Project).get(project_id)
        project.status = Project.status_archived
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        headers_pm = self.login_as_project_manager()
        self.testapp.get('/project/%d' % project_id,
                         status=200,
                         headers=headers_pm)

        headers_admin = self.login_as_admin()
        self.testapp.get('/project/%d' % project_id,
                         status=200,
                         headers=headers_admin)
    def test_project__archive_allowed(self):
        import transaction
        from osmtm.models import Project, DBSession
        project_id = self.create_project()

        project = DBSession.query(Project).get(project_id)
        project.status = Project.status_archived
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        headers_pm = self.login_as_project_manager()
        self.testapp.get('/project/%d' % project_id,
                         status=200,
                         headers=headers_pm)

        headers_admin = self.login_as_admin()
        self.testapp.get('/project/%d' % project_id,
                         status=200,
                         headers=headers_admin)
Example #34
0
    def create_project(self):
        import geoalchemy2
        import shapely
        import transaction
        from osmtm.models import Area, Project, DBSession

        shape = shapely.geometry.Polygon(
            [(7.23, 41.25), (7.23, 41.12), (7.41, 41.20)])
        geometry = geoalchemy2.shape.from_shape(shape, 4326)
        area = Area(geometry)
        project = Project(u'test project')
        project.area = area
        project.auto_fill(12)

        DBSession.add(project)
        DBSession.flush()
        project_id = project.id
        transaction.commit()

        return project_id
    def test_license__accept_or_reject(self):
        from osmtm.models import DBSession, User, License
        from . import USER1_ID
        headers = self.login_as_user1()
        self.testapp.post('/license/%d' % 1, headers=headers,
                          params={
                              'accepted_terms': 'I AGREE'
                          },
                          status=302)

        user = DBSession.query(User).get(USER1_ID)
        license = DBSession.query(License).get(1)
        self.assertTrue(license in user.accepted_licenses)

        self.testapp.post('/license/1', headers=headers,
                          params={
                              'accepted_terms': 'blah'
                          },
                          status=302)
        user = DBSession.query(User).get(USER1_ID)
        self.assertFalse(license in user.accepted_licenses)
    def test_task_assign_delete(self):
        from osmtm.models import Task, DBSession

        headers = self.login_as_project_manager()
        # assign task to user 1
        self.testapp.delete('/project/1/task/1/user',
                            headers=headers,
                            status=200,
                            xhr=True)

        task = DBSession.query(Task).get((1, 1))
        self.assertEqual(task.assigned_to_id, None)
    def test_task_comment__with_mention(self):
        from osmtm.models import Message, DBSession
        messages_bef = DBSession.query(Message) \
                                .filter(Message.to_user_id == self.user2_id) \
                                .all()
        headers = self.login_as_user1()
        res = self.testapp.get('/project/1/task/3/comment',
                               status=200,
                               headers=headers,
                               params={'comment': 'some_comment @user2'},
                               xhr=True)
        self.assertTrue(res.json['success'])

        messages_aft = DBSession.query(Message) \
                                .filter(Message.to_user_id == self.user2_id) \
                                .all()
        self.assertEqual(len(messages_aft), (len(messages_bef) + 1))

        res = self.testapp.get('/project/1/task/3', status=200, xhr=True)
        # confirm that the convert_mention filter is correctly called
        self.assertTrue('<a href="/user/user2">@user2</a>' in res)
Example #38
0
    def test_task_assign_delete(self):
        from osmtm.models import Task, DBSession

        headers = self.login_as_project_manager()
        # assign task to user 1
        self.testapp.delete('/project/1/task/1/user',
                            headers=headers,
                            status=200,
                            xhr=True)

        task = DBSession.query(Task).get((1, 1))
        self.assertEqual(task.assigned_to_id, None)
    def test_label_new__submitted(self):
        from osmtm.models import DBSession, Label
        headers = self.login_as_admin()
        self.testapp.post('/label/new', headers=headers,
                          params={
                              'form.submitted': True,
                              'name': 'Name',
                              'color': '#ff0000',
                          },
                          status=302)

        self.assertEqual(DBSession.query(Label).count(), 3)
 def test_project_new_grid_extra_instructions(self):
     from osmtm.models import DBSession, Project
     headers = self.login_as_admin()
     self.testapp.get('/project/new/grid', headers=headers,
                      params={
                          'form.submitted': True,
                          'geometry': '{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[2.28515625,46.37725420510028],[3.076171875,45.9511496866914],[3.69140625,46.52863469527167],[2.28515625,46.37725420510028]]]}}]}',  # noqa
                          'tile_size': -2
                      },
                      status=302)
     project = DBSession.query(Project).order_by(Project.id.desc()).first()
     self.assertEqual(project.tasks[0].get_extra_instructions(), '')
Example #41
0
    def test_project_new_arbitrary_extra_properties(self):
        from osmtm.models import DBSession, Project
        import json
        import transaction

        headers = self.login_as_admin()
        self.testapp.post(
            '/project/new/arbitrary',
            headers=headers,
            params={
                'form.submitted':
                True,
                'geometry':
                '{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"test1": "val1", "test2": "val2"},"geometry":{"type":"Polygon","coordinates":[[[4.39453125,19.559790136497398],[4.04296875,21.37124437061832],[7.6025390625,22.917922936146045],[8.96484375,20.05593126519445],[5.625,18.93746442964186],[4.39453125,19.559790136497398]]]}}]}'  # noqa
            },
            status=302)
        project = DBSession.query(Project).order_by(Project.id.desc()).first()
        task1 = project.tasks[0]
        self.assertEqual(json.loads(task1.extra_properties)['test1'], 'val1')
        self.assertEqual(json.loads(task1.extra_properties)['test2'], 'val2')
        project.per_task_instructions = u'replace {test1} and {test2}'
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()
        project = DBSession.query(Project).order_by(Project.id.desc()).first()
        task1 = project.tasks[0]
        self.assertEqual(task1.get_extra_instructions(),
                         'replace val1 and val2')
Example #42
0
    def test_project__experienced_mapper(self):
        import transaction
        from osmtm.models import DBSession, Project
        project_id = self.create_project()
        project = DBSession.query(Project).get(project_id)
        project.requires_experienced_mapper_role = True
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        project = DBSession.query(Project).get(project_id)
        tasks = project.tasks
        headers_user1 = self.login_as_user1()
        from osmtm.tests import EXPERIENCED_MAPPER_ID
        headers_exp_map = self.login_as_user(EXPERIENCED_MAPPER_ID)

        res = self.testapp.get('/project/%d/task/%d' %
                               (project_id, tasks[0].id),
                               headers=headers_user1,
                               status=200,
                               xhr=True)
        self.assertTrue('experienced mapper' in res.body)

        res = self.testapp.get('/project/%d/task/%d' %
                               (project_id, tasks[0].id),
                               headers=headers_exp_map,
                               status=200,
                               xhr=True)
        self.assertFalse('experienced mapper' in res.body)
Example #43
0
    def test_task_random__none_available(self):
        import geoalchemy2
        import shapely
        import transaction
        from osmtm.models import Area, Project, TaskState, DBSession

        shape = shapely.geometry.Polygon(
            [(7.23, 41.25), (7.23, 41.12), (7.41, 41.20)])
        geometry = geoalchemy2.shape.from_shape(shape, 4326)
        area = Area(geometry)
        project = Project(u'test project')
        project.area = area
        project.auto_fill(10)

        DBSession.add(project)
        DBSession.flush()
        project_id = project.id

        for task in project.tasks:
            task.states.append(TaskState(state=TaskState.state_done))
            DBSession.add(task)

        transaction.commit()

        headers = self.login_as_user1()
        res = self.testapp.get('/project/%d/random' % project_id, status=200,
                               headers=headers,
                               xhr=True)
        self.assertFalse(res.json['success'])
    def test_project_new_arbitrary_extra_properties(self):
        from osmtm.models import DBSession, Project
        import json
        import transaction

        headers = self.login_as_admin()
        self.testapp.post('/project/new/arbitrary',
                          headers=headers,
                          params={
                              'form.submitted': True,
                              'geometry': '{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"test1": "val1", "test2": "val2"},"geometry":{"type":"Polygon","coordinates":[[[4.39453125,19.559790136497398],[4.04296875,21.37124437061832],[7.6025390625,22.917922936146045],[8.96484375,20.05593126519445],[5.625,18.93746442964186],[4.39453125,19.559790136497398]]]}}]}'  # noqa
                          },
                          status=302)
        project = DBSession.query(Project).order_by(Project.id.desc()).first()
        task1 = project.tasks[0]
        self.assertEqual(json.loads(task1.extra_properties)['test1'], 'val1')
        self.assertEqual(json.loads(task1.extra_properties)['test2'], 'val2')
        project.per_task_instructions = u'replace {test1} and {test2}'
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()
        project = DBSession.query(Project).order_by(Project.id.desc()).first()
        task1 = project.tasks[0]
        self.assertEqual(task1.get_extra_instructions(),
                         'replace val1 and val2')
    def test_project_new_arbitrary_extra_properties(self):
        from osmtm.models import DBSession, Project
        import json
        import transaction

        headers = self.login_as_admin()
        self.testapp.post('/project/new/arbitrary',
                          headers=headers,
                          params={
                              'form.submitted': True,
                              'geometry': '{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"test1": "val1", "test2": "val2"},"geometry":{"type":"Polygon","coordinates":[[[4.39453125,19.559790136497398],[4.04296875,21.37124437061832],[7.6025390625,22.917922936146045],[8.96484375,20.05593126519445],[5.625,18.93746442964186],[4.39453125,19.559790136497398]]]}},{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[1.3623046875,17.09879223767869],[3.0322265625,18.687878686034196],[6.0205078125,18.271086109608877],[6.2841796875,16.972741019999035],[5.3173828125,16.509832826905846],[4.482421875,17.056784609942554],[2.900390625,16.088042220148807],[1.3623046875,17.09879223767869]]]}},{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[1.0986328125,19.849393958422805],[1.7578125,21.53484700204879],[3.7353515625,20.46818922264095],[3.33984375,18.979025953255267],[0.439453125,19.394067895396628],[1.0986328125,19.849393958422805]]]}}]}'  # noqa
                          },
                          status=302)
        project = DBSession.query(Project).order_by(Project.id.desc()).first()
        task1 = project.tasks[0]
        self.assertEqual(json.loads(task1.extra_properties)['test1'], 'val1')
        self.assertEqual(json.loads(task1.extra_properties)['test2'], 'val2')
        project.per_task_instructions = 'replace {test1} and {test2}'
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()
        project = DBSession.query(Project).order_by(Project.id.desc()).first()
        task1 = project.tasks[0]
        self.assertEqual(task1.get_extra_instructions(),
                         'replace val1 and val2')
    def test_project__experienced_mapper(self):
        import transaction
        from osmtm.models import DBSession, Project
        project_id = self.create_project()
        project = DBSession.query(Project).get(project_id)
        project.requires_experienced_mapper_role = True
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        project = DBSession.query(Project).get(project_id)
        tasks = project.tasks
        headers_user1 = self.login_as_user1()
        from osmtm.tests import EXPERIENCED_MAPPER_ID
        headers_exp_map = self.login_as_user(EXPERIENCED_MAPPER_ID)

        res = self.testapp.get('/project/%d/task/%d' % (project_id,
                                                        tasks[0].id),
                               headers=headers_user1, status=200, xhr=True)
        self.assertTrue('experienced mapper' in res.body)

        res = self.testapp.get('/project/%d/task/%d' % (project_id,
                                                        tasks[0].id),
                               headers=headers_exp_map, status=200, xhr=True)
        self.assertFalse('experienced mapper' in res.body)
    def test_task_random__none_available(self):
        import geoalchemy2
        import shapely
        import transaction
        from osmtm.models import Area, Project, TaskState, DBSession

        shape = shapely.geometry.Polygon([(7.23, 41.25), (7.23, 41.12),
                                          (7.41, 41.20)])
        geometry = geoalchemy2.shape.from_shape(shape, 4326)
        area = Area(geometry)
        project = Project(u'test project')
        project.area = area
        project.auto_fill(10)

        DBSession.add(project)
        DBSession.flush()
        project_id = project.id

        for task in project.tasks:
            task.states.append(TaskState(state=TaskState.state_done))
            DBSession.add(task)

        transaction.commit()

        headers = self.login_as_user1()
        res = self.testapp.get('/project/%d/random' % project_id,
                               status=200,
                               headers=headers,
                               xhr=True)
        self.assertFalse(res.json['success'])
Example #48
0
    def test_project_new_arbitrary_no_extra_properties(self):
        from osmtm.models import DBSession, Project
        import transaction

        headers = self.login_as_admin()
        self.testapp.post(
            '/project/new/arbitrary',
            headers=headers,
            params={
                'form.submitted':
                True,
                'geometry':
                '{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[4.39453125,19.559790136497398],[4.04296875,21.37124437061832],[7.6025390625,22.917922936146045],[8.96484375,20.05593126519445],[5.625,18.93746442964186],[4.39453125,19.559790136497398]]]}},{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[1.3623046875,17.09879223767869],[3.0322265625,18.687878686034196],[6.0205078125,18.271086109608877],[6.2841796875,16.972741019999035],[5.3173828125,16.509832826905846],[4.482421875,17.056784609942554],[2.900390625,16.088042220148807],[1.3623046875,17.09879223767869]]]}},{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[1.0986328125,19.849393958422805],[1.7578125,21.53484700204879],[3.7353515625,20.46818922264095],[3.33984375,18.979025953255267],[0.439453125,19.394067895396628],[1.0986328125,19.849393958422805]]]}}]}'  # noqa
            },
            status=302)
        project = DBSession.query(Project).order_by(Project.id.desc()).first()
        task1 = project.tasks[0]
        self.assertEqual(task1.extra_properties, '{}')
        project.per_task_instructions = u'test'
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()
        project = DBSession.query(Project).order_by(Project.id.desc()).first()
        task1 = project.tasks[0]
        self.assertEqual(task1.get_extra_instructions(), 'test')
Example #49
0
    def test_user_project_manager__logged_in_as_admin(self):
        httpretty.enable()

        from osmtm.models import User, DBSession
        import transaction

        userid = 5463
        username = u'simon_user'
        user = User(userid, username)
        DBSession.add(user)
        DBSession.flush()
        transaction.commit()

        httpretty.register_uri(
            httpretty.GET,
            "http://www.openstreetmap.org/api/0.6/user/%s" % userid,
            body='<?xml version="1.0" encoding="UTF-8"?>' +
                 '<osm> <user display_name="%s"></user></osm>' % username,
            content_type='application/xml; charset=utf-8')

        headers = self.login_as_admin()
        res = self.testapp.get('/user/%d/project_manager' % userid,
                               headers=headers,
                               status=302)
        res2 = res.follow(headers=headers, status=200)
        self.failUnless('This user is a project manager' in res2.body)

        DBSession.delete(user)
        transaction.commit()
Example #50
0
    def test_project_new_arbitrary_extra_properties_with_colon(self):
        from osmtm.models import DBSession, Project
        import transaction

        headers = self.login_as_admin()
        self.testapp.post(
            '/project/new/arbitrary',
            headers=headers,
            params={
                'form.submitted':
                True,
                'geometry':
                '{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"foo:bar": "val1"},"geometry":{"type":"Polygon","coordinates":[[[4.39,19.55],[4.04,21.37],[7.60,22.91],[8.96,20.05],[5.62,18.93],[4.39,19.55]]]}}]}'  # noqa
            },
            status=302)

        project = DBSession.query(Project).order_by(Project.id.desc()).first()
        project_id = project.id
        task1 = project.tasks[0]
        project.per_task_instructions = u'replace {foo:bar}'
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()
        project = DBSession.query(Project).get(project_id)
        task1 = project.tasks[0]
        self.assertEqual(task1.get_extra_instructions(), 'replace val1')
Example #51
0
    def test_user_project_manager__logged_in_as_admin(self):
        httpretty.enable()

        from osmtm.models import User, DBSession
        import transaction

        userid = 5463
        username = u'simon_user'
        user = User(userid, username)
        DBSession.add(user)
        DBSession.flush()
        transaction.commit()

        httpretty.register_uri(
            httpretty.GET,
            "http://www.openstreetmap.org/api/0.6/user/%s" % userid,
            body='<?xml version="1.0" encoding="UTF-8"?>' +
            '<osm> <user display_name="%s"></user></osm>' % username,
            content_type='application/xml; charset=utf-8')

        headers = self.login_as_admin()
        res = self.testapp.get('/user/%d/project_manager' % userid,
                               headers=headers,
                               status=302)
        res2 = res.follow(headers=headers, status=200)
        self.failUnless('This user is a project manager' in res2.body)

        DBSession.delete(user)
        transaction.commit()
    def test_license_edit__submitted(self):
        from osmtm.models import DBSession, License
        headers = self.login_as_admin()
        self.testapp.post('/license/1/edit', headers=headers,
                          params={
                              'form.submitted': True,
                              'name': 'changed_name',
                              'description': 'changed_description',
                              'plain_text': 'changed_plain_text'
                          },
                          status=302)

        self.assertEqual(DBSession.query(License).get(1).name, u'changed_name')
    def test_license_new__submitted(self):
        from osmtm.models import DBSession, License
        headers = self.login_as_admin()
        self.testapp.post('/license/new', headers=headers,
                          params={
                              'form.submitted': True,
                              'name': 'New License',
                              'description': 'description',
                              'plain_text': 'plain_text'
                          },
                          status=302)

        self.assertEqual(DBSession.query(License).count(), 2)
Example #54
0
    def test_project_new_grid(self):
        from osmtm.models import DBSession, Project
        headers = self.login_as_admin()
        self.testapp.get('/project/new/grid', headers=headers,
                         params={
                             'form.submitted': True,
                             'geometry': '{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[2.28515625,46.37725420510028],[3.076171875,45.9511496866914],[3.69140625,46.52863469527167],[2.28515625,46.37725420510028]]]}}]}',  # noqa
                             'tile_size': -2
                         },
                         status=302)

        project = DBSession.query(Project).order_by(Project.id.desc()).first()
        self.assertEqual(len(project.tasks), 4)
    def test_task_comment__with_mention(self):
        from osmtm.models import Message, DBSession
        messages_bef = DBSession.query(Message) \
                                .filter(Message.to_user_id == self.user2_id) \
                                .all()
        headers = self.login_as_user1()
        res = self.testapp.get('/project/1/task/3/comment', status=200,
                               headers=headers,
                               params={
                                   'comment': 'some_comment @user2'
                               },
                               xhr=True)
        self.assertTrue(res.json['success'])

        messages_aft = DBSession.query(Message) \
                                .filter(Message.to_user_id == self.user2_id) \
                                .all()
        self.assertEqual(len(messages_aft), (len(messages_bef) + 1))

        res = self.testapp.get('/project/1/task/3', status=200, xhr=True)
        # confirm that the convert_mention filter is correctly called
        self.assertTrue('<a href="/user/user2">@user2</a>' in res)
    def test_task_validate_roles(self):
        import transaction
        from osmtm.models import Project, DBSession

        headers = self.login_as_user1()
        self.testapp.get('/project/1/task/8/lock', headers=headers, xhr=True)
        self.testapp.get('/project/1/task/8/done', headers=headers, xhr=True)

        headers = self.login_as_validator()
        resp = self.testapp.get('/project/1/task/8', headers=headers, xhr=True)
        self.assertTrue('Review the work' in resp.body)

        headers = self.login_as_user2()
        resp = self.testapp.get('/project/1/task/8', headers=headers, xhr=True)
        self.assertTrue('Review the work' in resp.body)

        project = DBSession.query(Project).get(1)
        project.requires_validator_role = True
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        headers = self.login_as_validator()
        resp = self.testapp.get('/project/1/task/8', headers=headers, xhr=True)
        self.assertTrue('Review the work' in resp.body)

        headers = self.login_as_user2()
        resp = self.testapp.get('/project/1/task/8', headers=headers, xhr=True)
        self.assertFalse('Review the work' in resp.body)
        resp = self.testapp.get('/project/1/task/8/lock',
                                headers=headers,
                                xhr=True)
        self.assertFalse(resp.json['success'])

        project = DBSession.query(Project).get(1)
        project.requires_validator_role = False
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()