Tests in Oscar

38 views
Skip to first unread message

EricS

unread,
Feb 20, 2018, 4:00:26 PM2/20/18
to django-oscar
Hello,

What is the best procedure for creating and running custom tests for customized apps in Oscar.

I have setup a simple test file as follows:


-------
from django.test import TestCase

# Create your tests here.

from basket.forms import BasketLineForm

class BasketLineFormTest(TestCase):

    def setUp(self):
        import pdb; pdb.set_trace( )

    def test_this_form(self):
        import pdb; pdb.set_trace( )
        form = BasketLineForm()
------

This file is called 'test_forms.py and is located in a 'tests' sub-directory in my customized 'apps.basket' folder.

When I call 'python manage.py test apps/basket/tests' from my project root, it runs fine, pauses at the pdb's, then errors on 'form = BasketLineForm' with a positional argument error of 'strategy'.

I do know what this particular error is, however, but I wanted to stop right here and see if there is something I could reuse from the 'test' folder just outside the Oscar source folder.

In this 'test' folder I see a sub-dir called 'factories' and it 'appears' to have a lot of setup methods that seem I could use, in particular 'test/factories/basket.py' which sets self.strategy.

Can these 'test factory' items, including the files just outside of 'factories' folder (testcases.py, basket.py, utils.py, etc.) be used/subclassed into my custom test files?

What is a little confusing is in addition to this 'test' dir in the Oscar source, I see another folder outside of the source called 'tests', this later one I'm assuming it is for testing the any contributions to the base Oscar source, since this is mentioned in the Oscars Docs.

What has worked for you? Hopefully I've explained this well enough...

Thanks ahead of time for your help, much appreciated!

Eric


Samir Shah

unread,
Feb 23, 2018, 2:29:08 AM2/23/18
to django-oscar
Can these 'test factory' items, including the files just outside of 'factories' folder (testcases.py, basket.py, utils.py, etc.) be used/subclassed into my custom test files?

Yes, absolutely. This is why oscar.test ships as part of the packaged Oscar, so that you can use those utilities in your own project.

The top level `tests` is Oscar's own tests, and these will not be installed when you install using pip etc.
Reply all
Reply to author
Forward
0 new messages