-
Notifications
You must be signed in to change notification settings - Fork 97
Feature/allocation model tests #699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feature/allocation model tests #699
Conversation
…on clean() method Signed-off-by: Eric Butcher <107886303+Eric-Butcher@users.noreply.github.com>
7a006e2
to
df3a03b
Compare
Signed-off-by: Eric Butcher <107886303+Eric-Butcher@users.noreply.github.com>
Signed-off-by: Eric Butcher <107886303+Eric-Butcher@users.noreply.github.com>
df3a03b
to
cce5415
Compare
I did more research on how Django handles It seems that coldfront is appropriately using the configuration environment variables to set the locality. However, in most instances in this codebase it seems that the project uses For now I am using all dates and times as utc. The If having timezone aware tests are important it might be worth considering bringing a global time mocking library in such as freezegun or time machine. https://docs.djangoproject.com/en/5.2/topics/i18n/timezones/ |
eec246e
to
cce5415
Compare
Signed-off-by: Eric Butcher <107886303+Eric-Butcher@users.noreply.github.com>
Signed-off-by: Eric Butcher <107886303+Eric-Butcher@users.noreply.github.com>
…amming Signed-off-by: Eric Butcher <107886303+Eric-Butcher@users.noreply.github.com>
Signed-off-by: Eric Butcher <107886303+Eric-Butcher@users.noreply.github.com>
So I went ahead and replaced all occurrences of replacing environment variables using The problem with testing any functions that relied on the value of environment variables was that the code does not actually use the values of the environment variables inside of its functions. For example, at the top of the file
Crucially, these are now new variables that are set to the values of the environment variables in the settings, but are not actually the environment variables in the settings. The code in the module then uses these newly created variables. This meant that when trying to change the values of the environment variables in test cases using The first approach I used to fix this was to just put a new line at the top of each function that used an env value to get the current value of the environment. However, this could be problematic because I do not know how python would handle it if an admin ever came in and manually changed the values in settings file at some point in time in the middle of a coldfront deployment. When the function would then be called and the env value fetched, I am not sure if it would use the new or old value. The second approach is to use monkey patching instead, which hot-changes the value specifically of the variable inside the particular module when the tests are run using |
This is the start of adding to the Allocation app test suite. I have wrote several tests covering the clean method, the save method, and the get_information property.
Many of the tests for the clean method use
datetime
s. I am not sure how well coldfront currently handles dates and times so these may need to be revised as currently they are quite naive.Because the
save()
method uses an external setting to control whether or not it calls arbitrary functions it was quite hard to test and I had to get quite creative. Some of the code for that is admittedly ugly but it seems that it was the only way I could test it without making huge changes to the current way the code is written. I did need to make a small change to thesave()
method so that it refreshes the settingALLOCATION_FUNCS_ON_EXPIRE
when the method is called instead of relying on the value from when the module was instantiated by python. Without doing this there would be no way to test that behavior during test time. Some of the code that assists with theTestCase
forsave()
had to live outside of the actual class because of issues with the way python initializes things and the meta-programming the I had to use to be able to test that an external function actually was being called by save().It seems that it might be a bigger issue throughout the codebase of settings being loaded in at the top of a python file but then having their values used inside of functions defined in that file. This would mean that if someone ever went in a changed the value for an environment variable it might not take effect until they restarted the entire application. Let me know if you would like me to make an issue / PR to go through the codebase and fix everywhere that happens.