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)
Beispiel #2
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()
    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)
    def test_home__private_not_allowed(self):
        import transaction
        from . import USER1_ID
        from osmtm.models import User, Project, DBSession
        project_id = self.create_project()

        project = DBSession.query(Project).get(project_id)
        project.name = u"private_project"
        project.private = True
        project.status = Project.status_published
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        res = self.testapp.get('/', status=200)
        self.assertFalse("private_project" in res.body)

        res = self.testapp.get('/', status=200, params={'search': 'private'})
        self.assertFalse("private_project" in res.body)

        headers_user1 = self.login_as_user1()
        res = self.testapp.get('/', status=200, headers=headers_user1)
        self.assertFalse("private_project" in res.body)

        user1 = DBSession.query(User).get(USER1_ID)
        project = DBSession.query(Project).get(project_id)
        project.status = project.status_published
        project.allowed_users.append(user1)
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        res = self.testapp.get('/', status=200, headers=headers_user1)
        self.assertTrue("private_project" in res.body)
Beispiel #5
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_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_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()
Beispiel #8
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')
Beispiel #9
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_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'])
Beispiel #11
0
    def test_project__draft_not_allowed(self):
        import transaction
        from . import USER1_ID
        from osmtm.models import User, 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)

        user1 = DBSession.query(User).get(USER1_ID)
        project = DBSession.query(Project).get(project_id)
        project.allowed_users.append(user1)
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()
        self.testapp.get('/project/%d' % project_id,
                         status=403,
                         headers=headers_user1)
Beispiel #12
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')
    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_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()
    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)
    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_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_home__private_not_allowed(self):
        import transaction
        from . import USER1_ID
        from osmtm.models import User, 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()

        res = self.testapp.get('/', status=200)
        self.assertFalse("private_project" in res.body)

        res = self.testapp.get('/', status=200,
                               params={
                                   'search': 'private'
                               })
        self.assertFalse("private_project" in res.body)

        headers_user1 = self.login_as_user1()
        res = self.testapp.get('/', status=200, headers=headers_user1)
        self.assertFalse("private_project" in res.body)

        user1 = DBSession.query(User).get(USER1_ID)
        project = DBSession.query(Project).get(project_id)
        project.allowed_users.append(user1)
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        res = self.testapp.get('/', status=200, headers=headers_user1)
        self.assertTrue("private_project" in res.body)
    def test_project__draft_not_allowed(self):
        import transaction
        from . import USER1_ID
        from osmtm.models import User, 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)

        user1 = DBSession.query(User).get(USER1_ID)
        project = DBSession.query(Project).get(project_id)
        project.allowed_users.append(user1)
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()
        self.testapp.get('/project/%d' % project_id,
                         status=403,
                         headers=headers_user1)
    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_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'])
Beispiel #22
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)
    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_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'])
Beispiel #25
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')
    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_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)
Beispiel #29
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_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_project__private_not_allowed(self):
        import transaction
        from osmtm.models import Project, DBSession
        project_id = self.create_project()

        project = DBSession.query(Project).get(project_id)
        project.private = True
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()
        self.testapp.get('/project/%d' % project_id, status=403)

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

        project = DBSession.query(Project).get(project_id)
        project.private = True
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()
        self.testapp.get('/project/%d' % project_id, status=403)

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

        project = DBSession.query(Project).get(project_id)

        import datetime
        now = datetime.datetime.now()
        project.due_date = now - datetime.timedelta(hours=5)
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        self.testapp.get('/', status=200)
        project = DBSession.query(Project).get(project_id)
        self.assertEqual(project.status, Project.status_archived)
    def test_message(self):
        import transaction
        from osmtm.tests import USER1_ID, USER2_ID
        from osmtm.models import Message, User, DBSession
        user1 = DBSession.query(User).get(USER1_ID)
        user2 = DBSession.query(User).get(USER2_ID)
        message = Message(u'subject', user2, user1, u'message')
        DBSession.add(message)
        DBSession.flush()
        id = message.id
        transaction.commit()

        headers = self.login_as_user1()
        self.testapp.get('/message/read/%d' % id, headers=headers, status=200)

        headers = self.login_as_user2()
        self.testapp.get('/message/read/%d' % id, headers=headers, status=403)
    def test_message(self):
        import transaction
        from osmtm.tests import USER1_ID, USER2_ID
        from osmtm.models import Message, User, DBSession
        user1 = DBSession.query(User).get(USER1_ID)
        user2 = DBSession.query(User).get(USER2_ID)
        message = Message(u'subject', user2, user1, u'message')
        DBSession.add(message)
        DBSession.flush()
        id = message.id
        transaction.commit()

        headers = self.login_as_user1()
        self.testapp.get('/message/read/%d' % id, headers=headers, status=200)

        headers = self.login_as_user2()
        self.testapp.get('/message/read/%d' % id, headers=headers, status=403)
    def test_project_check_expiration(self):
        import transaction
        from osmtm.models import Project, DBSession
        project_id = self.create_project()

        project = DBSession.query(Project).get(project_id)

        import datetime
        now = datetime.datetime.now()
        project.due_date = now - datetime.timedelta(hours=5)
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        self.testapp.get('/', status=200)
        project = DBSession.query(Project).get(project_id)
        self.assertEqual(project.status, Project.status_archived)
    def test_check_for_message(self):
        import transaction
        from osmtm.tests import USER1_ID, USER2_ID
        from osmtm.models import Message, User, DBSession
        user1 = DBSession.query(User).get(USER1_ID)
        user2 = DBSession.query(User).get(USER2_ID)
        message = Message(u'subject', user2, user1, u'message')
        DBSession.add(message)
        DBSession.flush()
        transaction.commit()

        headers = self.login_as_user1()
        res = self.testapp.get('/user/messages/check',
                               headers=headers,
                               params={'interval': 1000},
                               status=200)
        self.assertTrue(res.json['new_message'])
        self.assertEqual(res.json['unread'], 1)
    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)
