def test_task_random__none_available(self): import geoalchemy2 import shapely import transaction from osmtm.models import Area, Project, TaskState, DBSession shape = shapely.geometry.Polygon( [(7.23, 41.25), (7.23, 41.12), (7.41, 41.20)]) geometry = geoalchemy2.shape.from_shape(shape, 4326) area = Area(geometry) project = Project(u'test project') project.area = area project.auto_fill(10) DBSession.add(project) DBSession.flush() project_id = project.id for task in project.tasks: task.states.append(TaskState(state=TaskState.state_done)) DBSession.add(task) transaction.commit() headers = self.login_as_user1() res = self.testapp.get('/project/%d/random' % project_id, status=200, headers=headers, xhr=True) self.assertFalse(res.json['success'])
def test_task_random__none_available(self): import geoalchemy2 import shapely import transaction from osmtm.models import Area, Project, TaskState, DBSession shape = shapely.geometry.Polygon([(7.23, 41.25), (7.23, 41.12), (7.41, 41.20)]) geometry = geoalchemy2.shape.from_shape(shape, 4326) area = Area(geometry) project = Project(u'test project') project.area = area project.auto_fill(10) DBSession.add(project) DBSession.flush() project_id = project.id for task in project.tasks: task.states.append(TaskState(state=TaskState.state_done)) DBSession.add(task) transaction.commit() headers = self.login_as_user1() res = self.testapp.get('/project/%d/random' % project_id, status=200, headers=headers, xhr=True) self.assertFalse(res.json['success'])
def test_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'])
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 populate_db(): import geoalchemy2 import shapely testing.setUp() config = ConfigParser.ConfigParser() config.read(local_settings_path) db_url = config.get('app:main', 'sqlalchemy.url') engine = create_engine(db_url) Base.metadata.drop_all(engine) Base.metadata.create_all(engine) DBSession.configure(bind=engine) # those users are immutables ie. they're not suppose to change during tests user = User(USER1_ID, u'user1') DBSession.add(user) user = User(USER2_ID, u'user2') DBSession.add(user) user = User(ADMIN_USER_ID, u'admin_user') user.role = User.role_admin DBSession.add(user) user = User(PROJECT_MANAGER_USER_ID, u'project_manager_user') user.role = User.role_project_manager DBSession.add(user) license = License() license.name = u'LicenseBar' license.description = u'the_description_for_license_bar' license.plain_text = u'the_plain_text_for_license_bar' DBSession.add(license) 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) project.status = Project.status_published DBSession.add(project) transaction.commit() DBSession.remove()
def populate_db(): import geoalchemy2 import shapely config = ConfigParser.ConfigParser() config.read(local_settings_path) db_url = config.get('app:main', 'sqlalchemy.url') engine = create_engine(db_url) Base.metadata.drop_all(engine) Base.metadata.create_all(engine) DBSession.configure(bind=engine) # those users are immutables ie. they're not suppose to change during tests user = User(USER1_ID, u'user1') DBSession.add(user) user = User(USER2_ID, u'user2') DBSession.add(user) user = User(ADMIN_USER_ID, u'admin_user') user.role = User.role_admin DBSession.add(user) user = User(PROJECT_MANAGER_USER_ID, u'project_manager_user') user.role = User.role_project_manager DBSession.add(user) license = License() license.name = u'LicenseBar' license.description = u'the_description_for_license_bar' license.plain_text = u'the_plain_text_for_license_bar' DBSession.add(license) 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) project.status = Project.status_published DBSession.add(project) transaction.commit() DBSession.remove()
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 populate_db(): import geoalchemy2 import shapely engine = create_engine(db_url) Base.metadata.drop_all(engine) Base.metadata.create_all(engine) DBSession.configure(bind=engine) # those users are immutables ie. they're not suppose to change during tests user = User(USER1_ID, u'user1', False) DBSession.add(user) user = User(USER2_ID, u'user2', False) DBSession.add(user) user = User(ADMIN_USER_ID, u'admin_user', True) DBSession.add(user) license = License() license.name = u'LicenseBar' license.description = u'the_description_for_license_bar' license.plain_text = u'the_plain_text_for_license_bar' DBSession.add(license) 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) transaction.commit() DBSession.remove()
def populate_db(): import geoalchemy2 import shapely testing.setUp() config = ConfigParser.ConfigParser() config.read(local_settings_path) db_url = config.get('app:main', 'sqlalchemy.url') engine = create_engine(db_url) Base.metadata.drop_all(engine) Base.metadata.create_all(engine) DBSession.configure(bind=engine) # those users are immutables ie. they're not suppose to change during tests user = User(USER1_ID, u'user1') DBSession.add(user) user = User(USER2_ID, u'user2') DBSession.add(user) user = User(ADMIN_USER_ID, u'admin_user') user.role = User.role_admin DBSession.add(user) user = User(PROJECT_MANAGER_USER_ID, u'project_manager_user') user.role = User.role_project_manager DBSession.add(user) user = User(VALIDATOR_ID, u'user_validator') user.role = User.role_validator DBSession.add(user) user = User(EXPERIENCED_MAPPER_ID, u'user_experienced_mapper') user.role = User.role_experienced_mapper DBSession.add(user) license = License() license.name = u'LicenseBar' license.description = u'the_description_for_license_bar' license.plain_text = u'the_plain_text_for_license_bar' DBSession.add(license) label0 = Label() label0.name = u'bar' label0.color = u'#ff0000' DBSession.add(label0) label1 = Label() label1.name = u'dude label' label1.color = u'#ff0000' DBSession.add(label1) 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.short_description = u'lorem ipsum description' project.area = area project.auto_fill(12) project.status = Project.status_published project.labels = [label0, label1] DBSession.add(project) transaction.commit() DBSession.remove()