I have followed the tutorial (parts 1 and 2) on the Django site (https://docs.djangoproject.com/en/1.4/intro/tutorial01/) and have managed to create a couple folders and to connect to my website. My app is called ‘app’, so my folder structure looks a bit like:
- mainFolder
- —__init__.py
- —test.py
- —djangoSite (created by Django)
- —— manage.py
- —— djangosite
- ——— other .py files
- —— app
- ———-__init__.py
- ——— models.py
- ——— other .py files
I changed the models.py file to be something like:
class Result(models.Model):
options = models.CharField(max_length = 1000, unique = False)
reverse = models.DecimalField(decimal_places = 6, max_digits = 12)
test.py currently runs a couple tests on some other classes. What I want is for my test.py class to run these tests and save the results in a database (in columns
and reverse). I was hoping to do something like this in my test.py class:
import models.py
if __name__ == "__main__":
optionResult = someTestsThatRuns
reverseResult = someOtherTestThatRuns
models.Result c;
c.options = optionResult
c.reverse = reverseResult
I’d like for the last two lines to save the result in the database.
Is this possible? How would I import the models.py from the app folder?
Thank you
EDIT:
When I say someTestsThatRuns, these aren’t unit tests. They are practically a function that returns a list and some strings with either ‘PASS’ or ‘FAIL’. Sorry for the confusion
Create an empty
__init__.pyfile in the app folder so Python treats the directory as a package. Then do:That will save ‘c’ to the database.
Note that Django’s test suite can create its own test database, which runs tests on a separate database. You can read more about Django testing here.
https://docs.djangoproject.com/en/dev/topics/testing/?from=olddocs