Skip to content

Commit

Permalink
[IMP] Simplified tests: no need to generate distinct IOC names now th…
Browse files Browse the repository at this point in the history
…at they are isolated by cases
  • Loading branch information
c8y3 committed Oct 2, 2024
1 parent 4e8ca75 commit da33f39
Showing 1 changed file with 18 additions and 33 deletions.
51 changes: 18 additions & 33 deletions tests/tests_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

class TestsGraphQL(TestCase):
_subject = None
_ioc_count = 0
_user_count = 0

@classmethod
def setUpClass(cls) -> None:
Expand All @@ -41,13 +39,6 @@ def tearDownClass(cls) -> None:
def tearDown(self):
self._subject.clear_database()

# Note: this method is necessary because the state of the database is not reset between each test
# and we want to work with distinct object in each test
@classmethod
def _generate_new_dummy_ioc_value(cls):
cls._ioc_count += 1
return f'IOC value #{cls._ioc_count}'

@staticmethod
def _get_first_case(body):
for case in body['data']['cases']['edges']:
Expand Down Expand Up @@ -89,7 +80,7 @@ def test_graphql_cases_should_have_a_global_identifier(self):

def test_graphql_create_ioc_should_not_fail(self):
case_identifier = self._create_case()
ioc_value = self._generate_new_dummy_ioc_value()
ioc_value = 'IOC value'
payload = {
'query': f'''mutation {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
Expand All @@ -103,10 +94,9 @@ def test_graphql_create_ioc_should_not_fail(self):

def test_graphql_delete_ioc_should_not_fail(self):
case_identifier = self._create_case()
ioc_value = self._generate_new_dummy_ioc_value()
payload = {
'query': f'''mutation {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "IOC value") {{
ioc {{ iocId }}
}}
}}'''
Expand All @@ -126,10 +116,9 @@ def test_graphql_delete_ioc_should_not_fail(self):
def test_graphql_create_ioc_should_allow_optional_description_to_be_set(self):
case_identifier = self._create_case()
description = 'Some description'
ioc_value = self._generate_new_dummy_ioc_value()
payload = {
'query': f'''mutation {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}",
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "IOC value",
description: "{description}") {{
ioc {{ iocDescription }}
}}
Expand All @@ -141,10 +130,9 @@ def test_graphql_create_ioc_should_allow_optional_description_to_be_set(self):
def test_graphql_create_ioc_should_allow_optional_tags_to_be_set(self):
case_identifier = self._create_case()
tags = 'tag1,tag2'
ioc_value = self._generate_new_dummy_ioc_value()
payload = {
'query': f'''mutation {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}",
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "IOC value",
tags: "{tags}") {{
ioc {{ iocTags }}
}}
Expand All @@ -155,7 +143,7 @@ def test_graphql_create_ioc_should_allow_optional_tags_to_be_set(self):

def test_graphql_update_ioc_should_update_tlp(self):
case_identifier = self._create_case()
ioc_value = self._generate_new_dummy_ioc_value()
ioc_value = 'IOC value'
payload = {
'query': f'''mutation {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
Expand All @@ -177,7 +165,7 @@ def test_graphql_update_ioc_should_update_tlp(self):

def test_graphql_update_ioc_should_not_update_typeId(self):
case_identifier = self._create_case()
ioc_value = self._generate_new_dummy_ioc_value()
ioc_value = 'IOC value'
payload = {
'query': f'''mutation {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
Expand All @@ -200,7 +188,7 @@ def test_graphql_update_ioc_should_not_update_typeId(self):

def test_graphql_update_ioc_should_fail_when_missing_iocId(self):
case_identifier = self._create_case()
ioc_value = self._generate_new_dummy_ioc_value()
ioc_value = 'IOC value'
payload = {
'query': f'''mutation {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
Expand All @@ -221,7 +209,7 @@ def test_graphql_update_ioc_should_fail_when_missing_iocId(self):

def test_graphql_update_ioc_should_not_update_tlpId(self):
case_identifier = self._create_case()
ioc_value = self._generate_new_dummy_ioc_value()
ioc_value = 'IOC value'
payload = {
'query': f'''mutation {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
Expand All @@ -244,10 +232,9 @@ def test_graphql_update_ioc_should_not_update_tlpId(self):

def test_graphql_update_ioc_should_not_update_value(self):
case_identifier = self._create_case()
ioc_value = self._generate_new_dummy_ioc_value()
payload = {
'query': f'''mutation {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "IOC value") {{
ioc {{ iocId iocValue }}
}}
}}'''
Expand All @@ -267,7 +254,7 @@ def test_graphql_update_ioc_should_not_update_value(self):

def test_graphql_update_ioc_should_update_optional_parameter_description(self):
case_identifier = self._create_case()
ioc_value = self._generate_new_dummy_ioc_value()
ioc_value = 'IOC value'
payload = {
'query': f'''mutation {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
Expand All @@ -291,7 +278,7 @@ def test_graphql_update_ioc_should_update_optional_parameter_description(self):

def test_graphql_update_ioc_should_update_optional_parameter_tags(self):
case_identifier = self._create_case()
ioc_value = self._generate_new_dummy_ioc_value()
ioc_value = 'IOC value'
payload = {
'query': f'''mutation {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
Expand Down Expand Up @@ -327,10 +314,9 @@ def test_graphql_case_should_return_a_case_by_its_identifier(self):

def test_graphql_iocs_should_return_all_iocs_of_a_case(self):
case_identifier = self._create_case()
ioc_value = self._generate_new_dummy_ioc_value()
payload = {
'query': f'''mutation {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "IOC value") {{
ioc {{ iocId }}
}}
}}'''
Expand Down Expand Up @@ -362,10 +348,9 @@ def test_graphql_case_should_return_error_log_uuid_when_permission_denied(self):
def test_graphql_case_should_return_error_ioc_when_permission_denied(self):
user = self._subject.create_dummy_user()
case_identifier = self._create_case()
ioc_value = self._generate_new_dummy_ioc_value()
payload = {
'query': f'''mutation {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "IOC value") {{
ioc {{ iocId iocValue }}
}}
}}'''
Expand Down Expand Up @@ -612,7 +597,7 @@ def test_graphql_update_case_with_optional_parameter_reviewStatusId(self):

def test_graphql_query_ioc_should_not_fail(self):
case_identifier = self._create_case()
ioc_value = self._generate_new_dummy_ioc_value()
ioc_value = 'IOC value'
payload = {
'query': f'''mutation {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
Expand Down Expand Up @@ -642,7 +627,7 @@ def test_graphql_cases_should_not_fail(self):

def test_graphql_update_ioc_should_update_misp(self):
case_identifier = self._create_case()
ioc_value = self._generate_new_dummy_ioc_value()
ioc_value = 'IOC value'
payload = {
'query': f'''mutation {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
Expand All @@ -665,7 +650,7 @@ def test_graphql_update_ioc_should_update_misp(self):

def test_graphql_update_ioc_should_update_userId(self):
case_identifier = self._create_case()
ioc_value = self._generate_new_dummy_ioc_value()
ioc_value = 'IOC value'
payload = {
'query': f'''mutation {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
Expand All @@ -687,7 +672,7 @@ def test_graphql_update_ioc_should_update_userId(self):

def test_graphql_update_ioc_should_update_iocEnrichment(self):
case_identifier = self._create_case()
ioc_value = self._generate_new_dummy_ioc_value()
ioc_value = 'IOC value'
payload = {
'query': f'''mutation {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
Expand All @@ -710,7 +695,7 @@ def test_graphql_update_ioc_should_update_iocEnrichment(self):

def test_graphql_update_ioc_should_update_modificationHistory(self):
case_identifier = self._create_case()
ioc_value = self._generate_new_dummy_ioc_value()
ioc_value = 'IOC value'
payload = {
'query': f'''mutation {{
iocCreate(caseId: {case_identifier}, typeId: 1, tlpId: 1, value: "{ioc_value}") {{
Expand Down

0 comments on commit da33f39

Please sign in to comment.