Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions unittests/dojo_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def add_product_jira(self, data, expect_redirect_to=None, expect_200=False):
product = Product.objects.get(id=response.url.split('/')[-2])
except:
raise ValueError('error parsing id from redirect uri: ' + response.url)
self.assertTrue(response.url == (expect_redirect_to % product.id))
self.assertEqual(response.url, (expect_redirect_to % product.id))
else:
self.assertEqual(response.status_code, 200)

Expand Down Expand Up @@ -401,12 +401,12 @@ def assert_jira_issue_in_epic(self, finding, engagement, issue_in_epic=True):
response = jira._session.get(url).json().get('fields', {})
epic_link = response.get(epic_link_field, None)
if epic_id is None and epic_link is None or issue_in_epic:
self.assertTrue(epic_id == epic_link)
self.assertEqual(epic_id, epic_link)
else:
self.assertTrue(epic_id != epic_link)
self.assertNotEqual(epic_id, epic_link)

def assert_jira_updated_change(self, old, new):
self.assertTrue(old != new)
self.assertNotEqual(old, new)

def get_latest_model(self, model):
return model.objects.order_by('id').last()
Expand Down
4 changes: 2 additions & 2 deletions unittests/test_apiv2_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_query_metadata(self):

def test_query_product_endpoint(self):
r = self.client.get(reverse('product-detail', args=(1,)))
self.assertTrue(dict(name='foo', value='bar') in r.json()['product_meta'])
self.assertIn(dict(name='foo', value='bar'), r.json()['product_meta'])

def test_delete(self):
r = self.client.delete(reverse('metadata-detail', args=(self.mid,)))
Expand All @@ -45,7 +45,7 @@ def test_delete(self):
self.assertEqual(r.status_code, 404)

r = self.client.get(reverse('product-detail', args=(1,)))
self.assertTrue(dict(name='foo', value='bar') not in r.json()['product_meta'])
self.assertNotIn(dict(name='foo', value='bar'), r.json()['product_meta'])

