本文整理汇总了Python中app.models.project.Project.save方法的典型用法代码示例。如果您正苦于以下问题:Python Project.save方法的具体用法?Python Project.save怎么用?Python Project.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.project.Project
的用法示例。
在下文中一共展示了Project.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_process_processed_files
# 需要导入模块: from app.models.project import Project [as 别名]
# 或者: from app.models.project.Project import save [as 别名]
def test_process_processed_files(self):
"""Make sure that a project that's being processed or already
processed can't be processed again.
"""
project1 = Project(name="foo", path="/test-path",
status=Project.STATUS_PREPROCESSING)
rel = self.user.add_project(project1, role=ProjectsUsers.ROLE_ADMIN)
document_file = DocumentFile(path="foo/foo.xml")
structure_file = StructureFile(path="foo/foo.json")
project1.document_files = [document_file]
project1.structure_files = [structure_file]
project1.save()
data = {
"struc_id": structure_file.id,
}
result = self.client.post(application.config["PROCESS_ROUTE"] + str(project1.id), data=data)
assert '"status": "OK"' not in result.data
project1.status = Project.STATUS_DONE
project1.save()
result = self.client.post(application.config["PROCESS_ROUTE"] + str(project1.id), data=data)
assert '"status": "OK"' not in result.data
示例2: test_logs
# 需要导入模块: from app.models.project import Project [as 别名]
# 或者: from app.models.project.Project import save [as 别名]
def test_logs(self):
"""Test to make sure that logs are being displayed.
"""
project1 = Project(name="foo", path="/test-path",
user=self.user)
project2 = Project(name="foob", path="/foobar",
user=self.user)
logs = [WarningLog(log_item="a", item_value="a", project=project1),
InfoLog(log_item="b", item_value="b", project=project1),
ErrorLog(log_item="c", item_value="c", project=project1)]
project1.document_files = [DocumentFile(path="foo")]
project2.document_files = [DocumentFile(path="foo")]
project1.save()
project2.save()
result = self.client.get("/projects/1")
assert "alert alert-warning" in result.data
assert "alert alert-info" in result.data
assert "alert alert-danger" in result.data
assert "<em>a</em>: a" in result.data
assert "<em>b</em>: b" in result.data
assert "<em>c</em>: c" in result.data
示例3: test_project_show_bad_process
# 需要导入模块: from app.models.project import Project [as 别名]
# 或者: from app.models.project.Project import save [as 别名]
def test_project_show_bad_process(self, mock_process_files):
"""Test processing an unprocessable group of files.
"""
project = Project(name="test", user=self.user, path="/foo")
project.save()
document_file1 = DocumentFile(projects=[project],
path="/test-path/1.xml")
document_file2 = DocumentFile(projects=[project],
path="/test-path/2.xml")
document_file1.save()
document_file2.save()
result = self.client.post("/projects/1", data={
"process-submitted": "true",
"action": "0",
"process-selection": ["1", "2"]
})
assert "must include exactly one" in result.data
structure_file = StructureFile(project=project, path="/foo/bar.json")
structure_file.save()
result = self.client.post("/projects/1", data={
"process-submitted": "true",
"action": "0",
"process-structure_file": [str(structure_file.id)]
})
assert "at least one document" in result.data.lower()
示例4: test_projects
# 需要导入模块: from app.models.project import Project [as 别名]
# 或者: from app.models.project.Project import save [as 别名]
def test_projects(self):
"""Test the projects view with a project present.
"""
new_project = Project(name="test", user=self.user)
new_project.save()
result = self.client.get("/projects/")
assert "/projects/1" in result.data
示例5: test_project_show_delete
# 需要导入模块: from app.models.project import Project [as 别名]
# 或者: from app.models.project.Project import save [as 别名]
def test_project_show_delete(self, mock_os):
"""Test file deletion.
"""
mock_os.path.isdir.return_value = False
project = Project(name="test")
db.session.add(project)
self.user.add_project(project, role=ProjectsUsers.ROLE_ADMIN)
project.save()
pid = str(project.id)
document_file1 = DocumentFile(projects=[project],
path="/test-path/1.xml")
document_file2 = DocumentFile(projects=[project],
path="/test-path/2.xml")
db.session.add_all([document_file1, document_file2])
document_file1.save()
document_file2.save()
result = self.client.post(application.config["DELETE_ROUTE"], data={
"project_id": pid,
"obj_type": "doc",
"obj_id": document_file1.id
})
assert '"obj_type": "doc",' in result.data
assert '"obj_id": %s' % document_file1.id in result.data
mock_os.remove.assert_any_call("/test-path/1.xml")
# mock_os.remove.assert_any_call("/test-path/2.xml")
assert mock_os.remove.call_count == 1
示例6: test_project_show_upload
# 需要导入模块: from app.models.project import Project [as 别名]
# 或者: from app.models.project.Project import save [as 别名]
def test_project_show_upload(self):
"""Try uploading a file to the project_show view.
"""
project = Project(name="test")
db.session.add(project)
self.user.add_project(project, role=ProjectsUsers.ROLE_ADMIN)
project.save()
pid = str(project.id)
upload_dir = tempfile.mkdtemp()
application.config["UPLOAD_DIR"] = upload_dir
os.makedirs(os.path.join(upload_dir, pid))
result = self.client.post(application.config["PROJECT_ROUTE"] + pid + "/upload", data={
"uploaded_file": (StringIO("<thing>Test file</thing>"), "test.xml")
})
data = loads(result.data)
# validation error contains "The file test.xml is not well-formed XML."
assert os.path.exists(os.path.join(upload_dir, pid, "test.xml"))
assert data["files"][0]["type"] == "doc"
assert data["files"][0]["filename"] == "test.xml"
uploaded_file = open(os.path.join(upload_dir, pid, "test.xml"))
assert uploaded_file.read() == "<thing>Test file</thing>"
示例7: test_no_project_show
# 需要导入模块: from app.models.project import Project [as 别名]
# 或者: from app.models.project.Project import save [as 别名]
def test_no_project_show(self):
"""Make sure project_show says that there are no files.
"""
project = Project(name="test", users=[self.user])
project.save()
result = self.client.get(application.config["PROJECT_ROUTE"] + str(project.id))
assert "test" in result.data
assert "There are no Documents in this project." in result.data
示例8: test_no_project_show
# 需要导入模块: from app.models.project import Project [as 别名]
# 或者: from app.models.project.Project import save [as 别名]
def test_no_project_show(self):
"""Make sure project_show says that there are no files.
"""
project = Project(name="test", user=self.user)
project.save()
result = self.client.get("/projects/1")
assert "test" in result.data
assert "There are no files in this project" in result.data
示例9: AuthTests
# 需要导入模块: from app.models.project import Project [as 别名]
# 或者: from app.models.project.Project import save [as 别名]
class AuthTests(unittest.TestCase):
"""Make sure that users can only see the pages and such that they
should be seeing.
"""
#TODO: can we make this a classmethod without SQLAlchemy complaining?
def setUp(self):
database.clean()
self.client = application.test_client()
self.user1 = user_datastore.create_user(email="[email protected]",
password="password")
self.user2 = user_datastore.create_user(email="[email protected]",
password="password")
db.session.commit()
with self.client.session_transaction() as sess:
sess["user_id"] = self.user1.get_id()
sess["_fresh"] = True
self.project = Project(name="Bars project", user=self.user2)
self.project.save()
file_handle, file_path = tempfile.mkstemp()
file_handle = os.fdopen(file_handle, "r+")
file_handle.write("foobar")
self.file_path = os.path.join(file_path)
self.document_file = DocumentFile(projects=[self.project],
path=self.file_path)
self.document_file.save()
def test_list_projects(self):
"""Test to make sure that bar's projects aren't listed for foo.
"""
result = self.client.get("/projects/")
assert "Bars project" not in result.data
def test_view_project(self):
"""Test to make sure that foo can't see bar's project.
"""
result = self.client.get("/projects/" + str(self.project.id))
assert "Bars project" not in result.data
def test_view_document(self):
"""Test to make sure that foo can't see bar's file.
"""
result = self.client.get("/projects/" + str(self.project.id) +
"/documents/" + str(self.document_file.id))
assert "/uploads/" + str(self.document_file.id) not in result.data
def test_get_document(self):
"""Test to make sure that foo can't get bar's file.
"""
result = self.client.get("/uploads/" + str(self.document_file.id))
with open(self.file_path) as test_file:
assert result.data is not test_file.read()
示例10: setUpModule
# 需要导入模块: from app.models.project import Project [as 别名]
# 或者: from app.models.project.Project import save [as 别名]
def setUpModule():
global project
project = Project()
project.save()
global mock_project_logger
with mock.patch("app.preprocessor.collectionprocessor.StringProcessor",
autospec=True), mock.patch("app.preprocessor.collectionprocessor.logger.ProjectLogger",
autospec=True):
global colproc
colproc = collectionprocessor.CollectionProcessor(project.id)
示例11: test_log
# 需要导入模块: from app.models.project import Project [as 别名]
# 或者: from app.models.project.Project import save [as 别名]
def test_log(self):
"""Test the log() method. These tests assume that get() works.
"""
project = Project()
project.save()
logger.log(project, "logtest", "true", logger.REPLACE)
self.failUnless(logger.get(project, "logtest") == "true")
logger.log(project, "logtest", "false", logger.UPDATE)
self.failUnless(logger.get(project, "logtest") == "true [false] ")
示例12: test_projects_duplicate_create
# 需要导入模块: from app.models.project import Project [as 别名]
# 或者: from app.models.project.Project import save [as 别名]
def test_projects_duplicate_create(self):
"""Test creating a project with the same name as another user's.
"""
project = Project(name="test", users=[User()])
project.save()
result = self.client.post("/projects/", data={
"create-submitted": "true",
"name": "test"
})
assert "already exists" not in result.data
示例13: test_projects_bad_create
# 需要导入模块: from app.models.project import Project [as 别名]
# 或者: from app.models.project.Project import save [as 别名]
def test_projects_bad_create(self):
"""Test creating an existing project.
"""
project = Project(name="test", user=self.user)
project.save()
result = self.client.post("/projects/", data={
"create-submitted": "true",
"create-name": "test"
})
assert "already exists" in result.data
示例14: test_get
# 需要导入模块: from app.models.project import Project [as 别名]
# 或者: from app.models.project.Project import save [as 别名]
def test_get(self):
"""Test the get() method.
"""
project = Project()
project.save()
entry = Log(project=project, item_value="true", log_item="logtest")
entry.save()
self.failUnless(logger.get(project, "logtest") ==
Log.query.filter(Log.log_item == "logtest").all()[0].item_value)
self.failUnless(logger.get(project, "fakerandomname") == "")
示例15: test_projects_bad_process
# 需要导入模块: from app.models.project import Project [as 别名]
# 或者: from app.models.project.Project import save [as 别名]
def test_projects_bad_process(self, mock_process_files):
"""Test processing an unprocessable project.
"""
project1 = Project(name="test1", user=self.user)
project1.save()
result = self.client.post("/projects/", data={
"action": "0",
"process-submitted": "true",
"process-selection": ["1"]
})
assert "include exactly one json file" in result.data