openwisp / openwisp-utils Goto Github PK
View Code? Open in Web Editor NEWPython and Django utilities shared between different openwisp modules
Home Page: http://openwisp.org
License: BSD 3-Clause "New" or "Revised" License
Python and Django utilities shared between different openwisp modules
Home Page: http://openwisp.org
License: BSD 3-Clause "New" or "Revised" License
DependencyLoader
and relative testsDependencyFinder
and relative testsTimeStampedEditableModel
TimeReadonlyAdminMixin
MultitenantAdminMixin
and relative testsMultitenantOrgFilter
and relative testsMultitenantObjectFilter
and relative testsThe tests will be the tricky part, we should ensure some test classes can be reused (the multitenant admin for example), so we move the main test logic to this module and in the other modules we just import the test classes and repeat them there to ensure the integration works correctly, there's an example of this technique in openwisp-controller, which imports the openwisp-users admin tests.
In the case of openwisp-controller, importing the admin tests from openwisp-users was necessary because an integration bug was not spotted during development until it went into production.
We need a common CI script to run all the CI tests, so that if there is minor change or a new check is added/removed, we do not need to update all the repositories with the minor change.
Read more: #37 (comment)
Add documentation for OPENWISP_ADMIN_SHOW_USERLINKS_BLOCK
settings in README.rst simialar to what has been done for other settings.
`
@nemesisdesign please add corresponding labels : good first issue
GCI
We've been spending a lot of time on code formatting during reviews lately.
In the past we discussed introducing black, I think we could start introducing it, I leave some notes here:
openwisp-qa-format
), so we can format the code with one command (hence making it easy for new contributors)openwisp-qa-format
and openwisp-qa-check
: http://openwisp.io/docs/developer/contributing.html#python-code-conventionsThe follow line contains backticks, making the script to interpret it as a command to be run and fail because manage.py is not expected to be there. See this travis log
openwisp-utils/openwisp-utils-qa-checks
Line 118 in 562e34b
Remove openwisp-utils-qa-checks in version 0.6.0.
GCI Task : link
The function openwisp_admin() in openwisp_utils.admin_theme.admin changes some settings of the vanilla django admin site at runtime. This makes it difficult to use an overridden admin site instead of the default one together with OpenWISP.
It would be better to override the vanilla admin site instead: https://docs.djangoproject.com/en/2.2/ref/contrib/admin/#customizing-the-adminsite-class Then, for further customization, this overridden class can be overridden once more.
In the new openwisp-utils-qa-checks
, there is a minor bug with the text printed.
openwisp-utils-qa-checks --skip-isort --skip-flake8 --skip-checkmigrations
Running blank endline check
SUCCESS: Blank endline check successful!
Running commit message check
SUCCESS: Commit name check successful!
File manage.py not found\nSkipping Make Migration Check
The last line does not have the newline interpreted correctly. The final result should look like
openwisp-utils-qa-checks --skip-isort --skip-flake8 --skip-checkmigrations
Running blank endline check
SUCCESS: Blank endline check successful!
Running commit message check
SUCCESS: Commit name check successful!
File manage.py not found
Skipping Make Migration Check
Read OpenWISP Commit conventions: openwisp/openwisp-docs#109
I still think we should keep consistency with what we've done until now, so I would use "feature" instead of "feat.
The prefix can be in square brackets, eg: [feature]
, [change]
.
Ensure first letter after ]
is capital letter.
We should use the same keywords of conventional commits, with the exception of "feat" which is better spelt "feature", 3 characters are worth it in my opinion in this case.
We should also add [change]
to the allowed prefixes.
We could then add a commit message template like this: https://thoughtbot.com/blog/better-commit-messages-with-a-gitmessage-template we can try it here first and then replicate it in the other modules.
Maybe we could ditch our own commit check solution in favor of a standard one, I just found this tool which looks really interesting!
https://commitizen-tools.github.io/commitizen/
This change will help us to generate change logs more easily later on.
extra_requires['rest']
with DRF and swagger in setup.pyOPENWISP_REST_SWAGGER
(or similar) which shall control whether the swagger docs is enabled or not (some users in prod may want to disable this)Related to #91.
The links "Templates" and "VPN Servers" are available in the menu although the user doesn't have the rights for these objects:
I had a look into this a bit:
ModelAdmin.has_module_permission
evaluates permissions only on the module level, not on the model level (Device, Template, Vpn).openwisp-utils
is decoupled from the other OpenWISP modules so we don't have access to models etcInstructions for development are redundant. Similar to openwisp/openwisp-users#113 (comment)
In https://github.com/openwisp/openwisp-utils#installing-for-development
Following command does not install dependencies of [qa] and [rest] which are required for running tests.
python setup.py develop
Thanks to @marfgold1 , now we have #60 merged.
We can now remove multiple checks of openwisp-utils-qa-checks
like this:
openwisp-utils-qa-checks --migration-path "./openwisp_users/migrations/ ./tests/testapp/migrations/" --migrations-to-ignore "3 2"
For this issue, you have to implement openwisp-utils-qa-check
in all the openwisp repositories that use openwisp-utils-qa-checks
multiple times to accomplish the same.
Whenever there's a build failure in a PR, it would be great to know what has failed and post a summary as a comment in the github PR.
I found a blog post which explains how to do it: https://damien.pobel.fr/post/github-api-from-travisci/
But any other updated online resources which work will be fine.
The comment should only have the relevant information about failures an nothing else.
If tests are failing we could simply say "Some test case have failed".
In case openwisp-qa-check
has failed, we could collect the reason of the failure and post it as a message.
One of the ways in which we could do this is to print errors to standard error (instead of printing to standard output), collect the standard error output in a separate var which is then used to build the comment which will be posted to github.
I suggest trying this change in your own fork first (enable travis on your fork and test the failures there).
Add ci test that checks if migration file created has a descriptive name, fail test if default name pattern is found.
The check performed at these lines is not being executed:
openwisp-utils/openwisp_utils/qa.py
Lines 155 to 163 in fc28a78
Add the description of checkendline
and openwisp-utils-qa-check
to the README, in a similar way to how the other quality assurance scripts are documented.
Let's centralize all the repetitive dependencies in openwisp-utils so we can avoid to repeat them in each package and so that we can manage the dependencies of all the OpenWISP modules.
Dependencies will divide in groups:
Then once we have done all these changes, we will remove the dependencies in the other modules and point to the openwisp-utils groups, eg: pip install openwisp-utils[django,rest]>=0.5.0
The commitcheck
has an option to avoid running the commitcheck on a particular commit by using the #noqa
option.
However, this feature is not documented. please add this with an example in the documentation.
commitcheck --message "[qa] Improved Y #20\n\n Simulation of a special unplanned case\n\n#noqa"
Increase test coverage to 100%.
Reserved for GCI.
Move MultitenantAdminMixin
and all similar logic which is related to users and organizations to openwisp-users, also remove openwisp_users
from extra_requires
in setup.py
.
The related unit tests and documentation in README has to be moved as well.
We'll need to increase the version to 0.3.0 because it will be a backward incompatible change
Django-rest-framework, which has been used to create API views, does not call the full_clean
method under models, this means that custom model validations would not run on API views while creating or updating records. We need to create a base serializer class which can be extended to other apps.
We should add a few settings to the admin_theme
module allowing to supply custom CSS and JS files; these should be lists of strings containing URLs to the static files (as users may add multiple files if they need), static files have to be deployed in separate steps (this should be made clear in the README).
Settings could be named:
OPENWISP_ADMIN_THEME_CSS
and OPENWISP_ADMIN_JS
As usual we need tests and docs for this feature.
Add a check to ensure that all the makemigrations
are done and there is "No changes detected" in the migrations.
The command to check this would be:
python manage.py makemigrations --dry-run <module-name>
where is optional <module-name>
would be passed as an arguement.We currently have two migration checks:
./manage.py makemigrations --dry-run
)auto
in themThe problem is that we have to specify both --migration-module
and --migration-path
.
I think we can avoid doing this and have only one command line flag.
I would get rid of --migration-path
, keeping only --migration-module
, although I would rename this flag to --migration-modules
while keeping backward compatibility with the old flag.
--migration-path
should be ignored (printing a deprecation warning).
We will need to upgrade the modules using this: https://github.com/search?q=org%3Aopenwisp+%27--migration-path%27&type=Code
When running the command: openwisp-qa-check
I am seeing an incompatibility between isort and black.
Black wants to convert this to:
-from django_loci.base.models import AbstractFloorPlan, AbstractLocation, AbstractObjectLocation
+from django_loci.base.models import (
+ AbstractFloorPlan,
+ AbstractLocation,
+ AbstractObjectLocation,
+)
While isort keeps changing it to:
+ from django_loci.base.models import AbstractFloorPlan, AbstractLocation, AbstractObjectLocation
- from django_loci.base.models import (
- AbstractFloorPlan,
- AbstractLocation,
- AbstractObjectLocation,
- )
There are many such lines in the django-netjsonconfig.
I was testing some changes in a test in openwisp_monitoring
and thought of using a docstring to better explain a test.
That's when I noticed TimeLoggingTestRunner
doesn't work with docstrings
, due to one particular line. Below is the traceback, it can be easily reproduced by introducing a docstring in any slow test.
Traceback (most recent call last):
File "tests/test_project/tests/test_test_utils.py", line 51, in test_time_logging_runner
runner.run_suite(suite)
File "/home/hardik/.local/lib/python3.6/site-packages/django/test/runner.py", line 630, in run_suite
return runner.run(suite)
File "/usr/lib/python3.6/unittest/runner.py", line 180, in run
stopTestRun()
File "/home/hardik/openwisp/openwisp-utils/openwisp_utils/tests.py", line 66, in stopTestRun
self.display_slow_tests()
File "/home/hardik/openwisp/openwisp-utils/openwisp_utils/tests.py", line 51, in display_slow_tests
name, module = name.split()
ValueError: too many values to unpack (expected 2)
Though I haven't seen much usage of docstring in tests in openwisp
, still there shouldn't be a limitation, in my opinion. I will try to fix this and submit a patch.
The check is failing with:
There are some Errors in your RST file syntax
- <string>:1: (WARNING/2) "raw" directive disabled.
However, I don't think the path we've taken is good.
The repositories which have sphinx documentation already have checks to ensure that documentation compiles and renders successfully, these checks simply generate the sphinx docs and they work reliably.
Now we're mixing things.
I asked to add this check because we need to check that the README files are compatible with pypi.
If we start allowing sphinx syntax in the README, we'll hit again the same issue that some of the sphinx syntax won't work on pypi.
I think the right solution is to separate the two things.
Sphinx documentation checks must be done as we already do: https://github.com/openwisp/netjsonconfig/blob/master/run-qa-checks#L8-L10
This new check should only focus on the README compatibility with pypi, removing the changes we introduced recently to make it work on openwisp-radius.
I would also rename the check to make this more explicit: we can call it checkreadme
to ensure things don't get confused.
@KapilBansal320 what do you think?
Python2 is very close to the end of it's lifecycle, it's time we drop the support for Python 2.
To do that,
The ReStructuredText check fails in those repos which are using sphinx, eg: openwisp-radius.
- <string>:43: (ERROR/3) Unknown directive type "toctree".
-
- .. toctree::
- :maxdepth: 2
- :caption: Contents:
-
- /developer/setup
- /developer/freeradius
- /user/settings
- /user/management_commands
- /user/importing_users
- /user/generating_users
- /user/enforcing_limits
- /user/registration
- /user/social_login
- /user/api
- /developer/how_to_extend
- /developer/contributing
- /general/goals
@KapilBansal320 can we selectively disable some errors?
Don't fail the commit check if the commit starts with: <numbers dots and letters> release
.
See how this PR is failing: openwisp/django-netjsonconfig#146
Right now, to add menu items in the several openwisp modules, we require a lot of repetition of code:
We should simplify this, allowing to register new items with a function, optionally allowing to specify the position at which the items will be added in the menu list (append by default to the end, allow to insert after a specific app or model).
Add support for django 3.1.
For consistency with the new openwisp-qa-format
, let's rename openwisp-utils-qa-checks
to openwisp-qa-check
but we have to maintain backward compatibility with the old command (openwisp-utils-qa-checks
) to avoid breaking builds.
Reserved for GSoC Students
We have different parts of different OpenWISP modules which have a key
or secret
field which has one or more of the following features:
uuid
and look at the javascript file)uuid
and look at the javascript file)receive_url
and then find the receive-url.js
javascript)We need to:
When publishing to pypi, sometimes the publishing fails because of an error in the README.rst, this may happen once the commit and git tag have been already sent, so it's not ideal.
We should avoid this, it shouldn't be hard:
docs/source
exists, run the check recursively on itThis would allow to enable this check on all the repos which make use of openwisp-utils!
For now, checkmigrations in the new openwisp-utils-qa-checks
common CI script is supported only for one migration path and one migration-to-ignore.
In some repo (like django-ipam, django-loci, and more) it's required to check on two migration-path.
And even some repo (like openwisp-users) it's required to check on two migration-path and two different migrations-to-ignore.
To deal with this, we can:
runcheckmigration
in those repo and use openwisp-utils-qa-checks
with --skip-checkmigration. The disadvantage is, well, why should checkmigration exist in the common CI test then... ๐
openwisp-utils-qa-checks
, with the second call to check for other checkmigration and skip all tests. The disadvantage is when there is an addition/removal in the CI test, we should change those repositories too.Either ways are fine, but kind of defeated the purpose of openwisp-utils-qa-checks
that simplify the workflow of minor change in the CI tests without having to deal with all repositories. So I suggest that we might support multiple checkmigration, separated by semicolon. For example, we can do this for openwisp-users
openwisp-utils-qa-checks --migration-path "./openwisp_users/migrations/;./tests/testapp/migrations/" --migrations-to-ignore "3;2"
Feel free to discuss/suggest/give your opinion about the better ways to do this ๐
DependencyLoader
and DependencyFinder
should allow django to reuse templates and static files of third party apps that are not loaded in settings.INSTALLED_APPS
.
Because the original code was tied to openwisp-controller, the two classes now don't make much sense because they will go to look into openwisp_utils.__dependencies__
.
What about creating a new setting like EXTENDED_APPS
?
In the test suite you could add a dependency to django-netjsonconfig, then set in the test project:
EXTENDED_APPS = ['django-netjsonconfig']
Then you could write 2 tests in which you just instantiate the 2 classes and check the list they produce is correct.
We should add another automated test to check if all the files have an empty line at the end of the file.
Many GCI students are making this mistake and an automated test will help them in my opinion! ๐
PS: binary files must be ignored, the check should be performed only on text files.
If it can be performed with just a series of shell commands, we can use that and start adding this check to the .travis.yml
build of this repo
The commit used in #126 should cause the check to fail, but it seems the check is not being run.
Recently some contributors have been confused by the fact that some tests print output to standard output and/or standard error, so they thought tests failed when tests are passing.
Let's use two context managers from the standard library to create two decorators that we'll use to decorate the test methods which produce output, the context managers are:
It should be possible to decorate test methods like the following:
import sys
from openwisp_utils.tests import redirect_stdout, redirect_stderr, redirect_any_output
@redirect_stdout
def test_something_out(self):
print('this test prints output')
@redirect_stderr
def test_something_err(self):
print('this test prints some error', file=sys.stderr)
@redirect_any_output
def test_something_out(self):
print('this test prints output')
print('this test prints some error', file=sys.stderr)
Sometimes we also need to check the output, so we need a way to access it, eg:
@redirect_stdout(io.StringIO())
def test_something_out(self, output):
action_generating_output() # pseudocode
self.assertIn('expected output', output.getvalue())
@redirect_any_output(stdout=io.StringIO(), stderr=io.StringIO())
def test_something_out(self, stdout, stderr):
action_generating_output() # pseudocode
self.assertIn('expected stdout', stdout.getvalue())
self.assertIn('expected stderr', stderr.getvalue())
Here's a sample decorator which does not use the context managers above but which may adapted to do so: https://gist.github.com/jasonbartz/8480004
As a last step, use this decorator to silence the output of some tests in this module.
As usual, tests and (brief) docs are needed as well.
Allow overriding the default argument of KeyField
. Would be good to have the get_random_key
bound to the KeyField
for easier generation of the default value. whenever it needs to be overridden.
It's time to automate the commit message style checks according to our guidelines, that will make contributing a lot smoother for new contributors and less time consuming for reviewers.
These are the most common issues which we should address:
Done something
(should be [qa] Done something
)[qa] done something
[qa] Done something.
[qa] Done something
Long description
Implements #20
(won't close), Closes #20 and #21
(won't close #21
- but we should allow writing something like Related to #33
, because sometimes we may want to reference an issue even though we are not solving it in that commit[qa] Done something
Fixes #2
should be:
[qa] Done something #2
Fixes #2
(easier to read in the short log format)
This is not urgent but not unimportant because having a clean commit history is important for the long term sustainability of the project.
It doesn't make sense to keep enforcing these rules by hand.. it's clear to me that as the community grows we won't be able to do that, so automating this check is key.
We need something like the migration check implemented in #16.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.