feat(test): Spliting test_view file for better test structure. Closes #794#803
Conversation
|
Good catch @drona-gyawali !
No, I don't think so. This was only merged recently in #725 and I don't remember we left these tests out on purpose.
I also don't think so. As far as I can see, calling the super method here is essential. The Django docs specifically warn to not forget it. I guess you found 2 proper bugs! Thanks a lot! :) |
regulartim
left a comment
There was a problem hiding this comment.
Good work! 👍
I just want to discuss the best way to fix the bug you found.
tests/__init__.py
Outdated
| @@ -189,6 +189,7 @@ def tearDownClass(cls): | |||
| IOC.objects.all().delete() | |||
| CowrieSession.objects.all().delete() | |||
| CommandSequence.objects.all().delete() | |||
There was a problem hiding this comment.
Now, that we properly call the super method, do we need these 4 model.objects.all().delete() calls?
If not, we only override the method to call its super method. So we can completely remove the whole method. Am I right?
There was a problem hiding this comment.
You're right also correct me if I’m wrong, but it seems we are using explicit deletes because we want to ensure no stale data is left behind between tests , yes.
My concern is that if we keep adding new models to the test suite, we’ll always have to remember to update tearDown(), which might become a maintainability headache as the project grows. I agree that we should avoid explicit deletes if possible, but I was wondering: is there a specific performance reason for doing it manually, or can we safely rely on super method?
There was a problem hiding this comment.
but it seems we are using explicit deletes because we want to ensure no stale data is left behind between tests
Yes, but that is exactly what tearDownClass is supposed to do. So I don't think we will end up with stale data if we remove the manual deletes.
My concern is that if we keep adding new models to the test suite, we’ll always have to remember to update tearDown(), which might become a maintainability headache as the project grows.
I agree.
is there a specific performance reason for doing it manually, or can we safely rely on super method?
I honestly don't know. This code was added before I joined the project. But if we remove it and all tests pass in a reasonable amount of time, then that's fine for me.
Thank you very much :) |

Description
In this pr we split test_views.py testcases
Related issues
closesL #794
Type of change
Please delete options that are not relevant.
Checklist
develop.Ruff) gave 0 errors. If you have correctly installed pre-commit, it does these checks and adjustments on your behalf.Important Rules