本文整理汇总了Python中tests.factories.ProjectFactory.add_file方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectFactory.add_file方法的具体用法?Python ProjectFactory.add_file怎么用?Python ProjectFactory.add_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.ProjectFactory
的用法示例。
在下文中一共展示了ProjectFactory.add_file方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestUtils
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_file [as 别名]
class TestUtils(OsfTestCase):
def setUp(self):
OsfTestCase.setUp(self)
self.project = ProjectFactory()
def test_prepare_file_name(self):
name, content, content_type, size = prepare_file(make_file_like(
name='file')
)
assert_equal(name, 'file')
def test_prepare_file_name_missing(self):
name, content, content_type, size = prepare_file(
make_file_like(name='ü')
)
assert_equal(name, settings.MISSING_FILE_NAME)
def test_get_current_file_version(self):
self.project.add_file(Auth(self.project.creator), 'foo', 'somecontent', 128, 'rst')
result = get_latest_version_number('foo', node=self.project)
assert_equal(result, 0)
# Update the file
self.project.add_file(Auth(self.project.creator), 'foo', 'newcontent', 128, 'rst')
result = get_latest_version_number('foo', node=self.project)
assert_equal(result, 1)
def test_get_current_file_raises_error_when_file_not_found(self):
with assert_raises(FileNotFoundError):
get_latest_version_number('notfound', node=self.project)
示例2: setUp
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_file [as 别名]
def setUp(self):
super(TestMigrateFiles, self).setUp()
self.clear()
self.nodes = []
for idx in range(3):
node = ProjectFactory()
node.add_file(
Auth(user=node.creator),
'name',
'contents',
len('contents'),
'text/plain',
)
self.nodes.append(node)
self.nodes[-1].files_versions = {}
self.nodes[-1].save()
# Sanity check
assert_in('name', self.nodes[-1].files_current)
assert_not_in('name', self.nodes[-1].files_versions)
示例3: test_sees_log_events_on_watched_projects
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_file [as 别名]
def test_sees_log_events_on_watched_projects(self):
# Another user has a public project
u2 = UserFactory(username='[email protected]', fullname='Bono')
key = ApiKeyFactory()
u2.api_keys.append(key)
u2.save()
project = ProjectFactory(creator=u2, is_public=True)
project.add_contributor(u2)
auth = Auth(user=u2, api_key=key)
# A file was added to the project
project.add_file(auth=auth, file_name='test.html',
content='123', size=2, content_type='text/html')
project.save()
# User watches the project
watch_config = WatchConfigFactory(node=project)
self.user.watch(watch_config)
self.user.save()
# Goes to her dashboard, already logged in
res = self.app.get('/dashboard/', auth=self.auth, auto_follow=True)
# Sees logs for the watched project
assert_in('Watched Projects', res) # Watched Projects header
# The log action is in the feed
assert_in('added file test.html', res)
assert_in(project.title, res)
示例4: TestMigrateFiles
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_file [as 别名]
class TestMigrateFiles(OsfTestCase):
def setUp(self):
super(TestMigrateFiles, self).setUp()
self.project = ProjectFactory()
self.user = self.project.creator
self.auth_obj = Auth(user=self.user)
self.project.delete_addon('osfstorage', auth=None, _force=True)
for idx in range(5):
content = 'i want {0} pizzas'.format(idx)
self.project.add_file(
auth=self.auth_obj,
file_name='pizza.md',
content=content,
size=len(content),
content_type='text/markdown',
)
def check_record(self, record):
assert_true(record)
assert_equal(len(record.versions), 5)
for idx, version in enumerate(record.versions):
assert_false(version.pending)
expected = 'i want {0} pizzas'.format(idx)
download_url = utils.get_waterbutler_download_url(idx + 1, version, record)
resp = requests.get(download_url)
assert_equal(expected, resp.content)
def test_migrate(self):
main(dry_run=False)
node_settings = self.project.get_addon('osfstorage')
assert_true(node_settings)
record = model.OsfStorageFileRecord.find_by_path('pizza.md', node_settings)
self.check_record(record)
# Test idempotence of migration
main(dry_run=False)
assert_equal(len(record.versions), 5)
def test_migrate_incomplete(self):
node_settings = self.project.get_or_add_addon('osfstorage', auth=None, log=False)
record = model.OsfStorageFileRecord.get_or_create('pizza.md', node_settings)
node_file = NodeFile.load(self.project.files_versions['pizza_md'][0])
content, _ = self.project.read_file_object(node_file)
file_pointer = StringIO(content)
hash_str = scripts_settings.UPLOAD_PRIMARY_HASH(content).hexdigest()
record.create_pending_version(node_file.uploader, hash_str)
main(dry_run=False)
def test_migrate_fork(self):
fork = self.project.fork_node(auth=self.auth_obj)
main(dry_run=False)
node_settings = self.project.get_addon('osfstorage')
record = model.OsfStorageFileRecord.find_by_path('pizza.md', node_settings)
self.check_record(record)
fork_node_settings = fork.get_addon('osfstorage')
fork_record = model.OsfStorageFileRecord.find_by_path('pizza.md', fork_node_settings)
self.check_record(fork_record)
def test_migrate_corrupt_fork_repo_deleted(self):
fork = self.project.fork_node(auth=self.auth_obj)
fork_repo = os.path.join(settings.UPLOADS_PATH, fork._id)
shutil.rmtree(fork_repo)
main(dry_run=False)
node_settings = self.project.get_addon('osfstorage')
record = model.OsfStorageFileRecord.find_by_path('pizza.md', node_settings)
self.check_record(record)
fork_node_settings = fork.get_addon('osfstorage')
fork_record = model.OsfStorageFileRecord.find_by_path('pizza.md', fork_node_settings)
self.check_record(fork_record)
def test_migrate_corrupt_fork_git_dir_deleted(self):
fork = self.project.fork_node(auth=self.auth_obj)
fork_git_dir = os.path.join(settings.UPLOADS_PATH, fork._id, '.git')
shutil.rmtree(fork_git_dir)
main(dry_run=False)
node_settings = self.project.get_addon('osfstorage')
record = model.OsfStorageFileRecord.find_by_path('pizza.md', node_settings)
self.check_record(record)
fork_node_settings = fork.get_addon('osfstorage')
fork_record = model.OsfStorageFileRecord.find_by_path('pizza.md', fork_node_settings)
self.check_record(fork_record)