Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_contest_users():
contest1 = mixer.blend('contests.Contest', id=1)
mixer.cycle(5).blend('contests.User', name='Name', contest=contest1)
result = get_contest_users(1)
assert len(result) == 5
for user in result:
assert user.name == 'Name'
with pytest.raises(NoSuchContestError):
get_contest_users(2)
def setUp(self):
super(HardwareAssetResourceTestCase, self).setUp()
# Create some hardware.
mixer.cycle(2).blend(HardwareAsset)
def test_AdminExport_with_unregistered_model_should_raise_ValueError(admin_client):
article = mixer.blend(Article)
mixer.cycle(3).blend(ArticleTag, article=article)
params = {
'ct': ContentType.objects.get_for_model(ArticleTag).pk,
'ids': ','.join(repr(pk) for pk in ArticleTag.objects.values_list('pk', flat=True))
}
url = "{}?{}".format(reverse('export_action:export'), urlencode(params))
with pytest.raises(ValueError):
admin_client.get(url)
def setUp(self):
"""Generate from FreshdeskTicket objects.
"""
super(FreshdeskTicketResourceTestCase, self).setUp()
mixer.cycle(5).blend(
FreshdeskContact, email=random_dbca_email)
mixer.cycle(5).blend(
FreshdeskTicket,
subject=mixer.RANDOM, description_text=mixer.RANDOM, type='Test',
freshdesk_requester=mixer.SELECT,
it_system=mixer.SELECT,
custom_fields={
'support_category': None, 'support_subcategory': None},
)
self.ticket = FreshdeskTicket.objects.first()
def test_admin_action_should_redirect_to_export_view_without_ids_for_large_queries(admin_client):
objects = mixer.cycle(1001).blend(Publication)
ids = [obj.pk for obj in objects[:50]]
data = {
"action": "export_selected_objects",
"_selected_action": ids,
"select_across": ids,
}
url = reverse('admin:tests_publication_changelist')
response = admin_client.post(url, data=data)
assert response.status_code == 302
assert 'session_key' in response.url
session_key = response.url[response.url.index('session_key=') + len('session_key='):]
session_ids = admin_client.session[session_key]
assert session_ids == [obj.pk for obj in objects]
def test_export_with_related_should_return_200(admin_client, output_format):
publications = mixer.cycle(5).blend(Publication)
reporter = mixer.blend(Reporter)
tag = mixer.blend(Tag, name='python')
articles = mixer.cycle(3).blend(Article, reporter=reporter, publications=publications)
for article in articles:
mixer.blend(ArticleTag, tag=tag, article=article)
params = {
'ct': ContentType.objects.get_for_model(Article).pk,
'ids': ','.join(repr(pk) for pk in Article.objects.values_list('pk', flat=True))
}
data = {
'id': 'on',
'headline': 'on',
'reporter__last_name': 'on',
'reporter__email': 'on',
'reporter__id': 'on',
def test_AdminExport_with_related_get_should_return_200(admin_client):
reporter = mixer.blend(Reporter)
mixer.cycle(3).blend(Article, reporter=reporter)
params = {
'related': True,
'model_ct': ContentType.objects.get_for_model(Article).pk,
'field': 'reporter',
'path': 'reporter.first_name',
}
url = "{}?{}".format(reverse('export_action:export'), urlencode(params))
response = admin_client.get(url)
assert response.status_code == 200
def setUp(self):
# Generate some other DepartmentUser objects.
mixer.cycle(8).blend(
DepartmentUser, username=mixer.RANDOM, photo=None, active=True,
email=random_dbca_email, org_unit=None,
cost_centre=None, ad_guid=uuid1, o365_licence=False, in_sync=False)
# Generate some locations.
self.loc1 = mixer.blend(Location, manager=None)
self.loc2 = mixer.blend(Location, manager=None)
# Generate a basic org structure.
# NOTE: don't use mixer to create OrgUnit objects (it breaks MPTT).
self.dept = OrgUnit.objects.create(name='Department 1', unit_type=0, acronym='DEPT', active=True)
self.div1 = OrgUnit.objects.create(
name='Divison 1', unit_type=1, parent=self.dept, location=self.loc1, acronym='DIV1', active=True)
self.branch1 = OrgUnit.objects.create(
name='Branch 1', unit_type=2, parent=self.div1, location=self.loc1, acronym='BRANCH1', active=True)
self.cc1 = CostCentre.objects.create(
name='Cost centre 1', code='001', division=self.div1, org_position=self.div1)
self.div2 = OrgUnit.objects.create(
def handle(self, *args, **options):
publishers = mixer.cycle(15).blend(Publisher)
authors = mixer.cycle(50).blend(Author, age=(i for i in range(20, 70)))
books = mixer.cycle(1000).blend(Book, pubdate=datetime.now(), authors=mixer.RANDOM, publisher=mixer.SELECT)