guides-cms
guides-cms copied to clipboard
Refactor models/file.py and models/article.py
These modules were created to be independent and used from the CLI. However, each module's functions have amassed a lot of arguments. We could refactor this by passing more objects around. Previously we didn't use objects because we were trying to make the layers share as little as possible.
The article.py file probably needs more work that file.py so we should focus on that first. I have a few random ideas for how to go about this refactor to consider when working on it:
- We should put tests in place first to make sure nothing in article.py is broken since it's the heart and soul of the application.
- We can incorporate some of the misc. functions in article.py into the
Articleclass.- I think there are a lot of functions in this file that do not belong in the class. However, it's hard to come up with a concrete list so we'll just have to try things out and continually iterate on balancing what goes in the class and what doesn't.
Any other thoughts?
@durden That sounds like a good plan! I can start working on creating tests around article.py, and then refactor misc. functions into the Article class.
One thing I am not sure is how these tests are supposed to run. I was able to run and verify test_file.py as python -m pskb_website.models.tests.test_file from the root. But I am wondering if there is a build script or something similar already in place which runs all these tests during run-time? If something like this already exists, I can use that locally to run tests.
There's a rule in the Makefile to run tests if you're on a UNIX machine or Windows with Make installed, just run "make test". You can also run "py.test" from the main repository directory and it will find the tests.
Name you new test file pskb_website/models/tests/test_article.py and then py.test will automatically find it and run.
On Sunday, April 3, 2016, Naba Sadia Siddiqui [email protected] wrote:
@durden https://github.com/durden That sounds like a good plan! I can start working on creating tests around article.py, and then refactor misc. functions into the Article class.
One thing I am not sure is how these tests are supposed to run. I was able to run and verify test_file.py as python -m pskb_website.models.tests.test_file from the root. But I am wondering if there is a build script or something similar already in place which runs all these tests during run-time? If something like this already exists, I can use that locally to run tests.
— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/pluralsight/guides-cms/issues/14#issuecomment-204852443
I prefer to use the pytest framework for the test runner. There's nothing pytest specific in the existing tests so we could discuss using something else if you have a strong preference. My preference for pytest is that it's easy and can run tests written with the built-in unittest as well as nose. So, we can technically accommodate all the major test frameworks if you think any specific test fits better with something other than plain assert statements from pytest.