예제 #1
0
    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)
예제 #2
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')
예제 #3
0
    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)
예제 #4
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)
예제 #5
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')
예제 #6
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)
예제 #7
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_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_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')
예제 #10
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_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)
예제 #12
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'])
예제 #13
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')
예제 #14
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')
예제 #15
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_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)
예제 #17
0
    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))
    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)
예제 #19
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()
예제 #20
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_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)
    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_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)
예제 #28
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_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_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)
예제 #32
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)
예제 #33
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)
예제 #34
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_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)
예제 #36
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_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)
예제 #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)
예제 #39
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)
예제 #40
0
    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_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(), '')
예제 #42
0
    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)
예제 #43
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)
예제 #44
0
    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)
예제 #45
0
    def test_project_new_import_submitted(self):
        from osmtm.models import DBSession, Project
        headers = self.login_as_admin()
        self.testapp.post('/project/new/import',
                          upload_files=[('import', 'map.geojson', '{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"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
                          headers=headers,
                          params={
                              'form.submitted': True
                          },
                          status=302)

        project = DBSession.query(Project).order_by(Project.id.desc()).first()
        self.assertEqual(len(project.tasks), 3)
예제 #46
0
    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)
예제 #47
0
    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_project_new_grid_submitted(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":"Polygon","coordinates":[[[2.28515625,46.37725420510028],[3.076171875,45.9511496866914],[3.69140625,46.52863469527167],[2.28515625,46.37725420510028]]]}',  # noqa
                             'zoom': 10
                         },
                         status=302)

        project = DBSession.query(Project).order_by(Project.id.desc()).first()
        self.assertEqual(len(project.tasks), 11)
    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)
예제 #50
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_project_new_import_submitted(self):
        from osmtm.models import DBSession, Project
        headers = self.login_as_admin()
        self.testapp.post('/project/new/import',
                          upload_files=[('import', 'map.geojson', '{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"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
                          headers=headers,
                          params={
                              'form.submitted': True
                          },
                          status=302)

        project = DBSession.query(Project).order_by(Project.id.desc()).first()
        self.assertEqual(len(project.tasks), 3)
예제 #52
0
    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)
    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)
예제 #54
0
    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()
    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)
예제 #56
0
    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)
예제 #57
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)
예제 #58
0
    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')