-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Make calls more generic, allowing easier writing of test cases. - Improve error handing to yield more meaningfull error messages
- Loading branch information
Showing
12 changed files
with
306 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,28 @@ | ||
import datetime | ||
|
||
from hashtopolis import Agent | ||
|
||
from utils import BaseTest | ||
from utils import do_create_agent, do_create_hashlist, do_create_task | ||
from utils import do_create_agent | ||
|
||
|
||
class AgentTest(BaseTest): | ||
def test_new_agent(self): | ||
dummy_agent, agent = do_create_agent() | ||
self.delete_after_test(agent) | ||
|
||
hashlist = do_create_hashlist() | ||
self.delete_after_test(hashlist) | ||
model_class = Agent | ||
|
||
task = do_create_task(hashlist) | ||
self.delete_after_test(task) | ||
def create_test_object(self, delete=True): | ||
_, model_obj = do_create_agent() | ||
if delete: | ||
self.delete_after_test(model_obj) | ||
return model_obj | ||
|
||
dummy_agent.get_task() | ||
dummy_agent.get_hashlist() | ||
dummy_agent.get_chunk() | ||
def test_create_agent(self): | ||
model_obj = self.create_test_object() | ||
self._test_create(model_obj) | ||
|
||
def test_patch_agent(self): | ||
_, agent = do_create_agent() | ||
self.delete_after_test(agent) | ||
|
||
new_name = f'agent-patch-{datetime.datetime.now().isoformat()}' | ||
agent.agentName = new_name | ||
agent.save() | ||
|
||
obj = Agent.objects.get(pk=agent.id) | ||
self.assertEqual(obj.agentName, new_name) | ||
model_obj = self.create_test_object() | ||
attr = 'agentName' | ||
self._test_patch(model_obj, attr) | ||
|
||
def test_expandables_agent(self): | ||
model_obj = self.create_test_object() | ||
expandables = ['agentstats'] | ||
self._test_expandables(model_obj, expandables) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,34 @@ | ||
import datetime | ||
|
||
from hashtopolis import Cracker | ||
from hashtopolis import HashtopolisError | ||
from utils import BaseTest | ||
from utils import do_create_cracker | ||
|
||
|
||
class CrackerTest(BaseTest): | ||
def test_create_cracker(self): | ||
cracker = do_create_cracker() | ||
self.delete_after_test(cracker) | ||
model_class = Cracker | ||
|
||
obj = Cracker.objects.get(crackerBinaryId=cracker.id) | ||
self.assertEqual(obj.binaryName, cracker.binaryName) | ||
def create_test_object(self, delete=True): | ||
model_obj = do_create_cracker() | ||
if delete: | ||
self.delete_after_test(model_obj) | ||
return model_obj | ||
|
||
def test_patch_cracker(self): | ||
cracker = do_create_cracker() | ||
self.delete_after_test(cracker) | ||
|
||
stamp = datetime.datetime.now().isoformat() | ||
obj_name = f'Dummy Cracker - {stamp}' | ||
cracker.binaryName = obj_name | ||
cracker.save() | ||
def test_create_cracker(self): | ||
model_obj = self.create_test_object() | ||
self._test_create(model_obj) | ||
|
||
obj = cracker.objects.get(crackerBinaryId=cracker.id) | ||
self.assertEqual(obj.binaryName, obj_name) | ||
def test_patch_cracker(self): | ||
model_obj = self.create_test_object() | ||
attr = 'binaryName' | ||
self._test_patch(model_obj, attr) | ||
|
||
def test_delete_cracker(self): | ||
cracker = do_create_cracker() | ||
|
||
obj = cracker.objects.get(crackerBinaryId=cracker.id) | ||
self.assertIsNotNone(obj) | ||
|
||
cracker.delete() | ||
|
||
objs = Cracker.objects.filter(crackerBinaryId=cracker.id) | ||
self.assertEqual(objs, []) | ||
model_obj = self.create_test_object(delete=False) | ||
self._test_delete(model_obj) | ||
|
||
def test_exception_cracker(self): | ||
with self.assertRaises(HashtopolisError) as e: | ||
_ = do_create_cracker('002') | ||
self.assertEqual(e.exception.args[1], 'Creation of object failed') | ||
self.assertIn('Required parameter', e.exception.args[4]) | ||
self._test_exception(do_create_cracker, '002') | ||
|
||
def test_expandables_cracker(self): | ||
model_obj = self.create_test_object() | ||
expandables = ['crackerBinaryType'] | ||
self._test_expandables(model_obj, expandables) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,35 @@ | ||
import json | ||
import datetime | ||
from pathlib import Path | ||
|
||
from hashtopolis import CrackerType | ||
from hashtopolis import HashtopolisError | ||
from utils import BaseTest | ||
from utils import do_create_crackertype | ||
|
||
|
||
class CrackerTypeTest(BaseTest): | ||
def test_create_crackertype(self): | ||
p = Path(__file__).parent.joinpath('create_crackertype_001.json') | ||
payload = json.loads(p.read_text('UTF-8')) | ||
crackertype = CrackerType(**payload) | ||
crackertype.save() | ||
model_class = CrackerType | ||
|
||
obj = CrackerType.objects.get(crackerBinaryTypeId=crackertype.id) | ||
self.assertEqual(obj.typeName, payload.get('typeName')) | ||
def create_test_object(self, delete=True): | ||
model_obj = do_create_crackertype() | ||
if delete: | ||
self.delete_after_test(model_obj) | ||
return model_obj | ||
|
||
crackertype.delete() | ||
def test_create_crackertype(self): | ||
model_obj = self.create_test_object() | ||
self._test_create(model_obj) | ||
|
||
def test_patch_crackertype(self): | ||
p = Path(__file__).parent.joinpath('create_crackertype_001.json') | ||
payload = json.loads(p.read_text('UTF-8')) | ||
crackertype = CrackerType(**payload) | ||
crackertype.save() | ||
|
||
stamp = datetime.datetime.now().day | ||
obj_name = f'hashcat{stamp}' | ||
crackertype.typeName = obj_name | ||
crackertype.save() | ||
|
||
obj = CrackerType.objects.get(crackerBinaryTypeId=crackertype.id) | ||
self.assertEqual(obj.typeName, obj_name) | ||
|
||
crackertype.delete() | ||
model_obj = self.create_test_object() | ||
attr = 'typeName' | ||
new_attr_value = 'Generic - edited' | ||
self._test_patch(model_obj, attr, new_attr_value) | ||
|
||
def test_delete_crackertype(self): | ||
p = Path(__file__).parent.joinpath('create_crackertype_001.json') | ||
payload = json.loads(p.read_text('UTF-8')) | ||
crackertype = CrackerType(**payload) | ||
crackertype.save() | ||
|
||
id = crackertype.id | ||
|
||
crackertype.delete() | ||
|
||
objs = CrackerType.objects.filter(crackerBinaryTypeId=id) | ||
|
||
self.assertEqual(objs, []) | ||
model_obj = self.create_test_object(delete=False) | ||
self._test_delete(model_obj) | ||
|
||
def test_exception_crackertype(self): | ||
p = Path(__file__).parent.joinpath('create_crackertype_002.json') | ||
payload = json.loads(p.read_text('UTF-8')) | ||
crackertype = CrackerType(**payload) | ||
|
||
with self.assertRaises(HashtopolisError) as e: | ||
crackertype.save() | ||
self.assertEqual(e.exception.args[1], 'Creation of object failed') | ||
self.assertIn('is not of type string', e.exception.args[4]) | ||
self._test_exception(do_create_crackertype, '002') | ||
|
||
def test_expandables_crackertype(self): | ||
model_obj = self.create_test_object() | ||
expandables = ['crackerVersions'] | ||
self._test_expandables(model_obj, expandables) |
Oops, something went wrong.