def test_no_product_or_endpoint_as_parameter(self):
r = self.create(name='foo', value='bar')
Expand Down
4 changes: 2 additions & 2 deletions unittests/test_apiv2_scan_import_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ def test_epmty_scan(self):
Import the ZAP scan without a test file.
"""
test = self.import_zap_scan(upload_empty_scan=False)
self.assertFalse(len(self.get_all_finding_ids(active=True, test__test_type=test.test_type)) == 0)
self.assertNotEqual(len(self.get_all_finding_ids(active=True, test__test_type=test.test_type)), 0)

def test_full_scan(self):
"""
Import the ZAP scan with a test file.
"""
test = self.import_zap_scan(upload_empty_scan=True)
self.assertFalse(len(self.get_all_finding_ids(active=True, test__test_type=test.test_type)) == 0)
self.assertNotEqual(len(self.get_all_finding_ids(active=True, test__test_type=test.test_type)), 0)
2 changes: 1 addition & 1 deletion unittests/test_apiv2_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_user_list(self):
r = self.client.get(reverse('user-list'))
self.assertEqual(r.status_code, 200, r.content[:1000])
user_list = r.json()['results']
self.assertTrue(len(user_list) >= 1, r.content[:1000])
self.assertGreaterEqual(len(user_list), 1, r.content[:1000])
for user in user_list:
for item in ['username', 'first_name', 'last_name', 'email']:
self.assertIn(item, user, r.content[:1000])
Expand Down
10 changes: 5 additions & 5 deletions unittests/test_endpoint_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ def test_equality_without_products(self):
e2 = Endpoint(protocol="https", host="localhost", port=5439, path="test", query="param=value")
e3 = Endpoint(protocol="https", host="localhost", port=5439, path="different", query="param=value")
# Verify e1 and e2 are actually equal
self.assertTrue(e1 == e2)
self.assertEqual(e1, e2)
# Verify e1 and e2 are not equal because the path is different
self.assertFalse(e1 == e3)
self.assertNotEqual(e1, e3)

def test_equality_with_one_product_one_without(self):
# Define the product
Expand All @@ -176,7 +176,7 @@ def test_equality_with_one_product_one_without(self):
e2 = Endpoint(host="localhost", product=p)
# Verify e1 and e2 are actually equal
# Since on has a product and the other does not, we cannot use products to aid in equality
self.assertTrue(e1 == e2)
self.assertEqual(e1, e2)

def test_equality_with_products(self):
# Define the product
Expand All @@ -196,10 +196,10 @@ def test_equality_with_products(self):
e3 = Endpoint(host="localhost", product=p2)
# Verify e1 and e2 are actually equal
# Since the products match, this should be true
self.assertTrue(e1 == e2)
self.assertEqual(e1, e2)
# Verify e1 and e2 are not equal
# Because the products are different, the endpoint objects are not the same
self.assertFalse(e1 == e3)
self.assertNotEqual(e1, e3)


@skip("Outdated - this class was testing clean-up broken entries in old version of model; new version of model doesn't to store broken entries")
Expand Down
2 changes: 1 addition & 1 deletion unittests/test_jira_config_engagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def add_engagement_jira(self, data, expect_redirect_to=None, expect_200=False):
engagement = Engagement.objects.get(id=response.url.split('/')[-2])
except:
raise ValueError('error parsing id from redirect uri: ' + response.url)
self.assertTrue(response.url == (expect_redirect_to % engagement.id))
self.assertEqual(response.url, (expect_redirect_to % engagement.id))
else:
self.assertEqual(response.status_code, 200)

Expand Down
4 changes: 2 additions & 2 deletions unittests/test_jira_config_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def test_add_jira_instance_invalid_credentials(self, jira_mock):

self.assertEqual(200, response.status_code)
content = response.content.decode('utf-8')
self.assertTrue('Login failed' in content)
self.assertTrue('Unable to authenticate to JIRA' in content)
self.assertIn('Login failed', content)
self.assertIn('Unable to authenticate to JIRA', content)

@patch('dojo.jira_link.views.jira_helper.is_jira_project_valid')
def test_add_jira_project_to_product_without_jira_project(self, jira_mock):
Expand Down
46 changes: 23 additions & 23 deletions unittests/test_rest_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def test_list(self):
self.assertEqual(len(check_for_tags), len(result.get('tags', None)))
for tag in check_for_tags:
# logger.debug('looking for tag %s in tag list %s', tag, result['tags'])
self.assertTrue(tag in result['tags'])
self.assertIn(tag, result['tags'])
tags_found = True
self.assertTrue(tags_found)

Expand All @@ -369,7 +369,7 @@ def test_create(self):
self.assertEqual(len(self.payload.get('tags')), len(response.data.get('tags', None)))
for tag in self.payload.get('tags'):
# logger.debug('looking for tag %s in tag list %s', tag, response.data['tags'])
self.assertTrue(tag in response.data['tags'])
self.assertIn(tag, response.data['tags'])

self.check_schema_response('post', '201', response)

Expand All @@ -381,9 +381,9 @@ def test_detail(self):
self.assertEqual(200, response.status_code, response.content[:1000])
# sensitive data must be set to write_only so those are not returned in the response
# https://github.com/DefectDojo/django-DefectDojo/security/advisories/GHSA-8q8j-7wc4-vjg5
self.assertFalse('password' in response.data)
self.assertFalse('ssh' in response.data)
self.assertFalse('api_key' in response.data)
self.assertNotIn('password', response.data)
self.assertNotIn('ssh', response.data)
self.assertNotIn('api_key', response.data)

self.check_schema_response('get', '200', response, detail=True)

Expand Down Expand Up @@ -418,16 +418,16 @@ def test_update(self):
response_data = response.data[key]
self.assertEqual(value, response_data)

self.assertFalse('push_to_jira' in response.data)
self.assertFalse('ssh' in response.data)
self.assertFalse('password' in response.data)
self.assertFalse('api_key' in response.data)
self.assertNotIn('push_to_jira', response.data)
self.assertNotIn('ssh', response.data)
self.assertNotIn('password', response.data)
self.assertNotIn('api_key', response.data)

if hasattr(self.endpoint_model, 'tags') and self.update_fields and self.update_fields.get('tags', None):
self.assertEqual(len(self.update_fields.get('tags')), len(response.data.get('tags', None)))
for tag in self.update_fields.get('tags'):
logger.debug('looking for tag %s in tag list %s', tag, response.data['tags'])
self.assertTrue(tag in response.data['tags'])
self.assertIn(tag, response.data['tags'])

response = self.client.put(
relative_url, self.payload)
Expand All @@ -448,17 +448,17 @@ def test_delete_preview(self):

self.check_schema_response('get', '200', response, detail=True)

self.assertFalse('push_to_jira' in response.data)
self.assertFalse('password' in response.data)
self.assertFalse('ssh' in response.data)
self.assertFalse('api_key' in response.data)
self.assertNotIn('push_to_jira', response.data)
self.assertNotIn('password', response.data)
self.assertNotIn('ssh', response.data)
self.assertNotIn('api_key', response.data)

self.assertIsInstance(response.data['results'], list)
self.assertTrue(len(response.data['results']) > 0, "Length: {}".format(len(response.data['results'])))
self.assertGreater(len(response.data['results']), 0, "Length: {}".format(len(response.data['results'])))

for obj in response.data['results']:
self.assertIsInstance(obj, dict)
self.assertTrue(len(obj), 3)
self.assertEqual(len(obj), 3)
self.assertIsInstance(obj['model'], str)
if obj['id']: # It needs to be None or int
self.assertIsInstance(obj['id'], int)
Expand All @@ -479,18 +479,18 @@ def test_detail_prefetch(self):

self.assertEqual(200, response.status_code)
obj = response.data
self.assertTrue("prefetch" in obj)
self.assertIn("prefetch", obj)

for field in prefetchable_fields:
field_value = obj.get(field, None)
if field_value is None:
continue

self.assertTrue(field in obj["prefetch"])
self.assertIn(field, obj["prefetch"])
values = field_value if isinstance(field_value, list) else [field_value]

for value in values:
self.assertTrue(value in obj["prefetch"][field])
self.assertIn(value, obj["prefetch"][field])

# TODO add schema check

Expand All @@ -504,22 +504,22 @@ def test_list_prefetch(self):

self.assertEqual(200, response.status_code)
objs = response.data
self.assertTrue("results" in objs)
self.assertTrue("prefetch" in objs)
self.assertIn("results", objs)
self.assertIn("prefetch", objs)

for obj in objs["results"]:
for field in prefetchable_fields:
field_value = obj.get(field, None)
if field_value is None:
continue

self.assertTrue(field in objs["prefetch"])
self.assertIn(field, objs["prefetch"])
values = field_value if isinstance(field_value, list) else [field_value]

for value in values:
if not isinstance(value, int):
value = value['id']
self.assertTrue(value in objs["prefetch"][field])
self.assertIn(value, objs["prefetch"][field])

# TODO add schema check

Expand Down
12 changes: 6 additions & 6 deletions unittests/test_risk_acceptance.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,13 @@ def test_expiration_handler(self):
to_warn = ra_helper.get_almost_expired_risk_acceptances_to_handle(heads_up_days=heads_up_days)
to_expire = ra_helper.get_expired_risk_acceptances_to_handle()

self.assertTrue(ra1 in to_warn)
self.assertFalse(ra2 in to_warn)
self.assertFalse(ra3 in to_warn)
self.assertIn(ra1, to_warn)
self.assertNotIn(ra2, to_warn)
self.assertNotIn(ra3, to_warn)

self.assertFalse(ra1 in to_expire)
self.assertFalse(ra2 in to_expire)
self.assertTrue(ra3 in to_expire)
self.assertNotIn(ra1, to_expire)
self.assertNotIn(ra2, to_expire)
self.assertIn(ra3, to_expire)

# run job
ra_helper.expiration_handler()
Expand Down
36 changes: 18 additions & 18 deletions unittests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_finding_get_tags(self):
self.assertEqual(len(tags), len(response.get('tags', None)))
for tag in tags:
# logger.debug('looking for tag %s in tag list %s', tag, response['tags'])
self.assertTrue(tag in response['tags'])
self.assertIn(tag, response['tags'])

def test_finding_filter_tags(self):
tags = ['tag1', 'tag2']
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_finding_post_tags(self):
self.assertEqual(len(tags_merged), len(response.get('tags')))
for tag in tags_merged:
# logger.debug('looking for tag %s in tag list %s', tag, response['tags'])
self.assertTrue(tag in response['tags'])
self.assertIn(tag, response['tags'])

def test_finding_post_tags_overlap(self):
# create finding
Expand All @@ -83,7 +83,7 @@ def test_finding_post_tags_overlap(self):
self.assertEqual(len(tags_merged), len(response.get('tags')))
for tag in tags_merged:
# logger.debug('looking for tag %s in tag list %s', tag, response['tags'])
self.assertTrue(tag in response['tags'])
self.assertIn(tag, response['tags'])

def test_finding_put_remove_tags(self):
# create finding
Expand All @@ -103,7 +103,7 @@ def test_finding_put_remove_tags(self):
self.assertEqual(len(tags_merged), len(response.get('tags')))
for tag in tags_merged:
# logger.debug('looking for tag %s in tag list %s', tag, response['tags'])
self.assertTrue(tag in response['tags'])
self.assertIn(tag, response['tags'])

def test_finding_put_remove_tags_all(self):
# create finding
Expand All @@ -123,7 +123,7 @@ def test_finding_put_remove_tags_all(self):
self.assertEqual(len(tags_merged), len(response.get('tags')))
for tag in tags_merged:
# logger.debug('looking for tag %s in tag list %s', tag, response['tags'])
self.assertTrue(tag in response['tags'])
self.assertIn(tag, response['tags'])

def test_finding_put_remove_tags_non_existent(self):
# create finding
Expand All @@ -143,7 +143,7 @@ def test_finding_put_remove_tags_non_existent(self):
self.assertEqual(len(tags_merged), len(response.get('tags')))
for tag in tags_merged:
# logger.debug('looking for tag %s in tag list %s', tag, response['tags'])
self.assertTrue(tag in response['tags'])
self.assertIn(tag, response['tags'])

def test_finding_patch_remove_tags(self):
# has same logic as PUT
Expand All @@ -168,8 +168,8 @@ def test_finding_create_tags_with_commas(self):
# self.assertEqual(2, len(response.get('tags')))
self.assertEqual(1, len(response.get('tags')))
# print("response['tags']:" + str(response['tags']))
self.assertTrue('one' in str(response['tags']))
self.assertTrue('two' in str(response['tags']))
self.assertIn('one', str(response['tags']))
self.assertIn('two', str(response['tags']))

def test_finding_create_tags_with_commas_quoted(self):
tags = ['"one,two"']
Expand All @@ -181,8 +181,8 @@ def test_finding_create_tags_with_commas_quoted(self):
for tag in tags:
logger.debug('looking for tag %s in tag list %s', tag, response['tags'])
# with django-tagging the quotes were stripped, with tagulous they remain
# self.assertTrue(tag.strip('\"') in response['tags'])
self.assertTrue(tag in response['tags'])
# self.assertIn(tag.strip('\"'), response['tags'])
self.assertIn(tag, response['tags'])

def test_finding_create_tags_with_spaces(self):
tags = ['one two']
Expand All @@ -195,8 +195,8 @@ def test_finding_create_tags_with_spaces(self):
# tags with commas, so should be minor trouble
# self.assertEqual(2, len(response.get('tags')))
self.assertEqual(1, len(response.get('tags')))
self.assertTrue('one' in str(response['tags']))
self.assertTrue('two' in str(response['tags']))
self.assertIn('one', str(response['tags']))
self.assertIn('two', str(response['tags']))
# finding.tags: [<Tag: one>, <Tag: two>]

def test_finding_create_tags_with_spaces_quoted(self):
Expand All @@ -209,8 +209,8 @@ def test_finding_create_tags_with_spaces_quoted(self):
for tag in tags:
logger.debug('looking for tag %s in tag list %s', tag, response['tags'])
# with django-tagging the quotes were stripped, with tagulous they remain
# self.assertTrue(tag.strip('\"') in response['tags'])
self.assertTrue(tag in response['tags'])
# self.assertIn(tag.strip('\"'), response['tags'])
self.assertIn(tag, response['tags'])

# finding.tags: <QuerySet [<Tag: one two>]>

Expand All @@ -222,7 +222,7 @@ def test_finding_create_tags_with_slashes(self):
self.assertEqual(len(tags), len(response.get('tags', None)))
for tag in tags:
# logger.debug('looking for tag %s in tag list %s', tag, response['tags'])
self.assertTrue(tag in response['tags'])
self.assertIn(tag, response['tags'])

def test_import_and_reimport_with_tags(self):
tags = ['tag1', 'tag2']
Expand All @@ -233,19 +233,19 @@ def test_import_and_reimport_with_tags(self):

self.assertEqual(len(tags), len(response.get('tags')))
for tag in tags:
self.assertTrue(tag in response['tags'])
self.assertIn(tag, response['tags'])

# reimport, do not specify tags: should retain tags
self.reimport_scan_with_params(test_id, self.zap_sample5_filename)
self.assertEqual(len(tags), len(response.get('tags')))
for tag in tags:
self.assertTrue(tag in response['tags'])
self.assertIn(tag, response['tags'])

# reimport, specify tags others: currently reimport doesn't do anything with tags param and silently ignores them
self.reimport_scan_with_params(test_id, self.zap_sample5_filename, tags=['tag3', 'tag4'])
self.assertEqual(len(tags), len(response.get('tags')))
for tag in tags:
self.assertTrue(tag in response['tags'])
self.assertIn(tag, response['tags'])


class InheritedTagsTests(DojoAPITestCase):
Expand Down
Loading