-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add unit tests for StorageService
- Loading branch information
1 parent
b999729
commit 5a379da
Showing
1 changed file
with
45 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import unittest | ||
from tinydb import TinyDB, Query | ||
from core.storage_service import StorageService | ||
|
||
class TestStorageService(unittest.TestCase): | ||
def setUp(self): | ||
self.db = TinyDB('test_db.json') | ||
self.storage_service = StorageService() | ||
|
||
def test_add(self): | ||
data = {'scan_name': 'test_scan', 'scan_id': '123', 'target': 'http://test_target', 'status': 'INPROGRESS'} | ||
self.storage_service.add(data) | ||
record = self.db.get(Query().scan_name == 'test_scan') | ||
self.assertEqual(record, data) | ||
|
||
def test_get_by_name(self): | ||
data = {'scan_name': 'test_scan', 'scan_id': '123', 'target': 'http://test_target', 'status': 'INPROGRESS'} | ||
self.db.insert(data) | ||
record = self.storage_service.get_by_name('test_scan') | ||
self.assertEqual(record, data) | ||
|
||
def test_get_by_id(self): | ||
data = {'scan_name': 'test_scan', 'scan_id': '123', 'target': 'http://test_target', 'status': 'INPROGRESS'} | ||
self.db.insert(data) | ||
record = self.storage_service.get_by_id('123') | ||
self.assertEqual(record, data) | ||
|
||
def test_update_by_name(self): | ||
data = {'scan_name': 'test_scan', 'scan_id': '123', 'target': 'http://test_target', 'status': 'INPROGRESS'} | ||
new_data = {'scan_name': 'test_scan', 'scan_id': '123', 'target': 'http://test_target', 'status': 'COMPLETE'} | ||
self.db.insert(data) | ||
self.storage_service.update_by_name('test_scan', new_data) | ||
record = self.db.get(Query().scan_name == 'test_scan') | ||
self.assertEqual(record, new_data) | ||
|
||
def test_update_by_id(self): | ||
data = {'scan_name': 'test_scan', 'scan_id': '123', 'target': 'http://test_target', 'status': 'INPROGRESS'} | ||
new_data = {'scan_name': 'test_scan', 'scan_id': '123', 'target': 'http://test_target', 'status': 'COMPLETE'} | ||
self.db.insert(data) | ||
self.storage_service.update_by_id('123', new_data) | ||
record = self.db.get(Query().scan_id == '123') | ||
self.assertEqual(record, new_data) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |