[Django] #25046: Initial SQL scripts (not data) for testing

34 views
Skip to first unread message

Django

unread,
Jul 2, 2015, 2:11:25 AM7/2/15
to django-...@googlegroups.com
#25046: Initial SQL scripts (not data) for testing
---------------------------------+-----------------------------------------
Reporter: liwee | Owner: nobody
Type: New feature | Status: new
Component: Testing | Version: 1.8
framework |
Severity: Normal | Keywords: testing view create_test_db
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------------------------
I use quite a lot of database view (i.e. CREATE VIEW my_view) in my
project. The only way to test the views is set keepdb=True, load the views
and manage the test_database as a static entity forever. Ideally, I would
prefer creating a clean database from both fixtures and database views
whenever I need to run a test. Is it possible to add an option to load a
sql script on create_test_db?

--
Ticket URL: <https://code.djangoproject.com/ticket/25046>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 2, 2015, 2:15:57 AM7/2/15
to django-...@googlegroups.com
#25046: Initial SQL scripts (not data) for testing
-------------------------------------+-------------------------------------

Reporter: liwee | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 1.8
Severity: Normal | Resolution:
Keywords: testing view | Triage Stage:
create_test_db | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by liwee):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Old description:

> I use quite a lot of database view (i.e. CREATE VIEW my_view) in my
> project. The only way to test the views is set keepdb=True, load the
> views and manage the test_database as a static entity forever. Ideally, I
> would prefer creating a clean database from both fixtures and database
> views whenever I need to run a test. Is it possible to add an option to
> load a sql script on create_test_db?

New description:

I use quite a lot of database view (i.e. CREATE VIEW my_view) in my
project. The only way to test the views is set keepdb=True, load the views

and manage the test_database as a static entity forever. Ideally, creating


a clean database from both fixtures and database views whenever I need to

run a test makes more sense. Is it possible to add an option to load a sql
script on create_test_db?

--

--
Ticket URL: <https://code.djangoproject.com/ticket/25046#comment:1>

Django

unread,
Jul 2, 2015, 2:49:10 AM7/2/15
to django-...@googlegroups.com
#25046: Initial SQL scripts (not data) for testing
-------------------------------------+-------------------------------------

Reporter: liwee | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 1.8
Severity: Normal | Resolution:
Keywords: testing view | Triage Stage:
create_test_db | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by shaib):

How do you create the views in the non-test database?

Ideally, you'd do that in migrations with `RunSQL` operations. If you did
that, you'd get the same views in your test databases.

If this solves your problem, please close the ticket as "invalid". If it
doesn't, please elaborate.

--
Ticket URL: <https://code.djangoproject.com/ticket/25046#comment:2>

Django

unread,
Jul 2, 2015, 4:42:11 AM7/2/15
to django-...@googlegroups.com
#25046: Initial SQL scripts (not data) for testing
-------------------------------------+-------------------------------------

Reporter: liwee | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 1.8
Severity: Normal | Resolution:
Keywords: testing view | Triage Stage:
create_test_db | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by liwee):

The view script can be quite long, please see attached file. I keep the
sql view script just above the relevant model in model.py. The
contrib.admin takes cares of the UI. If a view change is required, I run
the drop / create view script directly within the database, correcting
errors I see on the spot.

[https://docs.djangoproject.com/en/1.8/howto/initial-data/]
''If you require data for a test case, you should add it using either a
test fixture, or programmatically add it during the setUp() of your test
case.''

I wasn't aware that another method exist in RunSQL, thank you. To
summarize, I would need to export the view schema from the live database,
save the file, read the file and pass the contents to RunSQL to fake a
migration whenever I need to test my views. Would all these excessive
migration cause a problem? Is there anything wrong with my interpretation
of RunSQL?

It just seems cleaner if I can get create_test_db to read the exported
view schema directly or perhaps for create_test_db to extract the view
schema directly from the live database.

--
Ticket URL: <https://code.djangoproject.com/ticket/25046#comment:3>

Django

unread,
Jul 2, 2015, 4:42:28 AM7/2/15
to django-...@googlegroups.com
#25046: Initial SQL scripts (not data) for testing
-------------------------------------+-------------------------------------

Reporter: liwee | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 1.8
Severity: Normal | Resolution:
Keywords: testing view | Triage Stage:
create_test_db | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by liwee):

* Attachment "1.PNG" added.

Django

unread,
Jul 2, 2015, 11:54:00 AM7/2/15
to django-...@googlegroups.com
#25046: Initial SQL scripts (not data) for testing
-------------------------------------+-------------------------------------
Reporter: liwee | Owner: nobody
Type: New feature | Status: closed

Component: Testing framework | Version: 1.8
Severity: Normal | Resolution: invalid

Keywords: testing view | Triage Stage:
create_test_db | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => invalid


Comment:

It sounds like you are on the right track with your understanding. If you
need further help, please see TicketClosingReasons/UseSupportChannels.

--
Ticket URL: <https://code.djangoproject.com/ticket/25046#comment:4>

Reply all
Reply to author
Forward
0 new messages