本文整理汇总了Python中udata.utils.faker.sentence函数的典型用法代码示例。如果您正苦于以下问题:Python sentence函数的具体用法?Python sentence怎么用?Python sentence使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sentence函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_list_issues_for
def test_list_issues_for(self):
dataset = Dataset.objects.create(title='Test dataset')
issues = []
for i in range(3):
user = UserFactory()
message = Message(content=faker.sentence(), posted_by=user)
issue = Issue.objects.create(
subject=dataset,
user=user,
title='test issue {}'.format(i),
discussion=[message]
)
issues.append(issue)
# Creating a closed issue that shouldn't show up in response.
user = UserFactory()
other_dataset = Dataset.objects.create(title='Other Test dataset')
message = Message(content=faker.sentence(), posted_by=user)
issue = Issue.objects.create(
subject=other_dataset,
user=user,
title='test issue {}'.format(i),
discussion=[message]
)
kwargs = {'for': str(dataset.id)}
response = self.get(url_for('api.issues', **kwargs))
self.assert200(response)
self.assertEqual(len(response.json['data']), len(issues))
示例2: test_list_discussions_closed_filter
def test_list_discussions_closed_filter(self):
dataset = Dataset.objects.create(title='Test dataset')
open_discussions = []
closed_discussions = []
for i in range(2):
user = UserFactory()
message = Message(content=faker.sentence(), posted_by=user)
discussion = Discussion.objects.create(
subject=dataset,
user=user,
title='test discussion {}'.format(i),
discussion=[message]
)
open_discussions.append(discussion)
for i in range(3):
user = UserFactory()
message = Message(content=faker.sentence(), posted_by=user)
discussion = Discussion.objects.create(
subject=dataset,
user=user,
title='test discussion {}'.format(i),
discussion=[message],
closed=datetime.now(),
closed_by=user
)
closed_discussions.append(discussion)
response = self.get(url_for('api.discussions', closed=True))
self.assert200(response)
self.assertEqual(len(response.json['data']), len(closed_discussions))
for discussion in response.json['data']:
self.assertIsNotNone(discussion['closed'])
示例3: test_list_discussions_for
def test_list_discussions_for(self):
dataset = DatasetFactory()
discussions = []
for i in range(3):
user = UserFactory()
message = Message(content=faker.sentence(), posted_by=user)
discussion = Discussion.objects.create(
subject=dataset,
user=user,
title='test discussion {}'.format(i),
discussion=[message]
)
discussions.append(discussion)
user = UserFactory()
message = Message(content=faker.sentence(), posted_by=user)
Discussion.objects.create(
subject=DatasetFactory(),
user=user,
title='test discussion {}'.format(i),
discussion=[message]
)
kwargs = {'for': str(dataset.id)}
response = self.get(url_for('api.discussions', **kwargs))
self.assert200(response)
self.assertEqual(len(response.json['data']), len(discussions))
示例4: test_closed_issue_mail
def test_closed_issue_mail(self):
owner = UserFactory()
poster = UserFactory()
commenter = UserFactory()
message = Message(content=faker.sentence(), posted_by=poster)
second_message = Message(content=faker.sentence(), posted_by=commenter)
closing_message = Message(content=faker.sentence(), posted_by=owner)
issue = Issue.objects.create(
subject=DatasetFactory(owner=owner),
user=poster,
title=faker.sentence(),
discussion=[message, second_message, closing_message]
)
# issue = IssueFactory()
with capture_mails() as mails:
notify_issue_closed(issue, message=closing_message)
# Should have sent one mail to each participant
# and no mail to the closer
expected_recipients = (poster.email, commenter.email)
self.assertEqual(len(mails), len(expected_recipients))
for mail in mails:
self.assertIn(mail.recipients[0], expected_recipients)
self.assertNotIn(owner.email, mail.recipients)
示例5: test_list_issues
def test_list_issues(self):
dataset = Dataset.objects.create(title='Test dataset')
open_issues = []
for i in range(3):
user = UserFactory()
message = Message(content=faker.sentence(), posted_by=user)
issue = Issue.objects.create(
subject=dataset,
user=user,
title='test issue {}'.format(i),
discussion=[message]
)
open_issues.append(issue)
# Creating a closed issue that shouldn't show up in response.
user = UserFactory()
message = Message(content=faker.sentence(), posted_by=user)
closed_issues = [Issue.objects.create(
subject=dataset,
user=user,
title='test issue {}'.format(i),
discussion=[message],
closed=datetime.now(),
closed_by=user
)]
response = self.get(url_for('api.issues'))
self.assert200(response)
expected_length = len(open_issues + closed_issues)
self.assertEqual(len(response.json['data']), expected_length)
示例6: test_blogpost_with_first_image_as_thumbnail_as_src_set
def test_blogpost_with_first_image_as_thumbnail_as_src_set(self, blogpost, tpl):
title = faker.sentence()
post_url = faker.uri()
image_url = faker.image_url()
summary = faker.sentence()
tz = pytz.timezone(faker.timezone())
publish_date = faker.date_time(tzinfo=tz)
srcset = ', '.join(
' '.join((faker.image_url(width=w), '{0}w'.format(w)))
for w in ('1200', '1024', '300')
)
sizes = "(max-width: 1200px) 100vw, 1200px"
content = tpl.format(image_url, srcset, sizes)
feed = self.feed('Some blog', title, content, post_url,
published=publish_date,
summary=summary)
post = blogpost(feed)
assert post['title'] == title
assert post['link'] == post_url
assert post['summary'] == summary
assert_equal_dates(post['date'], publish_date)
assert post['image_url'] == image_url
assert post['srcset'] == srcset
assert post['sizes'] == sizes
示例7: feed
def feed(self, feed_title, title, content, url, published=None, summary=None,
enclosure=None, media_thumbnail=None):
feed = FeedGenerator()
feed.title(feed_title)
feed.description(faker.sentence())
feed.link({'href': WP_FEED_URL})
entry = feed.add_entry()
entry.title(title)
entry.link({'href': url})
entry.author(name=faker.name())
entry.content(content, type="cdata")
if summary:
entry.description(summary)
if enclosure:
entry.enclosure(url=enclosure['url'],
type=enclosure['type'],
length=str(faker.pyint()))
if media_thumbnail:
feed.load_extension('media')
entry.media.thumbnail({'url': media_thumbnail})
tz = pytz.timezone(faker.timezone())
published = published or faker.date_time(tzinfo=tz)
entry.published(published)
entry.updated(faker.date_time_between(start_date=published, tzinfo=tz))
return feed.rss_str().decode('utf8')
示例8: test_prioritize_title_over_alternate_title
def test_prioritize_title_over_alternate_title(self):
title = faker.sentence()
license = LicenseFactory(title=title)
LicenseFactory(alternate_titles=[title])
found = License.guess(title)
assert isinstance(found, License)
assert license.id == found.id
示例9: test_update_job_change_type
def test_update_job_change_type(self):
@job('a-job')
def test_job():
pass
task = PeriodicTask.objects.create(
name=faker.name(),
description=faker.sentence(),
task='a-job',
crontab=PeriodicTask.Crontab(minute='5')
)
self.login(AdminFactory())
response = self.put(url_for('api.job', id=task.id), {
'name': task.name,
'description': task.description,
'task': task.task,
'interval': {
'every': 5,
'period': 'minutes',
}
})
self.assert200(response)
self.assertEqual(response.json['id'], str(task.id))
self.assertEqual(response.json['name'], task.name)
self.assertEqual(response.json['task'], task.task)
self.assertEqual(response.json['description'], task.description)
self.assertEqual(response.json['interval']['every'], 5)
self.assertEqual(response.json['interval']['period'], 'minutes')
self.assertIsNone(response.json['crontab'])
示例10: test_update_job
def test_update_job(self):
@job('a-job')
def test_job():
pass
task = PeriodicTask.objects.create(
name=faker.name(),
description=faker.sentence(),
task='a-job',
crontab=PeriodicTask.Crontab(minute='5')
)
self.login(AdminFactory())
response = self.put(url_for('api.job', id=task.id), {
'name': task.name,
'description': 'New description',
'task': task.task,
'crontab': task.crontab.to_json()
})
self.assert200(response)
self.assertEqual(response.json['id'], str(task.id))
self.assertEqual(response.json['name'], task.name)
self.assertEqual(response.json['task'], task.task)
self.assertEqual(response.json['description'], 'New description')
self.assertIsNotNone(response.json['crontab'])
self.assertIsNone(response.json['interval'])
示例11: test_request_transfer_to_self
def test_request_transfer_to_self(self):
user = UserFactory()
dataset = VisibleDatasetFactory(owner=user)
comment = faker.sentence()
login_user(user)
with pytest.raises(ValueError):
self.assert_transfer_started(dataset, user, user, comment)
示例12: test_new_issue_mail
def test_new_issue_mail(self):
user = UserFactory()
owner = UserFactory()
message = Message(content=faker.sentence(), posted_by=user)
issue = Issue.objects.create(
subject=DatasetFactory(owner=owner),
user=user,
title=faker.sentence(),
discussion=[message]
)
with capture_mails() as mails:
notify_new_issue(issue)
# Should have sent one mail to the owner
self.assertEqual(len(mails), 1)
self.assertEqual(mails[0].recipients[0], owner.email)
示例13: test_request_transfer_user_to_organization
def test_request_transfer_user_to_organization(self):
user = UserFactory()
dataset = VisibleDatasetFactory(owner=user)
recipient = OrganizationFactory()
comment = faker.sentence()
login_user(user)
self.assert_transfer_started(dataset, user, recipient, comment)
示例14: test_request_transfer_not_authorized_not_owner
def test_request_transfer_not_authorized_not_owner(self):
user = UserFactory()
dataset = VisibleDatasetFactory(owner=UserFactory())
recipient = UserFactory()
comment = faker.sentence()
login_user(user)
with pytest.raises(PermissionDenied):
request_transfer(dataset, recipient, comment)
示例15: test_minimal_from_multiple
def test_minimal_from_multiple(self):
node = BNode()
g = Graph()
title = faker.sentence()
g.add((node, RDF.type, DCAT.Dataset))
g.add((node, DCT.title, Literal(title)))
for i in range(3):
other = BNode()
g.add((other, RDF.type, DCAT.Dataset))
g.add((other, DCT.title, Literal(faker.sentence())))
dataset = dataset_from_rdf(g, node=node)
dataset.validate()
assert isinstance(dataset, Dataset)
assert dataset.title == title