From e8e4690e0916b43af2e883023b55c9f9ebee8b0e Mon Sep 17 00:00:00 2001 From: jblu Date: Mon, 19 Sep 2022 20:37:14 -0500 Subject: [PATCH] added dragnet test case and fixed dragnet --- qprocess.py | 11 ++++------- test_dragnet.py | 20 ++++++++++++++++++++ test_qbitmaid.py | 2 ++ 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 test_dragnet.py diff --git a/qprocess.py b/qprocess.py index 0919421..f383e5a 100644 --- a/qprocess.py +++ b/qprocess.py @@ -1,6 +1,3 @@ -from cgitb import enable - - def tor_processor(self): """Main logic to sort through both self.tracker_nonprotected_list and self.tracker_protected_list If torrent meets criteria for deletion, its infohash_v1 will be appended to self.torrent_hash_delete_list @@ -36,7 +33,7 @@ def tor_processor(self): self.tl.info(f'Submitted ["{canidate["name"][0:20]}..."] for deletion.') else: if self.enable_dragnet: - dragnet(self,canidate['state'],canidate['ratio'],canidate["tags"],canidate['added_on'],self.age,self.t.time(),canidate['infohash_v1'],canidate["name"][0:20]) + dragnet(self.cv,self.dragnet_outfile,canidate['state'],canidate['ratio'],canidate["tags"],canidate['added_on'],self.age,self.t.time(),canidate['infohash_v1'],canidate["name"][0:20]) self.tl.info(f'["{canidate["name"][0:20]}..."] is orphaned.') self.up_tor_counter += 1 continue @@ -73,11 +70,11 @@ def is_not_protected_tor(setnonprotectedtag, tortags): if setnonprotectedtag in tortags: return True -def dragnet(self,state,ratio,tags,added,age,time,thash,tname): +def dragnet(csv_obj,outfile,state,ratio,tags,added,age,time,thash,tname): header = ['state','ratio','tags','added','age','time','thash','tname'] row = [state,ratio,tags,added,age,time,thash,tname] - with open(self.dragnet_outfile, 'w', encoding='UTF8', newline='') as f: - writer = self.cv.writer(f) + with open(outfile, 'a+', encoding='UTF8', newline='') as f: + writer = csv_obj.writer(f) if f.tell() == 0: writer.writerow(header) writer.writerow(row) \ No newline at end of file diff --git a/test_dragnet.py b/test_dragnet.py new file mode 100644 index 0000000..d1adb33 --- /dev/null +++ b/test_dragnet.py @@ -0,0 +1,20 @@ +from qprocess import dragnet +import csv +import unittest + +class TestDragnet(unittest.TestCase): + def test_dragnet_sanity(self): + self.cv = csv + outfile = './test_outfile.csv' + state = 'downloading' + ratio = 1.05 + tags = 'ipt' + added = 1 + age = 240000 + time = 123456 + thash = 'asfasdf23412adfqwer' + tname = 'thisismynamehahahah' + dragnet(self.cv,outfile,state,ratio,tags,added,age,time,thash,tname) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/test_qbitmaid.py b/test_qbitmaid.py index 2488856..8a9d309 100644 --- a/test_qbitmaid.py +++ b/test_qbitmaid.py @@ -93,6 +93,8 @@ class TestQbitmaid(unittest.TestCase): def test_isignoredtag_sanity(self): self.assertTrue(is_ignored_tag(['a','b','c'], 'first,second,third,a')) + + # def test__sanity(self): # pass -- 2.45.2