Beispiel #39
0
    def test_project_user_delete(self):
        import transaction
        from . import USER1_ID
        from osmtm.models import User, Project, DBSession
        project_id = self.create_project()

        project = DBSession.query(Project).get(project_id)
        user1 = DBSession.query(User).get(USER1_ID)
        project.allowed_users.append(user1)
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        headers = self.login_as_admin()
        self.testapp.delete('/project/%d/user/%d' % (project_id, USER1_ID),
                            headers=headers, status=200)

        project = DBSession.query(Project).get(project_id)
        self.assertEqual(len(project.allowed_users), 0)
    def test_project_user_delete(self):
        import transaction
        from . import USER1_ID
        from osmtm.models import User, Project, DBSession
        project_id = self.create_project()

        project = DBSession.query(Project).get(project_id)
        user1 = DBSession.query(User).get(USER1_ID)
        project.allowed_users.append(user1)
        DBSession.add(project)
        DBSession.flush()
        transaction.commit()

        headers = self.login_as_admin()
        self.testapp.delete('/project/%d/user/%d' % (project_id, USER1_ID),
                            headers=headers, status=200)

        project = DBSession.query(Project).get(project_id)
        self.assertEqual(len(project.allowed_users), 0)
    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_check_for_message(self):
        import transaction
        from osmtm.tests import USER1_ID, USER2_ID
        from osmtm.models import Message, User, DBSession
        user1 = DBSession.query(User).get(USER1_ID)
        user2 = DBSession.query(User).get(USER2_ID)
        message = Message(u'subject', user2, user1, u'message')
        DBSession.add(message)
        DBSession.flush()
        transaction.commit()

        headers = self.login_as_user1()
        res = self.testapp.get('/user/messages/check',
                               headers=headers,
                               params={
                                   'interval': 1000
                               },
                               status=200)
        self.assertTrue(res.json['new_message'])
        self.assertEqual(res.json['unread'], 1)
    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)
Beispiel #44
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_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)
Beispiel #46
0
    def test_user_admin__logged_in_as_admin(self):

        from osmtm.models import User, DBSession
        import transaction

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

        headers = self.login_as_admin()
        res = self.testapp.get('/user/%d/admin' % userid, headers=headers,
                               status=302)
        res2 = res.follow(headers=headers, status=200)
        self.failUnless('dude_user' in res2.body)
        self.failUnless('This user is an administrator' in res2.body)

        DBSession.delete(user)
        transaction.commit()
    def test_task_difficulty_delete(self):
        from osmtm.models import Task, DBSession

        import transaction
        task = DBSession.query(Task).get((1, 1))
        task.difficulty = task.difficulty_easy
        DBSession.add(task)
        DBSession.flush()
        transaction.commit()

        task = DBSession.query(Task).get((1, 1))
        self.assertEqual(task.difficulty, task.difficulty_easy)

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

        task = DBSession.query(Task).get((1, 1))
        self.assertEqual(task.difficulty, None)
    def test_task_difficulty_delete(self):
        from osmtm.models import Task, DBSession

        import transaction
        task = DBSession.query(Task).get((1, 1))
        task.difficulty = task.difficulty_easy
        DBSession.add(task)
        DBSession.flush()
        transaction.commit()

        task = DBSession.query(Task).get((1, 1))
        self.assertEqual(task.difficulty, task.difficulty_easy)

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

        task = DBSession.query(Task).get((1, 1))
        self.assertEqual(task.difficulty, None)
    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()
