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_uniqueness(self):
annotation1 = mixer.blend('server.SequenceAnnotation')
with self.assertRaises(IntegrityError):
mixer.blend('server.SequenceAnnotation',
document=annotation1.document,
user=annotation1.user,
label=annotation1.label,
start_offset=annotation1.start_offset,
end_offset=annotation1.end_offset)
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(
name='Divison 2', unit_type=1, parent=self.dept, location=self.loc2, acronym='DIV2', active=True)
self.branch2 = OrgUnit.objects.create(
name='Branch 2', unit_type=2, parent=self.div2, location=self.loc2, acronym='BRANCH2', active=True)
self.cc2 = CostCentre.objects.create(
name='Cost centre 2', code='002', division=self.div2, org_position=self.div2)
# Give each of the org units some members.
def setUp(self):
# Create User and linked DepartmentUser objects.
self.du1 = mixer.blend(DepartmentUser, photo=None)
self.user1 = User.objects.create_user(
username=self.du1.username, email=self.du1.email)
self.user1.is_superuser = True
self.user1.set_password('pass')
self.user1.save()
# Log in user1 by default.
self.client.login(username=self.user1.username, password='pass')
self.du2 = mixer.blend(DepartmentUser, photo=None)
self.user2 = User.objects.create_user(
username=self.du2.username, email=self.du2.email)
self.user2.set_password('pass')
self.user2.save()
self.itsystem = mixer.blend(ITSystem, system_id='S001')
# Create User and linked DepartmentUser objects.
self.du1 = mixer.blend(DepartmentUser, username=mixer.RANDOM, photo=None)
self.user1 = User.objects.create_user(
username=self.du1.username, email=self.du1.email)
self.user1.is_superuser = True
self.user1.set_password('pass')
self.user1.save()
# Log in user1 by default.
self.client.login(username=self.user1.username, password='pass')
self.du2 = mixer.blend(DepartmentUser, username=mixer.RANDOM, photo=None)
self.user2 = User.objects.create_user(
username=self.du2.username, email=self.du2.email)
self.user2.set_password('pass')
self.user2.save()
self.itsystem = mixer.blend(ITSystem)
def test_options(self):
self.assertTrue('OPTIONS' in ArticleResource._meta.allowed_methods)
uri = self.reverse('author-test-book-article', book=self.book.pk)
response = self.client.options(uri, data=dict(author=self.author.pk))
self.assertContains(response, 'OK')
author = mixer.blend('main.author')
response = self.client.options(uri, data=dict(author=author.pk))
self.assertContains(response, 'OK')
def setUp(self):
super(RegistersAdminTestCase, self).setUp()
# Create an admin user.
self.admin_user = mixer.blend(User, username='admin', is_superuser=True, is_staff=True)
self.admin_user.set_password('pass')
self.admin_user.save()
# Create some Computers
self.com1 = mixer.blend(Computer)
self.com2 = mixer.blend(Computer)
# Create some ITSystemHardware objects
self.itsys1 = mixer.blend(ITSystemHardware, computer=self.com1, production=True)
self.itsys2 = mixer.blend(ITSystemHardware, computer=self.com2)
# Attach ITSystemHardware to ITSystem objects.
self.it1.hardwares.add(self.itsys1)
self.it2.hardwares.add(self.itsys2)
# Log in as admin user by default
self.client.login(username='admin', password='pass')
def setUp(self):
super(RegistersAdminTestCase, self).setUp()
# Create an admin user.
self.admin_user = mixer.blend(User, username='admin', is_superuser=True, is_staff=True)
self.admin_user.set_password('pass')
self.admin_user.save()
# Create some Computers
self.com1 = mixer.blend(Computer)
self.com2 = mixer.blend(Computer)
# Create some ITSystemHardware objects
self.itsys1 = mixer.blend(ITSystemHardware, computer=self.com1, production=True)
self.itsys2 = mixer.blend(ITSystemHardware, computer=self.com2)
# Attach ITSystemHardware to ITSystem objects.
self.it1.hardwares.add(self.itsys1)
self.it2.hardwares.add(self.itsys2)
# Log in as admin user by default
self.client.login(username='admin', password='pass')
def setUp(self) -> None:
teacher = mixer.blend(Teacher)
teacher.username = '198500038'
teacher.password = make_encode('198500038')
teacher.save()
self.log_data = {
'username': teacher.username,
'password': teacher.username
}
data = {
'username': '198500038',
'password': '198500038'
}
url = ""
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'login.html')
def test_list(self):
"""Test the LocationResource list response
"""
loc_inactive = mixer.blend(Location, manager=None, active=False)
url = '/api/locations/'
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
# Response should not contain the inactive Location.
self.assertNotContains(response, loc_inactive.name)