switch between standard and testing database?

111 views
Skip to first unread message

Mirek Zvolský

unread,
Jul 18, 2016, 5:55:57 AM7/18/16
to web...@googlegroups.com
1.

I use postgres database dbapp
I am trying to make splinter tests and want to run them over the 2nd database dbapp_tests.

When I switch to the testing database (which is EMPTY include the auth_user table)
I am logged in thanks the session:
auth.user and auth.user_id are both set (but auth_user is EMPTY).

Can I avoid this, without deleting sessions for the normal work?



I have ideas for some workarounds, like:

- populate dbapp_tests with single auth_user row (mine...)

- move sessions into database



But I'm asking, if somebody has idea how to switch both databases more clever.
Thank you...


2.

I have no good idea how to easy switch between normal and testing database.
At this time I use port (8000/8001), but this works on development, not on production.
What is better?

Mirek Zvolský

unread,
Jul 19, 2016, 9:40:09 AM7/19/16
to web2py-users
I will describe again, what I want:

I have url <app>/plugin_splinter/tests
with checkboxes:
  - chrome
  - firefox

  - test localhost:8000
  - test production

  - all webtests --or--
  - webtest1 , - webtest2, ...

Then I want run webtests (splinter+selenium), navigate to different actions (and type or click).
But I need to open TESTING database, not the MAIN database.

At this time I have changed the architecture to use of Scheduler (which works well),
and I think, I will do following:

- appconfig.ini : test_IP : nnn.nnn.nnn.nnn
   
- <app>/plugin_splinter.py
   if form.process().accepted:
      # dynamically create a file models/_tests.py with something like: testDb=True
      # schedule tests here

- in db.py I will open MAIN or TESTING datatabase based on: testDb and request.ip==test_IP.

I hope previous will work good for me.
But if somebody has better idea or some comment ....... ? --thanks in advance







Dne pondělí 18. července 2016 11:55:57 UTC+2 Mirek Zvolský napsal(a):

Mirek Zvolský

unread,
Jul 26, 2016, 6:24:44 AM7/26/16
to web2py-users
Finally I realized it using

session.testing = False / True

Because I think the resulting plugin_splinter is interesting (for somebody),
I hope I will publish it and write more later.






Dne pondělí 18. července 2016 11:55:57 UTC+2 Mirek Zvolský napsal(a):
1.

Richard Vézina

unread,
Jul 27, 2016, 10:18:34 AM7/27/16
to web2py-users
Hello Mirek,

Did you give a look at how web2py.test is doing that?

Bassically, a folder is created with the name of the app when at tests launch if the folder is there the testing database is used...

Richard

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mirek Zvolský

unread,
Aug 10, 2016, 11:32:32 AM8/10/16
to web2py-users
Thank you.
I have found this inside:

def is_running_under_test(request, appname):
   
if request.get('_running_under_test') or testfile_exists(appname):
       
return True
   
else:
       
return False

But I am not sure what mean both parts of the condition.

I think this run on the TESTED machine, so 2nd part - testfile_exists() will cause (I think) that such machine cannot serve non-test requests at same time.

So I think more important is the 1st part - request.get('_running_under_test')
But how will I set from the TESTING machine request,_running_under_test on the TESTED machine?




Dne středa 27. července 2016 16:18:34 UTC+2 Richard napsal(a):

Richard Vézina

unread,
Aug 10, 2016, 12:04:02 PM8/10/16
to web2py-users
Here how I realize it :

# Production
if request.env.web2py_path.split('/')[2] == 'www-data' and request.application == 'app_name':
    # print 'Prod...'
    db = DAL('postgres://username_prod:pass...@127.0.0.1:5432/dbname',
             pool_size=1,
             migrate_enabled=False,
             lazy_tables=True)
# Systeme under test
elif web2pytest.is_running_under_test(request, request.application):
    # print 'Testing mode...'
    # When running under test, db cannot be ':memory:'
    # because it is recreated in each request and a webclient test
    # can make many requests to validate a single scenario.
             migrate_enabled=False,
             lazy_tables=True
             )
# Normal dev operation
elif request.env.web2py_path.split('/')[2] == 'username' and request.application.startswith('dbname'):
    # print 'Dev mode...'
             migrate_enabled=False,
             lazy_tables=True
             )
# Prod DEMO Application
elif request.env.web2py_path.split('/')[2] == 'www-data' and request.application == 'dbname_demo':
    # print 'Prod demo...'
             pool_size=1,
             migrate_enabled=False,
             lazy_tables=True)

Richard

To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.

Richard Vézina

unread,
Aug 10, 2016, 12:06:36 PM8/10/16
to web2py-users
About your question, I think he maybe had try an approach where he was passing some parameters in request...

Richard
Reply all
Reply to author
Forward
0 new messages