Beispiel #50
0
    def test_user__username_with_accents(self):
        httpretty.enable()

        from osmtm.models import User, DBSession
        import transaction

        userid = 12
        username = u'new_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_user(userid)
        self.testapp.get('/project/1/task/4/lock',
                         status=200,
                         headers=headers,
                         xhr=True)
        self.testapp.get('/project/1/task/4/done',
                         status=200,
                         headers=headers,
                         params={'comment': 'some_comment'},
                         xhr=True)

        self.testapp.get((u'/user/%s' % username).encode('utf8'), status=200)

        self.testapp.get('/project/1/task/4',
                         status=200,
                         headers=headers,
                         xhr=True)
    def test_label_edit__submitted(self):
        import transaction
        from osmtm.models import DBSession, Label
        headers = self.login_as_admin()

        label = Label()
        label.name = 'some name'
        DBSession.add(label)
        DBSession.flush()
        label_id = label.id
        transaction.commit()

        self.testapp.post('/label/%s/edit' % label_id, headers=headers,
                          params={
                              'form.submitted': True,
                              'name': 'changed_name',
                              'color': '#ff0000',
                          },
                          status=302)

        self.assertEqual(DBSession.query(Label).get(label_id).name,
                         u'changed_name')
        DBSession.delete(label)
        transaction.commit()
    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')
    def test_user__username_with_accents(self):
        httpretty.enable()

        from osmtm.models import User, DBSession
        import transaction

        userid = 12
        username = u'new_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_user(userid)
        self.testapp.get('/project/1/task/4/lock', status=200,
                         headers=headers,
                         xhr=True)
        self.testapp.get('/project/1/task/4/done', status=200,
                         headers=headers,
                         params={
                             'comment': 'some_comment'
                         },
                         xhr=True)

        self.testapp.get((u'/user/%s' % username).encode('utf8'), status=200)

        self.testapp.get('/project/1/task/4', status=200,
                         headers=headers,
                         xhr=True)
tiles_history = metadata_v1.tables['tiles_history']
licenses = metadata_v1.tables['licenses']
users_table = metadata_v1.tables['users']

header("Cleaning up db")
with transaction.manager:
    # FIXME we may need to empty the V2 db first
    session_v2.query(TaskLock).delete()
    session_v2.query(TaskState).delete()
    session_v2.query(TaskComment).delete()
    session_v2.query(Task).delete()
    session_v2.query(Project).delete()
    session_v2.query(Area).delete()
    session_v2.query(License).delete()
    session_v2.query(User).delete()
    session_v2.flush()

header("Retrieving users ids")
f = open('users.list', 'r+')
users = {}
for line in f:
    user = line.split(';')
    users[user[0]] = user[1]

for k, u in enumerate(session_v1.query(users_table).all()):
    username = u.username.encode('utf-8')
    if username not in users:
        print "%s - %s" % (k, u.username)
        url = "http://whosthat.osmz.ru/whosthat.php?action=names&q=%s" % \
            username
        response = urllib.urlopen(url)
tiles_history = metadata_v1.tables['tiles_history']
licenses = metadata_v1.tables['licenses']
users_table = metadata_v1.tables['users']

header("Cleaning up db")
with transaction.manager:
    # FIXME we may need to empty the V2 db first
    session_v2.query(TaskLock).delete()
    session_v2.query(TaskState).delete()
    session_v2.query(TaskComment).delete()
    session_v2.query(Task).delete()
    session_v2.query(Project).delete()
    session_v2.query(Area).delete()
    session_v2.query(License).delete()
    session_v2.query(User).delete()
    session_v2.flush()

header("Retrieving users ids")
f = open('users.list', 'r+')
users = {}
for line in f:
    user = line.split(';')
    users[user[0]] = user[1]

for k, u in enumerate(session_v1.query(users_table).all()):
    username = u.username.encode('utf-8')
    if username not in users:
        print "%s - %s" % (k, u.username)
        url = "http://whosthat.osmz.ru/whosthat.php?action=names&q=%s" % \
            username
        response = urllib.urlopen(url)