本文整理汇总了Python中base.Fixtures类的典型用法代码示例。如果您正苦于以下问题:Python Fixtures类的具体用法?Python Fixtures怎么用?Python Fixtures使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Fixtures类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_20_admin_add_category
def test_20_admin_add_category(self):
"""Test ADMIN add category works"""
Fixtures.create()
category = {'name': 'cat', 'short_name': 'cat',
'description': 'description'}
# Anonymous user
url = '/admin/categories'
res = self.app.post(url, data=category, follow_redirects=True)
dom = BeautifulSoup(res.data)
err_msg = "Anonymous users should be redirected to sign in"
assert dom.find(id='signin') is not None, err_msg
# Authenticated user but not admin
self.signin(email=Fixtures.email_addr2, password=Fixtures.password)
res = self.app.post(url, data=category, follow_redirects=True)
err_msg = "Non-Admin users should get 403"
assert res.status_code == 403, err_msg
self.signout()
# Admin
self.signin(email=Fixtures.root_addr, password=Fixtures.root_password)
res = self.app.post(url, data=category, follow_redirects=True)
err_msg = "Category should be added"
assert "Category added" in res.data, err_msg
assert category['name'] in res.data, err_msg
示例2: test_22_get_specific_completed_task_anonymous
def test_22_get_specific_completed_task_anonymous(self):
"""Test WEB get specific completed task_id for an app works as anonymous"""
model.rebuild_db()
Fixtures.create()
app = model.Session.query(model.App).first()
task = model.Session.query(model.Task)\
.filter(model.App.id==app.id)\
.first()
for i in range(10):
task_run = model.TaskRun(app_id=app.id,
task_id=task.id,
user_ip="127.0.0.1",
info={'answer':1})
model.Session.add(task_run)
model.Session.commit()
ntask = model.Task(id=task.id,state='completed')
assert ntask not in model.Session
model.Session.merge(ntask)
model.Session.commit()
res = self.app.get('app/%s/task/%s' % (app.short_name, task.id),
follow_redirects=True)
assert 'You have already participated in this task' in res.data, res.data
assert 'Try with another one' in res.data, res.data
示例3: test_24_get_specific_completed_task_user
def test_24_get_specific_completed_task_user(self):
"""Test WEB get specific completed task_id for an app works as an user"""
model.rebuild_db()
Fixtures.create()
self.register()
user = model.Session.query(model.User)\
.filter(model.User.name=='johndoe')\
.first()
app = model.Session.query(model.App).first()
task = model.Session.query(model.Task)\
.filter(model.App.id==app.id)\
.first()
for i in range(10):
task_run = model.TaskRun(app_id=app.id,
task_id=task.id,
user_id=user.id,
info={'answer':1})
model.Session.add(task_run)
model.Session.commit()
#self.app.get('api/app/%s/newtask' % app.id)
ntask = model.Task(id=task.id,state='completed')
#self.signin()
assert ntask not in model.Session
model.Session.merge(ntask)
model.Session.commit()
res = self.app.get('app/%s/task/%s' % (app.short_name, task.id),
follow_redirects=True)
assert 'You have already participated in this task' in res.data, res.data
assert 'Try with another one' in res.data, res.data
self.signout()
示例4: test_20_admin_add_category
def test_20_admin_add_category(self):
"""Test ADMIN add category works"""
Fixtures.create()
category = {"name": "cat", "short_name": "cat", "description": "description"}
# Anonymous user
url = "/admin/categories"
res = self.app.post(url, data=category, follow_redirects=True)
dom = BeautifulSoup(res.data)
err_msg = "Anonymous users should be redirected to sign in"
assert dom.find(id="signin") is not None, err_msg
# Authenticated user but not admin
self.signin(email=Fixtures.email_addr2, password=Fixtures.password)
res = self.app.post(url, data=category, follow_redirects=True)
err_msg = "Non-Admin users should get 403"
assert res.status_code == 403, err_msg
self.signout()
# Admin
self.signin(email=Fixtures.root_addr, password=Fixtures.root_password)
res = self.app.post(url, data=category, follow_redirects=True)
err_msg = "Category should be added"
assert "Category added" in res.data, err_msg
assert category["name"] in res.data, err_msg
category = {"name": "cat", "short_name": "cat", "description": "description"}
self.signin(email=Fixtures.root_addr, password=Fixtures.root_password)
res = self.app.post(url, data=category, follow_redirects=True)
err_msg = "Category form validation should work"
assert "Please correct the errors" in res.data, err_msg
示例5: test_25_get_wrong_task_app
def test_25_get_wrong_task_app(self):
"""Test WEB get wrong task.id for an app works"""
model.rebuild_db()
Fixtures.create()
app1 = db.session.query(model.App).get(1)
app1_short_name = app1.short_name
db.session.query(model.Task)\
.filter(model.Task.app_id == 1)\
.first()
self.register()
self.new_application()
app2 = db.session.query(model.App).get(2)
self.new_task(app2.id)
task2 = db.session.query(model.Task)\
.filter(model.Task.app_id == 2)\
.first()
task2_id = task2.id
self.signout()
res = self.app.get('/app/%s/task/%s' % (app1_short_name, task2_id))
assert "Error" in res.data, res.data
assert "This task does not belong to %s" % app1_short_name\
in res.data, res.data
示例6: test_22_admin_delete_category
def test_22_admin_delete_category(self):
"""Test ADMIN delete category works"""
Fixtures.create()
obj = db.session.query(model.Category).get(2)
category = obj.dictize()
# Anonymous user GET
url = "/admin/categories/del/%s" % obj.id
res = self.app.get(url, follow_redirects=True)
dom = BeautifulSoup(res.data)
err_msg = "Anonymous users should be redirected to sign in"
assert dom.find(id="signin") is not None, err_msg
# Anonymous user POST
res = self.app.post(url, data=category, follow_redirects=True)
dom = BeautifulSoup(res.data)
err_msg = "Anonymous users should be redirected to sign in"
assert dom.find(id="signin") is not None, err_msg
# Authenticated user but not admin GET
self.signin(email=Fixtures.email_addr2, password=Fixtures.password)
res = self.app.post(url, follow_redirects=True)
err_msg = "Non-Admin users should get 403"
assert res.status_code == 403, err_msg
# Authenticated user but not admin POST
res = self.app.post(url, data=category, follow_redirects=True)
err_msg = "Non-Admin users should get 403"
assert res.status_code == 403, err_msg
self.signout()
# Admin GET
self.signin(email=Fixtures.root_addr, password=Fixtures.root_password)
res = self.app.get(url, follow_redirects=True)
err_msg = "Category should be listed for admin user"
assert category["name"] in res.data, err_msg
# Admin POST
res = self.app.post(url, data=category, follow_redirects=True)
err_msg = "Category should be deleted"
assert "Category deleted" in res.data, err_msg
assert category["name"] not in res.data, err_msg
output = db.session.query(model.Category).get(obj.id)
assert output is None, err_msg
# Non existant category
category["id"] = 5000
url = "/admin/categories/del/5000"
res = self.app.post(url, data=category, follow_redirects=True)
assert res.status_code == 404, res.status_code
# Now try to delete the only available Category
obj = db.session.query(model.Category).first()
url = "/admin/categories/del/%s" % obj.id
category = obj.dictize()
res = self.app.post(url, data=category, follow_redirects=True)
print res.data
err_msg = "Category should not be deleted"
assert "Category deleted" not in res.data, err_msg
assert category["name"] in res.data, err_msg
output = db.session.query(model.Category).get(obj.id)
assert output.id == category["id"], err_msg
示例7: test_incremental_tasks
def test_incremental_tasks(self):
""" Test incremental SCHED strategy - second TaskRun receives first gaven answer"""
Fixtures.create_2(sched='incremental')
# Del previous TaskRuns
self.del_task_runs()
# Register
self.register(fullname=self.user.fullname, username=self.user.username,
password=self.user.password)
self.register(fullname="Marie Doe", username="mariedoe", password="dr0wss4p")
self.signin()
# Get the only task with no runs!
res = self.app.get('api/app/1/newtask')
data = json.loads(res.data)
# Check that we received a clean Task
assert data.get('info'), data
assert not data.get('info').get('last_answer')
# Submit an Answer for the assigned task
tr = dict(app_id=data['app_id'], task_id=data['id'], info={'answer': 'No'})
tr = json.dumps(tr)
self.app.post('/api/taskrun', data=tr)
# No more tasks available for this user!
res = self.app.get('api/app/1/newtask')
data = json.loads(res.data)
assert not data
#### Get the only task now with an answer as Anonimous!
self.signout()
res = self.app.get('api/app/1/newtask')
data = json.loads(res.data)
# Check that we received a Task with answer
assert data.get('info'), data
assert data.get('info').get('last_answer').get('answer') == 'No'
# Submit a second Answer as Anonimous
tr = dict(app_id=data['app_id'], task_id=data['id'],
info={'answer': 'No No'})
tr = json.dumps(tr)
self.app.post('/api/taskrun', data=tr)
#### Get the only task now with an answer as User2!
self.signin(email="[email protected]", password="dr0wss4p")
res = self.app.get('api/app/1/newtask')
data = json.loads(res.data)
# Check that we received a Task with answer
assert data.get('info'), data
assert data.get('info').get('last_answer').get('answer') == 'No No'
示例8: test_21_get_specific_ongoing_task_anonymous
def test_21_get_specific_ongoing_task_anonymous(self):
"""Test WEB get specific ongoing task_id for
an app works as anonymous"""
Fixtures.create()
self.delTaskRuns()
app = db.session.query(model.App).first()
task = db.session.query(model.Task).filter(model.App.id == app.id).first()
res = self.app.get("app/%s/task/%s" % (app.short_name, task.id), follow_redirects=True)
assert "TaskPresenter" in res.data, res.data
assert "?next=%2Fapp%2F" + app.short_name + "%2Ftask%2F" + str(task.id), res.data
示例9: test_29_tutorial_anonymous_user
def test_29_tutorial_anonymous_user(self):
"""Test WEB app without tutorials work as an anonymous user"""
Fixtures.create()
db.session.commit()
self.register()
# First time accessing the app should redirect me to the tutorial
res = self.app.get("/app/test-app/newtask", follow_redirects=True)
assert "some help" not in res.data, "There should not be a tutorial for the application"
# Second time should give me a task, and not the tutorial
res = self.app.get("/app/test-app/newtask", follow_redirects=True)
assert "some help" not in res.data
示例10: setUp
def setUp(self):
model.rebuild_db()
self.root, self.user1, self.user2 = Fixtures.create_users()
self.app = Fixtures.create_app('')
self.app.owner = self.root
db.session.add(self.app)
db.session.commit()
self.task = model.Task(app_id=self.app.id, state='0', n_answers=10)
self.task.app = self.app
db.session.add(self.task)
db.session.commit()
示例11: test_28_non_tutorial_signed_user
def test_28_non_tutorial_signed_user(self):
"""Test WEB app without tutorial work as signed in user"""
Fixtures.create()
model.Session.commit()
self.register()
# First time accessing the app should redirect me to the tutorial
res = self.app.get('/app/test-app/newtask', follow_redirects=True)
assert "some help" not in res.data,\
"There should not be a tutorial for the application"
# Second time should give me a task, and not the tutorial
res = self.app.get('/app/test-app/newtask', follow_redirects=True)
assert "some help" not in res.data
示例12: test_23_get_specific_ongoing_task_user
def test_23_get_specific_ongoing_task_user(self):
"""Test WEB get specific ongoing task_id for an app works as an user"""
Fixtures.create()
self.delTaskRuns()
self.register()
self.signin()
app = db.session.query(model.App).first()
task = db.session.query(model.Task).filter(model.App.id == app.id).first()
res = self.app.get("app/%s/task/%s" % (app.short_name, task.id), follow_redirects=True)
assert "TaskPresenter" in res.data, res.data
self.signout()
示例13: test_21_get_specific_ongoing_task_anonymous
def test_21_get_specific_ongoing_task_anonymous(self):
"""Test WEB get specific ongoing task_id for an app works as anonymous"""
Fixtures.create()
self.delTaskRuns()
app = model.Session.query(model.App).first()
task = model.Session.query(model.Task)\
.filter(model.App.id==app.id)\
.first()
res = self.app.get('app/%s/task/%s' % (app.short_name, task.id),
follow_redirects=True)
assert 'TaskPresenter' in res.data, res.data
示例14: test_26_tutorial_signed_user
def test_26_tutorial_signed_user(self):
"""Test WEB tutorials work as signed in user"""
Fixtures.create()
app1 = db.session.query(model.App).get(1)
app1.info = dict(tutorial="some help")
db.session.commit()
self.register()
# First time accessing the app should redirect me to the tutorial
res = self.app.get("/app/test-app/newtask", follow_redirects=True)
assert "some help" in res.data, "There should be some tutorial for the application"
# Second time should give me a task, and not the tutorial
res = self.app.get("/app/test-app/newtask", follow_redirects=True)
assert "some help" not in res.data
示例15: test_06_featured_apps
def test_06_featured_apps(self):
"""Test WEB application index shows featured apps in all the pages works"""
Fixtures.create()
f = model.Featured()
f.app_id=1
db.session.add(f)
db.session.commit()
res = self.app.get('/app', follow_redirects=True)
assert self.html_title("Applications") in res.data, res.data
assert "Applications" in res.data, res.data
assert '/app/test-app' in res.data, res.data
assert '<h2> <i class="icon-star"></i><a href="/app/test-app">My New App</a></h2>' in res.data, res.data