本文整理汇总了Python中comport.department.models.Extractor.create方法的典型用法代码示例。如果您正苦于以下问题:Python Extractor.create方法的具体用法?Python Extractor.create怎么用?Python Extractor.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类comport.department.models.Extractor
的用法示例。
在下文中一共展示了Extractor.create方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_extractor_post_triggers_slack_notification
# 需要导入模块: from comport.department.models import Extractor [as 别名]
# 或者: from comport.department.models.Extractor import create [as 别名]
def test_extractor_post_triggers_slack_notification(self, testapp):
''' A valid heartbeat post triggers a Slack notification
'''
# set up the extractor
department = Department.create(name="Good Police Department", short_name="GPD", load_defaults=False)
Extractor.create(username='extractor', email='[email protected]', password="password", department_id=department.id, next_month=10, next_year=2006)
# set the correct authorization
testapp.authorization = ('Basic', ('extractor', 'password'))
# set a fake Slack webhook URL
fake_webhook_url = 'http://webhook.example.com/'
current_app.config['SLACK_WEBHOOK_URL'] = fake_webhook_url
# create a mock to receive POST requests to that URL
responses.add(responses.POST, fake_webhook_url, status=200)
# post a sample json object to the heartbeat URL
testapp.post_json("/data/heartbeat", params={"heartbeat": "heartbeat"})
# test the captured post payload
post_body = json.loads(responses.calls[0].request.body)
assert 'Comport Pinged by Extractor!' in post_body['text']
# delete the fake Slack webhook URL
del(current_app.config['SLACK_WEBHOOK_URL'])
# reset the mock
responses.reset()
示例2: test_reject_extractor_post_with_wrong_password
# 需要导入模块: from comport.department.models import Extractor [as 别名]
# 或者: from comport.department.models.Extractor import create [as 别名]
def test_reject_extractor_post_with_wrong_password(self, testapp):
''' An extractor login with the wrong password is rejected.
'''
Extractor.create(username='extractor', email='[email protected]', password="password")
testapp.authorization = ('Basic', ('extractor', 'drowssap'))
response = testapp.post("/data/heartbeat", expect_errors=True)
assert response.status_code == 401
assert response.text == 'Extractor authorization failed!'
示例3: test_valid_login_replies_with_request
# 需要导入模块: from comport.department.models import Extractor [as 别名]
# 或者: from comport.department.models.Extractor import create [as 别名]
def test_valid_login_replies_with_request(self, testapp):
right_department = Department.create(name="good2", load_defaults=False)
Extractor.create(username="good4", email="[email protected]", password="valid", department_id=right_department.id)
testapp.authorization = ("Basic", ("good4", "valid"))
res = testapp.post_json("/data/heartbeat", params={"json": "yep"}, expect_errors=True)
assert res.status_code == 200
示例4: test_extractors_are_users
# 需要导入模块: from comport.department.models import Extractor [as 别名]
# 或者: from comport.department.models.Extractor import create [as 别名]
def test_extractors_are_users(self):
department = DepartmentFactory()
department.save()
extractor = Extractor.create(username='foobarbaz', email='[email protected]', department_id=department.id)
assert extractor.department_id == department.id
示例5: test_successful_extractor_post
# 需要导入模块: from comport.department.models import Extractor [as 别名]
# 或者: from comport.department.models.Extractor import create [as 别名]
def test_successful_extractor_post(self, testapp):
''' Send a valid heartbeat post, get a valid response.
'''
# set up the extractor
department = Department.create(name="Good Police Department", short_name="GPD", load_defaults=False)
Extractor.create(username='extractor', email='[email protected]', password="password", department_id=department.id, next_month=10, next_year=2006)
# set the correct authorization
testapp.authorization = ('Basic', ('extractor', 'password'))
# post a sample json object to the heartbeat URL
response = testapp.post_json("/data/heartbeat", params={"heartbeat": "heartbeat"})
# assert that we got the expected response
assert response.status_code == 200
assert response.json_body['nextMonth'] == 10
assert response.json_body['nextYear'] == 2006
assert response.json_body['received'] == {'heartbeat': 'heartbeat'}
示例6: test_extractors_are_users
# 需要导入模块: from comport.department.models import Extractor [as 别名]
# 或者: from comport.department.models.Extractor import create [as 别名]
def test_extractors_are_users(self):
department = DepartmentFactory()
department.save()
extractor = Extractor.create(username='foobarbaz', email='[email protected]')
extractor.departments.append(department)
extractor.save()
assert extractor.first_department().id == department.id
示例7: test_bad_extractor_password_is_a_401
# 需要导入模块: from comport.department.models import Extractor [as 别名]
# 或者: from comport.department.models.Extractor import create [as 别名]
def test_bad_extractor_password_is_a_401(self, testapp):
Extractor.create(username="good", email="[email protected]", password="valid")
testapp.authorization = ("Basic", ("good", "fake"))
res = testapp.post("/data/heartbeat", expect_errors=True)
assert res.status_code == 401