[web2py] How to create a new DAL connection?

2012-09-16 Thread spiffytech
I'm writing a script that runs in the web2py environment and accesses my 
database through the DAL. Because my script is multithreaded and the DB 
logic is not easily isolated to a single thread, I need multiple 
connections to the DB, which means multiple DAL instances. I see I can do 
this:

DAL('sqlite://storage.sqlite',folder='path/to/app/databases', auto_import=True))

but then I don't get validators, etc. Is there a way to create a new DAL 
instance based off of one I already have, instead of my script needing to 
run through the define_tables() stuff again for each DAL instance I need?

-- 





Re: [web2py] Re: Major speed improvement need testers

2012-08-22 Thread spiffytech
I'd like to cast my vote against implementing something as core as Storage 
in C, as that hinders web2py's support for PyPy and other alternate 
runtimes that don't play nice with C modules.


On Wednesday, August 22, 2012 1:15:45 PM UTC-4, Massimo Di Pierro wrote:
>
> Some more info the issue page claims this issue is fixed in pyhton 
> 2.7.3 but my tests and Michele's test revealed it is not in fact fixed.
>
> I changed trunk gain:
> - reverted all improvements to dal.py except for lazy tables
> - made the improvement to Storage conditional (it detects the bugs and 
> uses the fast or the slow version accordingly).
>
> Problem is that I am not aware of a python version without the bug (2.7.3 
> is the latest in 2.x and has it). 
>
> We will try look for other solutions but this does not look good.
>
> There is one more option... implement our own Storage from scratch using 
> the C-API. I am sure we can make it very fast and meet our needs.  I do not 
> have enough experience with this but I will try look into it. Will not 
> happen in web2py 2.0.
>
> Massimo
>
> On Wednesday, 22 August 2012 11:50:49 UTC-5, LightDot wrote:
>>
>> There are many hosting companies that won't upgrade OS provided python 
>> versions for the lifetime of a server. Good luck requesting a python 
>> upgrade on a Red Hat / CentOS / Scientific Linux server, this simply won't 
>> happen.
>>
>> This is the situation at the moment:
>>
>> RHEL 6: python 2.6.5
>> Debian 6: python 2.6.6
>> Ubuntu 10.4 LTS: python 2.6.5
>> Ubuntu 12.4 LTS: python 2.7.3
>>
>> The proper way to handle such a change would be to make this feature 
>> optional and file bug reports with all linux distributions that use python 
>> < 2.7.3 at the same time. I'm sure Red Hat would backport this into RHEL 6, 
>> which takes care of CentOS, SL and others. Can't say about Debian or 
>> Ubuntu, but I don't see why not at least try.
>>
>> But, should these kind of major changes even be considered on the eve of 
>> the new release..?
>>
>> Regards,
>> Ales
>>
>>
>> On Wednesday, August 22, 2012 6:22:06 PM UTC+2, Khalil KHAMLICHI wrote:
>>>
>>> if we go back the future will not wait for us, and we will become 
>>> obsolete.
>>> Python versions are easy to manage on absolutely any platform or OS, I 
>>> say we keep it.
>>>
>>>
>>> On Wed, Aug 22, 2012 at 2:52 PM, Anthony  wrote:
>>>
 If we can't fix the memory leak, can we at least have the code detect 
 the Python version and use the faster Storage in case >= 2.7.3, or are 
 there too many places where code would need to change to make that 
 practical?

 Anthony


 On Wednesday, August 22, 2012 9:28:59 AM UTC-4, Massimo Di Pierro wrote:
>
> We run into a major problem. The Storage improvements in trunk cause a 
> memory leak.
> This is a python bug and it was discovered in 2006.:
>
> 
> http://bugs.python.org/**issue1469629
>
> Apparently this was only fixed in python 3.2 and python 2.7.3.
>
> Not sure what to do but at the moment I do not see any solution than 
> removing the improvements.
>
> massimo
>
>
>
>
> On Wednesday, 22 August 2012 01:44:44 UTC-5, Johann Spies wrote:
>>
>> I hope that web2py 2.0 will not be released without these 
>> improvements even if it means that testing it will delay the release. 
>>
>> Thanks to the developers for their initiatives and ingenuity.
>>
>> Regards
>> Johann
>> -- 
>> Because experiencing your loyal love is better than life itself, 
>> my lips will praise you.  (Psalm 63:3)
>>
>>  -- 
  
  
  

>>>
>>>

-- 





[web2py] Re: whats the state of NoSQL in web2py 2.0

2012-08-20 Thread spiffytech
Are there any restrictions on what operations can/cannot be performed with 
MongoDB through the DAL? E.g., I don't think MongoDB has a native JOIN 
equivalent- does web2py emulate one?


On Monday, August 20, 2012 9:02:12 AM UTC-4, Massimo Di Pierro wrote:
>
> db=DAL('mongodb://127.0.0.1:5984/db')
>
> they try some models and other dal expressions.
>
> On Monday, 20 August 2012 00:36:48 UTC-5, Pystar wrote:
>>
>> how do I test it? I have 2 days free I can use working on that. I need 
>> some hints
>>
>> On Monday, August 20, 2012 5:48:22 AM UTC+1, Massimo Di Pierro wrote:
>>>
>>> mongodb is supposed to work but although many people requested it, I do 
>>> not know of many people who tested it.
>>>
>>>
>>>
>>> On Sunday, 19 August 2012 23:23:51 UTC-5, Pystar wrote:

 I would like to know the state of NoSQL support in version 2.0. Is it 
 production ready or still on the todo list?
>>>
>>>

-- 





[web2py] Re: Is copying request.env in LOAD() reliable?

2012-08-20 Thread spiffytech

>
> I assume you're using LOAD() with ajax=False (the default), correct? 

Correct.
 

> I think Massimo generally discourages use of non-ajax components

What's the rationale behind this?
 

> LOAD('default', 'mycomponent', vars=dict(rows=rows))
>

That did the trick nicely, and feels much less hacky. Thanks!

-- 





[web2py] Re: Route to static file fails on App Engine

2012-08-19 Thread spiffytech
Looking inside apps.yaml, I see that that idea is exactly what makes 
/init/static/stuff.txt work. Added an entry for /stuff.txt and it works 
now. Thanks!


On Saturday, August 18, 2012 9:45:11 PM UTC-4, howesc wrote:
>
> hrm.i've not used the 'r' in my routesi just put the strings in 
> and it seems to do what i want.
>
> on GAE you might rather do this in app.yaml as you save yourself loading 
> web2py to serve a static file.
>
> cfh
>
> On Friday, August 17, 2012 8:14:08 PM UTC-7, spiffytech wrote:
>>
>> I'm trying to make routes.py send certain URLs to static files, but I 
>> can't make it work on App Engine (neither the development server nor a 
>> production deployment). The following route works with Rocket, and not App 
>> Engine, failing with 'invalid request' :
>>
>> routes_in = (
>>  (r'.*stuff.txt.*', r'/init/static/stuff.txt'),
>> )
>> # Tested as http://localhost:8080/stuff.txt
>>
>> http://localhost:8080/init/static/stuff.txt works on App Engine, which 
>> means App Engine can at least see the file and knows what to do with it. 
>>
>> I'm running web2py trunk commit a7268ff.
>>
>

-- 





[web2py] Is copying request.env in LOAD() reliable?

2012-08-19 Thread spiffytech
For efficiency and simplicity, I would like to pass Python variables (such 
as Rows objects) through LOAD() calls and have them accessible from the 
loaded component. After checking the LOAD() source code, I found I could do 
this by inserting the variables into request.env, since LOAD copies the 
original request.env into the component's new request.env.

The copying of request.env doesn't seem to be an advertised part of how 
LOAD() works. Can I count on this to work, even through future 
modifications/rewrites of LOAD(), or is this an accidental feature I 
shouldn't rely on?

-- 





[web2py] Route to static file fails on App Engine

2012-08-17 Thread spiffytech
I'm trying to make routes.py send certain URLs to static files, but I can't 
make it work on App Engine (neither the development server nor a production 
deployment). The following route works with Rocket, and not App Engine:

routes_in = (
 (r'.*stuff.txt.*', r'/init/static/stuff.txt'),
)
# Tested as http://localhost:8080/stuff.txt

http://localhost:8080/init/static/stuff.txt works on App Engine, which 
means App Engine can at least see the file and knows what to do with it. 

I'm running web2py trunk commit a7268ff.

-- 





Re: [web2py] Re: Model-less approach should be standadized in web2py in future releases ...

2012-08-15 Thread spiffytech
Well done, sir! I think this is an excellent way to solve the problem. 
Model-less is still there for anyone who wants it, but with LazyDAL web2py 
fixes the performance hit it takes from models while retaining the 
simplicity, lack of boilerplate code, and fast implementation times that 
set it apart from other frameworks!


On Wednesday, August 15, 2012 6:06:46 PM UTC-4, rochacbruno wrote:
>
>
>
> On Wed, Aug 15, 2012 at 5:52 PM, pbreit 
> > wrote:
>
>> I disagree. Current model definition works fine for vast majority of 
>> projects and the alternatives are still much too confusing IMO.
>
>
> I just proposed a solution for testing: 
> http://rochacbruno.com.br/lazy-dal-beta-working/ 
>  

-- 





[web2py] Re: DAL belongs() fails on App Engine

2012-08-14 Thread spiffytech
Yep, that fixes it! Thanks for your work on that!


On Tuesday, August 14, 2012 6:18:29 PM UTC-4, howesc wrote:
>
> i added a patch against trunk to the ticket.  spiffytech - can you see if 
> that works for you?
>
> cfh
>
> On Monday, August 13, 2012 12:20:02 AM UTC-7, howesc wrote:
>>
>> we do special query handling on the key field, so i suspect the multiple 
>> filters on key is wonky.  i'll try and look at this in the next couple of 
>> days
>>
>> thanks for reporting, and thanks for your patience guiding us through it. 
>> :)
>>
>> christian
>>
>> On Sunday, August 12, 2012 8:01:29 PM UTC-7, spiffytech wrote:
>>>
>>> Yes, I've verified that this can be done. The below query works in the 
>>> App Engine Datastore Viewer (note that it only worked once I manually 
>>> created the index in index.yaml and deployed it; web2py did not 
>>> automatically create the appropriate index:
>>>
>>> SELECT * FROM posts WHERE __key__ IN (KEY('posts', 3), KEY('posts', 4), 
>>> KEY('posts', 1003)) and post_date <= DATETIME('2012-08-12 00:00:00') ORDER 
>>> BY post_date DESC
>>>
>>>
>>> On Sunday, August 12, 2012 9:56:20 PM UTC-4, Anthony wrote:
>>>>
>>>> How would you do the query in GQL? Have you confirmed that it can be 
>>>> done?
>>>>
>>>> Anthony
>>>>
>>>> On Sunday, August 12, 2012 9:23:39 PM UTC-4, spiffytech wrote:
>>>>>
>>>>> I tested with your suggested orderby, but the outcome was the same.
>>>>>
>>>>> I tested with the query as you wrote it below, with no common_filter, 
>>>>> and the query still failed. Since that's a pretty straightforward query 
>>>>> that should work, this seems like a bug to me, so I filed a web2py bug 
>>>>> report: http://code.google.com/p/web2py/issues/detail?id=930
>>>>>
>>>>>
>>>>> On Thursday, August 9, 2012 5:39:14 PM UTC-4, howesc wrote:
>>>>>>
>>>>>> i had to look up common_filters.based on your experience i would 
>>>>>> assume that this is being implemented as a query filter rather than 
>>>>>> getting 
>>>>>> results from the DB and then filtering them.  so what is must be causing 
>>>>>> in 
>>>>>> your case is:
>>>>>>
>>>>>> posts = db((db.posts.id.belongs(post_ids)) & 
>>>>>> (db.posts.post_date<=request.now)).select(db.posts.ALL,orderby=db.posts.post_date,
>>>>>>  cache
>>>>>> =(cache.ram, 60))
>>>>>>
>>>>>> it *might* work if you put an orderby on that is 
>>>>>> db.posts.id|db.posts.post_date  
>>>>>> i'm not sure.  you might have to remove the common filter for this query 
>>>>>> and then filter the results. (i don't have experience with common 
>>>>>> filters 
>>>>>> and how they are implemented)
>>>>>>
>>>>>> GAE has a restriction on IN queries (web2py belongs queries) that 
>>>>>> they have no more than 30 items in the list.  "because i said so" says 
>>>>>> google.
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Thursday, August 9, 2012 1:57:13 PM UTC-7, spiffytech wrote:
>>>>>>>
>>>>>>> I've narrowed the problem down further- the exception is caused by a 
>>>>>>> common_filter attached to my posts table:
>>>>>>>
>>>>>>> common_filter = lambda query: db.posts.post_date <= request.now
>>>>>>>
>>>>>>> I'm not sure why that would trigger the orderby error, though. 
>>>>>>>
>>>>>>> Also, is there some significance to limiting the belongs lists to 30 
>>>>>>> items?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Thursday, August 9, 2012 4:24:13 PM UTC-4, howesc wrote:
>>>>>>>>
>>>>>>>> the query and the error message do not match.  your query has no 
>>>>>>>> orderby, yet the error message suggests there is an orderby property 
>>>>>>>> set.  
>>>>>>>> this confuses me.
>>>>>>>>
>>>>>>>> i do:
>>>>>>>>
>>>>>>>> db(db.table.id.belongs([list of items not more than 30 
>>>>>>>> long])).select()
>>>>>>>>
>>>>>>>> all the time on GAE and it works for me (latest stable web2py, and 
>>>>>>>> the last time i checked trunk though that was a few weeks ago)
>>>>>>>>
>>>>>>>> note that cache does nothing on selects on GAE due to the inability 
>>>>>>>> to serialize Rows objects to memcache (at least i think that is the 
>>>>>>>> limitation)
>>>>>>>>
>>>>>>>> cfh
>>>>>>>>
>>>>>>>> On Thursday, August 9, 2012 10:40:33 AM UTC-7, spiffytech wrote:
>>>>>>>>>
>>>>>>>>> I'm trying to use the DAL belongs clause on App Engine and am 
>>>>>>>>> getting an error. 
>>>>>>>>>
>>>>>>>>> posts = db(db.posts.id.belongs(post_ids)).select(db.posts.ALL,cache
>>>>>>>>> =(cache.ram, 60))
>>>>>>>>>
>>>>>>>>> Produces:
>>>>>>>>>
>>>>>>>>> BadArgumentError: First ordering property must be the same as 
>>>>>>>>> inequality filter property, if specified for this query; received 
>>>>>>>>> __key__, 
>>>>>>>>> expected post_date
>>>>>>>>>
>>>>>>>>> Some Googling suggests this can be due to not providing a sort 
>>>>>>>>> key. I tried orderby=db.posts.post_date with no success. What 
>>>>>>>>> could be going wrong?
>>>>>>>>>
>>>>>>>>> I'm using the latest trunk web2py, but tested all the way back to 
>>>>>>>>> 1.99.3.
>>>>>>>>>
>>>>>>>>

-- 





[web2py] Re: DAL belongs() fails on App Engine

2012-08-12 Thread spiffytech
Yes, I've verified that this can be done. The below query works in the App 
Engine Datastore Viewer (note that it only worked once I manually created 
the index in index.yaml and deployed it; web2py did not automatically 
create the appropriate index:

SELECT * FROM posts WHERE __key__ IN (KEY('posts', 3), KEY('posts', 4), 
KEY('posts', 1003)) and post_date <= DATETIME('2012-08-12 00:00:00') ORDER 
BY post_date DESC


On Sunday, August 12, 2012 9:56:20 PM UTC-4, Anthony wrote:
>
> How would you do the query in GQL? Have you confirmed that it can be done?
>
> Anthony
>
> On Sunday, August 12, 2012 9:23:39 PM UTC-4, spiffytech wrote:
>>
>> I tested with your suggested orderby, but the outcome was the same.
>>
>> I tested with the query as you wrote it below, with no common_filter, and 
>> the query still failed. Since that's a pretty straightforward query that 
>> should work, this seems like a bug to me, so I filed a web2py bug report: 
>> http://code.google.com/p/web2py/issues/detail?id=930
>>
>>
>> On Thursday, August 9, 2012 5:39:14 PM UTC-4, howesc wrote:
>>>
>>> i had to look up common_filters.based on your experience i would 
>>> assume that this is being implemented as a query filter rather than getting 
>>> results from the DB and then filtering them.  so what is must be causing in 
>>> your case is:
>>>
>>> posts = db((db.posts.id.belongs(post_ids)) & 
>>> (db.posts.post_date<=request.now)).select(db.posts.ALL,orderby=db.posts.post_date,
>>>  cache
>>> =(cache.ram, 60))
>>>
>>> it *might* work if you put an orderby on that is 
>>> db.posts.id|db.posts.post_date  
>>> i'm not sure.  you might have to remove the common filter for this query 
>>> and then filter the results. (i don't have experience with common filters 
>>> and how they are implemented)
>>>
>>> GAE has a restriction on IN queries (web2py belongs queries) that they 
>>> have no more than 30 items in the list.  "because i said so" says google.
>>>
>>>
>>>
>>> On Thursday, August 9, 2012 1:57:13 PM UTC-7, spiffytech wrote:
>>>>
>>>> I've narrowed the problem down further- the exception is caused by a 
>>>> common_filter attached to my posts table:
>>>>
>>>> common_filter = lambda query: db.posts.post_date <= request.now
>>>>
>>>> I'm not sure why that would trigger the orderby error, though. 
>>>>
>>>> Also, is there some significance to limiting the belongs lists to 30 
>>>> items?
>>>>
>>>>
>>>>
>>>> On Thursday, August 9, 2012 4:24:13 PM UTC-4, howesc wrote:
>>>>>
>>>>> the query and the error message do not match.  your query has no 
>>>>> orderby, yet the error message suggests there is an orderby property set. 
>>>>>  
>>>>> this confuses me.
>>>>>
>>>>> i do:
>>>>>
>>>>> db(db.table.id.belongs([list of items not more than 30 long])).select()
>>>>>
>>>>> all the time on GAE and it works for me (latest stable web2py, and the 
>>>>> last time i checked trunk though that was a few weeks ago)
>>>>>
>>>>> note that cache does nothing on selects on GAE due to the inability to 
>>>>> serialize Rows objects to memcache (at least i think that is the 
>>>>> limitation)
>>>>>
>>>>> cfh
>>>>>
>>>>> On Thursday, August 9, 2012 10:40:33 AM UTC-7, spiffytech wrote:
>>>>>>
>>>>>> I'm trying to use the DAL belongs clause on App Engine and am getting 
>>>>>> an error. 
>>>>>>
>>>>>> posts = db(db.posts.id.belongs(post_ids)).select(db.posts.ALL, cache
>>>>>> =(cache.ram, 60))
>>>>>>
>>>>>> Produces:
>>>>>>
>>>>>> BadArgumentError: First ordering property must be the same as 
>>>>>> inequality filter property, if specified for this query; received 
>>>>>> __key__, 
>>>>>> expected post_date
>>>>>>
>>>>>> Some Googling suggests this can be due to not providing a sort key. I 
>>>>>> tried orderby=db.posts.post_date with no success. What could be 
>>>>>> going wrong?
>>>>>>
>>>>>> I'm using the latest trunk web2py, but tested all the way back to 
>>>>>> 1.99.3.
>>>>>>
>>>>>

-- 





[web2py] Re: DAL belongs() fails on App Engine

2012-08-12 Thread spiffytech
I tested with your suggested orderby, but the outcome was the same.

I tested with the query as you wrote it below, with no common_filter, and 
the query still failed. Since that's a pretty straightforward query that 
should work, this seems like a bug to me, so I filed a web2py bug report: 
http://code.google.com/p/web2py/issues/detail?id=930


On Thursday, August 9, 2012 5:39:14 PM UTC-4, howesc wrote:
>
> i had to look up common_filters.based on your experience i would 
> assume that this is being implemented as a query filter rather than getting 
> results from the DB and then filtering them.  so what is must be causing in 
> your case is:
>
> posts = db((db.posts.id.belongs(post_ids)) & 
> (db.posts.post_date<=request.now)).select(db.posts.ALL,orderby=db.posts.post_date,
>  cache
> =(cache.ram, 60))
>
> it *might* work if you put an orderby on that is 
> db.posts.id|db.posts.post_date  
> i'm not sure.  you might have to remove the common filter for this query 
> and then filter the results. (i don't have experience with common filters 
> and how they are implemented)
>
> GAE has a restriction on IN queries (web2py belongs queries) that they 
> have no more than 30 items in the list.  "because i said so" says google.
>
>
>
> On Thursday, August 9, 2012 1:57:13 PM UTC-7, spiffytech wrote:
>>
>> I've narrowed the problem down further- the exception is caused by a 
>> common_filter attached to my posts table:
>>
>> common_filter = lambda query: db.posts.post_date <= request.now
>>
>> I'm not sure why that would trigger the orderby error, though. 
>>
>> Also, is there some significance to limiting the belongs lists to 30 
>> items?
>>
>>
>>
>> On Thursday, August 9, 2012 4:24:13 PM UTC-4, howesc wrote:
>>>
>>> the query and the error message do not match.  your query has no 
>>> orderby, yet the error message suggests there is an orderby property set.  
>>> this confuses me.
>>>
>>> i do:
>>>
>>> db(db.table.id.belongs([list of items not more than 30 long])).select()
>>>
>>> all the time on GAE and it works for me (latest stable web2py, and the 
>>> last time i checked trunk though that was a few weeks ago)
>>>
>>> note that cache does nothing on selects on GAE due to the inability to 
>>> serialize Rows objects to memcache (at least i think that is the limitation)
>>>
>>> cfh
>>>
>>> On Thursday, August 9, 2012 10:40:33 AM UTC-7, spiffytech wrote:
>>>>
>>>> I'm trying to use the DAL belongs clause on App Engine and am getting 
>>>> an error. 
>>>>
>>>> posts = db(db.posts.id.belongs(post_ids)).select(db.posts.ALL, cache=(
>>>> cache.ram, 60))
>>>>
>>>> Produces:
>>>>
>>>> BadArgumentError: First ordering property must be the same as 
>>>> inequality filter property, if specified for this query; received __key__, 
>>>> expected post_date
>>>>
>>>> Some Googling suggests this can be due to not providing a sort key. I 
>>>> tried orderby=db.posts.post_date with no success. What could be going 
>>>> wrong?
>>>>
>>>> I'm using the latest trunk web2py, but tested all the way back to 
>>>> 1.99.3.
>>>>
>>>

-- 





[web2py] Re: DAL belongs() fails on App Engine

2012-08-09 Thread spiffytech
I've narrowed the problem down further- the exception is caused by a 
common_filter attached to my posts table:

common_filter = lambda query: db.posts.post_date <= request.now

I'm not sure why that would trigger the orderby error, though. 

Also, is there some significance to limiting the belongs lists to 30 items?



On Thursday, August 9, 2012 4:24:13 PM UTC-4, howesc wrote:
>
> the query and the error message do not match.  your query has no orderby, 
> yet the error message suggests there is an orderby property set.  this 
> confuses me.
>
> i do:
>
> db(db.table.id.belongs([list of items not more than 30 long])).select()
>
> all the time on GAE and it works for me (latest stable web2py, and the 
> last time i checked trunk though that was a few weeks ago)
>
> note that cache does nothing on selects on GAE due to the inability to 
> serialize Rows objects to memcache (at least i think that is the limitation)
>
> cfh
>
> On Thursday, August 9, 2012 10:40:33 AM UTC-7, spiffytech wrote:
>>
>> I'm trying to use the DAL belongs clause on App Engine and am getting an 
>> error. 
>>
>> posts = db(db.posts.id.belongs(post_ids)).select(db.posts.ALL, cache=(
>> cache.ram, 60))
>>
>> Produces:
>>
>> BadArgumentError: First ordering property must be the same as inequality 
>> filter property, if specified for this query; received __key__, expected 
>> post_date
>>
>> Some Googling suggests this can be due to not providing a sort key. I 
>> tried orderby=db.posts.post_date with no success. What could be going 
>> wrong?
>>
>> I'm using the latest trunk web2py, but tested all the way back to 1.99.3.
>>
>

-- 





[web2py] DAL belongs() fails on App Engine

2012-08-09 Thread spiffytech
I'm trying to use the DAL belongs clause on App Engine and am getting an 
error. 

posts = db(db.posts.id.belongs(post_ids)).select(db.posts.ALL, cache=(cache.
ram, 60))

Produces:

BadArgumentError: First ordering property must be the same as inequality 
filter property, if specified for this query; received __key__, expected 
post_date

Some Googling suggests this can be due to not providing a sort key. I tried 
orderby=db.posts.post_date with no success. What could be going wrong?

I'm using the latest trunk web2py, but tested all the way back to 1.99.3.

-- 





[web2py] Re: web2py on appfog

2012-08-03 Thread spiffytech
Followup:

I contacted AppFog support via their live chat to get a few questions 
answered:

   - Confirmed: You can't buy more storage (yet). It's a priority for them, 
   though.
   - An app's instances don't all see the same copy of the filesystem. 
   That's less of a problem than the fact that:
   - Your writable filesystem isn't persistent. AppFog recommend it be 
   devoted strictly to your codebase, with any static assets being placed on 
   something like S3.
   - Confirmed: They don't provide cron. I attempted to use web2py cron in 
   my AppFog app, but I can't make it work. I haven't tried very hard to 
   figure out why.

I was also able to get my app running on their Rackspace instances- it 
seems their `af` command doesn't work right with the --debug flag, which I 
was using to see why things weren't working :P `af start ` worked fine.

Lastly, the Apache Benchmark numbers I presented last time lasted through 
at least Monday night. When I tested tonight, they had fallen to around 1 
second average load time- far more reasonable. I asked AppFog support about 
the high load times last weekend, and they couldn't pinpoint a specific 
issue, but said they had been fiddling with things in response to opening 
to the public and I might have just caught them at a bad time. I'll give 
them the benefit of the doubt on that, but I'd still keep an eye on those 
load times for a while before assuming an app will perform reasonably on 
their service. 

So, now that I got a Rackspace deployment working, and their hosting isn't 
slower than molasses, I'm a little more optimistic about AppFog. 


On Sunday, July 29, 2012 12:04:06 AM UTC-4, spiffytech wrote:
>
> Tonight I threw up a copy of my personal site, just to see if AppFog is 
> worth looking into. Perhaps my experience would have been better if I tried 
> during business hours while their live chat support was open, but I don't 
> plan to use AppFog after this experience.
>
> The highlights:
>
>- They advertise unlimited apps, but you're limited by how many apps 
>you can squeeze into the RAM your account gets. Sure, you don't have the 
>hard cap of 10 apps like App Engine (still?) gives you, but "unlimited" 
>isn't really true
>- AppFog's founder wants you to 
> believe<http://blog.appfog.com/if-paas-is-expensive-and-slow-why-not-use-a-vps/>they're
>  proving PaaS doesn't have to be slow and expensive, but I found 
>AppFog to be slow, and their pricing<https://console.appfog.com/pricing> 
> gets 
>nutty-expensive very fast
>- Getting my app working at all was a trying experience, and AppFog 
>doesn't offer much in the way of documentation or debug output to help you
>- No sign of a cron system, so you'll be relying on web2py's built-in 
>cron (didn't check if it works there, but I assume so)
>- All apps have a 100MB disk limit, and I don't see a way to buy more. 
>Better hope you're apps don't get very big!
>- You do have a writable filesystem, for what that's worth with the 
>100MB disk use limit. I didn't check whether all instances access the same 
>FS (that's kind of an important way so design the service)
>
> My conclusion: If you want a free place to host something that (really, 
> really) doesn't need to be performant, AppFog is a decent choice because:
>
>- It has a writable filesystem, which sets it apart from App Engine
>- It has free MySQL (App Engine started charging for MySQL in June), 
>which sets it apart from App Engine
>- It looks more likely to stick around than some of the other free web 
>host services that I've seen mentioned here
>
> However, to get that free hosting you'll have to put up with terrible 
> performance (or highly variable performance if it magically speeds up by 
> tomorrow morning), poor documentation, and a tricky and opaque setup 
> procedure.
>
> On to doing stuff, and statistics!
>
> First off, I could not find any links on their site instructing me on how 
> to configure a Python app to work on AppFog. I eventually gave up and 
> resorted to Googling for a tutorial, which led me to this 
> section<http://docs.appfog.com/frameworks/python>in AppFog's docs. Not sure 
> how you are supposed to find that.
>
> That link isn't too helpful, though- it shows how to make a Flask site 
> that works on AppFog, and links to working Bottle and Django sites, but 
> doesn't spell out how to make a generic WSGI site work. To make my simple 
> web2py site work, I had to do the following:
>
> mv wsgihandler.py wsgi.py  # AppFog needs wsgi.py. I tried a

[web2py] Re: web2py on appfog

2012-07-28 Thread spiffytech
Tonight I threw up a copy of my personal site, just to see if AppFog is 
worth looking into. Perhaps my experience would have been better if I tried 
during business hours while their live chat support was open, but I don't 
plan to use AppFog after this experience.

The highlights:

   - They advertise unlimited apps, but you're limited by how many apps you 
   can squeeze into the RAM your account gets. Sure, you don't have the hard 
   cap of 10 apps like App Engine (still?) gives you, but "unlimited" isn't 
   really true
   - AppFog's founder wants you to 
believethey're
 proving PaaS doesn't have to be slow and expensive, but I found 
   AppFog to be slow, and their pricing  
gets 
   nutty-expensive very fast
   - Getting my app working at all was a trying experience, and AppFog 
   doesn't offer much in the way of documentation or debug output to help you
   - No sign of a cron system, so you'll be relying on web2py's built-in 
   cron (didn't check if it works there, but I assume so)
   - All apps have a 100MB disk limit, and I don't see a way to buy more. 
   Better hope you're apps don't get very big!
   - You do have a writable filesystem, for what that's worth with the 
   100MB disk use limit. I didn't check whether all instances access the same 
   FS (that's kind of an important way so design the service)

My conclusion: If you want a free place to host something that (really, 
really) doesn't need to be performant, AppFog is a decent choice because:

   - It has a writable filesystem, which sets it apart from App Engine
   - It has MySQL, which sets it apart from App Engine
   - It looks more likely to stick around than some of the other free web 
   host services that I've seen mentioned here

However, to get that free hosting you'll have to put up with terrible 
performance (or highly variable performance if it magically speeds up by 
tomorrow morning), poor documentation, and a tricky and opaque setup 
procedure.

On to doing stuff, and statistics!

First off, I could not find any links on their site instructing me on how 
to configure a Python app to work on AppFog. I eventually gave up and 
resorted to Googling for a tutorial, which led me to this 
sectionin AppFog's docs. Not sure how 
you are supposed to find that.

That link isn't too helpful, though- it shows how to make a Flask site that 
works on AppFog, and links to working Bottle and Django sites, but doesn't 
spell out how to make a generic WSGI site work. To make my simple web2py 
site work, I had to do the following:

mv wsgihandler.py wsgi.py  # AppFog needs wsgi.py. I tried a symlink 
instead of a move, but couldn't make AppFog work in that arrangement
ln -s wsgi.py wsgihandler.py  # This ensures updates to web2py affect your 
wsgi.py
gem install af
af login
af push   # This gives you an Amazon East app. I can't figure out 
how to use `af` to deploy to a different infrastructure

I tried creating an app on the Rackspace infrastructure through AppFog's 
web admin `af update `, but couldn't get my app to start. It 
didn't start automatically, and `af start  --debug` tells me I 
don't have the "run" mode available. So no Rackspace for me.

Once I got my app running on AppFog's Amazon EC2 infrastructure (after a 
number of false starts related to not having wsgi.py) I noticed my app ran 
very slowly. The front page of my app doesn't really do anything; it could 
almost be a static HTML file, yet it was unbearably slow on AppFog.

I fired up Apache Benchmark and got some very disappointing results. With a 
concurrency of 50, run for 30 seconds: 

   - 1 instance, 128MB RAM: 139 requests completed, mean average of 10.5 
   seconds to fulfill a request
   - 1 instance, 2GB RAM: 140 requests, 10.8 seconds mean
   - 15 instances, 128MB RAM each: 163 requests, 9.2 seconds mean

For comparison, my site hosted on its usual low-end rackmount server (RHEL 
6.2, 3.1GHz quad-core Xeon, 8GB RAM, Apache with mod_wsgi) completed 3061 
requests with a mean 0.490 seconds per request. Beefier than what AppFog 
gave me? Sure, but not enough to explain handling 22x the requests, with 
1/22nd the response time.

*  The AppFog mean request fulfillment numbers varied by as much as two 
seconds over the several times I ran the tests. That sort of 
unpredictability worries me.



On Thursday, July 26, 2012 9:50:01 PM UTC-4, Joel Carrier wrote:
>
> Has anyone tried running web2py on appfog ( www.appfog.com ) and cares to 
> comment on their experience?

-- 





[web2py] Re: Want to create pop-up ad app

2012-07-15 Thread spiffytech
You can use web2py to implement the backend for such an ad system. It's 
perfectly capable of deciding which ad to serve, recording things about who 
views which ad, letting advertisers upload ads, etc. Most of that will 
probably be straight-forward database queries that any web framework, 
including web2py, can handle.

Web2py is a perfectly-capable choice for your task, but web2py's role in 
your app basically amounts to "randomly choose an image and return a link 
to it via AJAX". Your choice of web framework has little-to-no bearing on 
how easy or hard it will be to cover up the customer's website and display 
the ad to the user, which will all be done in framework-independent 
JavaScript.


On Saturday, July 14, 2012 7:08:27 PM UTC-4, lukedc wrote:
>
> Hi, 
>
> I want to create a web application that allows websites to have pop-up 
> ads. 
>
> But it will not be like the usual pop-up ads. This one will just integrate 
> into the web page. Like, it will not show up in a separate window. It will 
> just come up in the same webpage, and block the page. The user can then 
> exit or click on the ad. It will come up after the user has been on the 
> site for a few seconds. 
>
> So, the advertisers will upload their ad on my site. Then, websites can 
> add a code to their own site. Once they do that, they will get the ads on 
> their site. 
>
> Can web2py do this? Can I create this feature on web2py?
>
> Thank you so much, Luke
>


[web2py] Re: Scheduler: help us test it while learning

2012-07-15 Thread spiffytech
By the way, I think this app is an *excellent* way to get features tested, 
and to introduce users to features they might not ordinarily think to use. 
I'd love to see the idea more-widely adopted!


On Thursday, July 12, 2012 4:36:38 PM UTC-4, Niphlod wrote:
>
> Hello everybody, in the last month several changes were commited to the 
> scheduler, in order to improve it.
> Table schemas were changed, to add some features that were missed by some 
> users.
> On the verge of releasing web2py v.2.0.0, and seeing that the scheduler 
> potential is often missed by regular web2py users, I created a test app 
> with two main objectives: documenting the new scheduler and test the 
> features.
>
> App is available on github (https://github.com/niphlod/w2p_scheduler_tests). 
> All you need is download the trunk version of web2py, download the app and 
> play with it.
>
> Current features:
> - one-time-only tasks
> - recurring tasks
> - possibility to schedule functions at a given time
> - possibility to schedule recurring tasks with a stop_time
> - can operate distributed among machines, given a database reachable for 
> all workers
> - group_names to "divide" tasks among different workers
> - group_names can also influence the "percentage" of assigned tasks to 
> similar workers
> - simple integration using modules for "embedded" tasks (i.e. you can use 
> functions defined in modules directly in your app or have them processed in 
> background)
> - configurable heartbeat to reduce latency: with sane defaults and not 
> t many tasks queued normally a queued task doesn't exceed 5 seconds 
> execution times
> - option to start it, process all available tasks and then die 
> automatically
> - integrated tracebacks
> - monitorable as state is saved on the db
> - integrated app environment if started as web2py.py -K
> - stop processes immediately (set them to "KILL")
> - stop processes gracefully (set them to "TERMINATE")
> - disable processes (set them to "DISABLED")
> - functions that doesn't return results do not generate a scheduler_run 
> entry
> - added a discard_results parameter that doesn't store results "no matter 
> what"
> - added a uuid record to tasks to simplify checkings of "unique" tasks
> - task_name is not required anymore
> - you can skip passing the function to the scheduler istantiation: 
> functions can be dinamically retrieved in the app's environment
>
> So, your mission is:
> - test the scheduler with the app and familiarize with it
> Secondary mission is:
> - report any bug you find here or on github (
> https://github.com/niphlod/w2p_scheduler_tests/issues)
> - propose new examples to be embedded in the app, or correct the current 
> docs (English is not my mother tongue) 
>
> Once approved, docs will be probably embedded in the book (
> http://web2py.com/book)
>
> Feel free to propose features you'd like to see in the scheduler, I have 
> some time to spend implementing it.
>
>
>
>

[web2py] Re: Scheduler: help us test it while learning

2012-07-14 Thread spiffytech
All the tests passed for me.


On Thursday, July 12, 2012 4:36:38 PM UTC-4, Niphlod wrote:
>
> Hello everybody, in the last month several changes were commited to the 
> scheduler, in order to improve it.
> Table schemas were changed, to add some features that were missed by some 
> users.
> On the verge of releasing web2py v.2.0.0, and seeing that the scheduler 
> potential is often missed by regular web2py users, I created a test app 
> with two main objectives: documenting the new scheduler and test the 
> features.
>
> App is available on github (https://github.com/niphlod/w2p_scheduler_tests). 
> All you need is download the trunk version of web2py, download the app and 
> play with it.
>
> Current features:
> - one-time-only tasks
> - recurring tasks
> - possibility to schedule functions at a given time
> - possibility to schedule recurring tasks with a stop_time
> - can operate distributed among machines, given a database reachable for 
> all workers
> - group_names to "divide" tasks among different workers
> - group_names can also influence the "percentage" of assigned tasks to 
> similar workers
> - simple integration using modules for "embedded" tasks (i.e. you can use 
> functions defined in modules directly in your app or have them processed in 
> background)
> - configurable heartbeat to reduce latency: with sane defaults and not 
> t many tasks queued normally a queued task doesn't exceed 5 seconds 
> execution times
> - option to start it, process all available tasks and then die 
> automatically
> - integrated tracebacks
> - monitorable as state is saved on the db
> - integrated app environment if started as web2py.py -K
> - stop processes immediately (set them to "KILL")
> - stop processes gracefully (set them to "TERMINATE")
> - disable processes (set them to "DISABLED")
> - functions that doesn't return results do not generate a scheduler_run 
> entry
> - added a discard_results parameter that doesn't store results "no matter 
> what"
> - added a uuid record to tasks to simplify checkings of "unique" tasks
> - task_name is not required anymore
> - you can skip passing the function to the scheduler istantiation: 
> functions can be dinamically retrieved in the app's environment
>
> So, your mission is:
> - test the scheduler with the app and familiarize with it
> Secondary mission is:
> - report any bug you find here or on github (
> https://github.com/niphlod/w2p_scheduler_tests/issues)
> - propose new examples to be embedded in the app, or correct the current 
> docs (English is not my mother tongue) 
>
> Once approved, docs will be probably embedded in the book (
> http://web2py.com/book)
>
> Feel free to propose features you'd like to see in the scheduler, I have 
> some time to spend implementing it.
>
>
>
>

[web2py] Re: routes_out to put static scripts on a subdomain

2012-07-14 Thread spiffytech
Done: http://code.google.com/p/web2py/issues/detail?id=890


On Saturday, July 14, 2012 12:32:25 PM UTC-4, Massimo Di Pierro wrote:
>
> Unfortunately routes out cannot match the domain only the path.
> Perhaps this can be changed. Open a ticket about it.
>
> massimo
>
>
>
> On Saturday, 14 July 2012 09:13:51 UTC-5, spiffytech wrote:
>>
>> I'm trying to make routes_out put all requests for static content on a 
>> static subdomain, e.g. domain.com/static/file.css -> 
>> static.domain.com/static/file.css
>>
>> The following is the closest I've come, but it doesn't work- it produces 
>> static./static/file.css. What am I doing wrong?
>>
>> routes_out = (
>> (r'(?P[^/]+):/$a/static/(?P.*)', r'http://static
>> .\g/$a/static/\g'),
>> )
>>
>>

[web2py] routes_out to put static scripts on a subdomain

2012-07-14 Thread spiffytech
I'm trying to make routes_out put all requests for static content on a 
static subdomain, e.g. domain.com/static/file.css -> 
static.domain.com/static/file.css

The following is the closest I've come, but it doesn't work- it produces 
static./static/file.css. What am I doing wrong?

routes_out = (
(r'(?P[^/]+):/$a/static/(?P.*)', r
'http://static.\g/$a/static/\g'),
)



[web2py] Re: DAL speed - an idea

2012-03-09 Thread spiffytech
Before we add special features to the DAL, has anyone profiled the DAL with 
queries and data similar to nick name's to see if there's any low-hanging 
fruit we can tackle to speed up the normal select()?

nick name, can you please provide your table schema so we can test 
performance on data sets similar to yours?


On Thursday, February 9, 2012 1:51:47 PM UTC-5, nick name wrote:
>
> One of my controllers need to go through a lot of records to provide a 
> meaningful answer -- as in, 60k records.
>
> Just loading them from the database takes about 100ms 
> (db.executesql("select * from table order by id;")); Doing the same through 
> DAL takes over 6 seconds. I realize that the DAL does do a lot of 
> additional work, which in general is helpful -- but I can do without all 
> the parsing / Rows() generation for this.
>
> What do people here think about adding a db.rawselect(...), which is a 
> slim rapper for db.executesql(db._select())  that wraps everything with 
> a named tuple? It solves most of the speed problem when it is needed, but 
> still maintains a lot of the features of the SQL DAL processing.
>
>

[web2py] Re: The Winners! Web2py Application Exhibition Version 3.0

2012-03-08 Thread spiffytech
Yay! Thanks for putting on the contest!


On Wednesday, March 7, 2012 1:49:33 PM UTC-5, NetAdmin wrote:
>
>
>  1st Place Prize $100 
>
> Brian Cottingham  from the U.S. was the First Place Winner. 
> His entry of MobleBlur is a mobile-friendly interface 
> to the Newsblur RSS reading website. 
>
> A working demo can be viewed at http://mobileblur.spiffyte.ch 
>
> https://github.com/spiffytech/MobileBlur/tarball/master 
>
>  
>
> 2nd Place Prize $50 
>
> Phyo Arkar from from Burma is the Second Place Winner, 
> with an entry of HersPOS -- A Web2py + Qooxdoo based restaurant POS 
>
> http://herspos.appspot.com/HersPOS 
>
> http://code.google.com/p/herspos/ 
>
> - 
>
> I'd like to thank Bruno Rocha and Falko Krause for helping 
> out as judges, and I'd like to thank Massimo for a GREAT Framework! 
>
>
> Mr.NetAdmin 
>
>

Re: [web2py] Re: Sporadic ImportError with custom module

2012-03-07 Thread spiffytech

>
> "spiffytech", how is your process/threads apache and wsgi conf?
>

My apache configuration is pretty straightforward:

WSGIScriptAlias / 
"/home/spiffytech/apache/mobileblur.spiffyte.ch/docroot/wsgihandler.py"

I'm using the stock web2py wsgihandler.py.
 

And I'm using the prefork MPM:


StartServers   8
MinSpareServers5
MaxSpareServers   20
ServerLimit  256
MaxClients   256
MaxRequestsPerChild  4000


 

 

> "spiffytech", have you noticed if this errors happen when traffic is 
> higher or similar?
>

Traffic for my application doesn't get very high, but I've verified that 
the error occurs with only one person browsing the site.  

I've scanned through my code and don't see anything that would cause an 
obvious race condition. 

I've also deployed with the new, normal style of import instead of 
local_import, but the problem persists. 


[web2py] Re: web2py 1.99.7 is OUT

2012-03-05 Thread spiffytech
Have you considered publishing release candidates ~1 week ahead of a
release, to allow early-adopters to upgrade and see what's broken,
rather than having the rapid stream of releases? I saw you said "I'm
releasing 1.99.5 tomorrow, please test it today", but that's rather a
short and informal testing cycle.


On Mar 4, 5:29 pm, Massimo Di Pierro 
wrote:
> Same as 1.99.5 and 1.99.6 but should solve all the outstanding
> compatibility issues.
>
> Massimo


[web2py] Re: Last Day for Submissions! -- Web2py Application Exhibition Version 3.0

2012-03-05 Thread spiffytech
When will the winners be announced?


On Feb 14, 11:04 pm, NetAdmin  wrote:
> Hello All,
>
> February 15 is the last day for submissions for the 
> Web2pyApplicationExhibitionVersion 3.0 so don't delay!
>
> For more details, see the pinned message at the top of the news-group.
>
> Mr.NetAdmin
>
> Mr.NetAdmin@gmail


[web2py] Sporadic ImportError with custom module

2012-02-24 Thread spiffytech
My web2py app is hosted on Apache with mod_wsgi. Sometimes I'm
browsing through it and web2py encounters an error:

ImportError: No module named mobileblur.modules.newsblur

Caused by this line in my models file:

nb_module = local_import("newsblur")

This only happens occasionally, but on seemingly any page. Funny thing
is, if I hit the browser's refresh button the page loads fine. And
since nearly every page on the site requires that module, I know the
import works most of the time.

The permissions on the module are -rw-r--r--, apache:apache (the same
user:group Apache is configured to use).

The full source code can be found here[0], and I can provide
additional information on the server if needed.

What could be going wrong?


[0] https://github.com/spiffytech/MobileBlur/tree/master/applications/mobileblur


[web2py] Re: Application-wide exception handler?

2012-01-15 Thread spiffytech
I put this in my model file and it did exactly what I wanted. Thanks!

Is there a reason my attempts to use sys.excepthook failed? This was
my test code, which triggered the normal web2py exception handling,
which pointed to the "raise" line:

--
import sys
def handler(t, v, tb):
  redirect("http://example.com";)
sys.excepthook = handler
raise Exception("should trigger a redirect")
---


On Jan 14, 12:28 pm, Massimo Di Pierro 
wrote:
> you can do, in controller
>
> def mycaller(f):
>     try:
>         return f()
>     except IOError:
>         redirect(URL('my_IOError_page'))
>
> response._caller = mycaller
>
> response._caller wraps all action calls. Give it a try and let us know
> if this works.
>
> On Jan 13, 8:23 pm, spiffytech  wrote:
>
>
>
>
>
>
>
> > My web2py application is littered with calls to a library that loves
> > throwing exceptions when the website it connects to isn't available.
> > I'd like my web2py app to catch the exceptions thrown by the library
> > and redirect the user to a friendly error page. However, there are too
> > many library calls to load up the app with try/except statements all
> > over the place.
>
> > Is there something I can put in my models file that will catch all
> > exceptions of a certain type and handle them?


[web2py] Application-wide exception handler?

2012-01-13 Thread spiffytech
My web2py application is littered with calls to a library that loves
throwing exceptions when the website it connects to isn't available.
I'd like my web2py app to catch the exceptions thrown by the library
and redirect the user to a friendly error page. However, there are too
many library calls to load up the app with try/except statements all
over the place.

Is there something I can put in my models file that will catch all
exceptions of a certain type and handle them?


[web2py] Re: working slower than PHP on shared hosting

2011-12-29 Thread spiffytech
If I read the state dump correctly, your site is running over CGI, the
slowest possible way to host a Python website. CGI starts a new
process for each request. This is fine for PHP, since the PHP runtime
starts up very quickly. The Python virtual machine, however, starts up
much more slowly.

I expect most of your performance hit comes from the web server
starting the whole Python interpreter and web2py program fresh for
each page load. If you have the option, switch to _any_ other server
interface protocol (WSGI is most preferred, then mod_python, then
fastcgi). These all start the Python process when the web server
starts and let the existing process handle new requests as they come
in.


On Dec 29, 5:12 am, Zen Master  wrote:
> Hi guys, i installed web2py on my shared hosting a/c and configured a
> index.py as CGI/FASTCGI gateway and then configured .htaccess to send all
> traffice thru this index.py but it seems to be working slower than PHP.
> i complied the app and set migrate=False to disable migration and tried
> again but still seems to be lagging behind PHP. Is is it common or there
> are some special steps or tips i need to do to configure web2py to work on
> a shared hosting.
>
> I just configured few tables... and modified layout.html to roughly look
> like my PHP site... thats it.. and then tried to measure a single page
> load. where  a PHP page takes around 1 to 2 secs to load fully...
> web2py takes around 6 to 8 secs. On inspecting the sate dump... its WSGI
> section says... Apache supports multiprocess = true but multithreading =
> False and Gateway is CGI 1.1
>
> Waiting eagerly for some insight or solution... ;)
>
> - regards


[web2py] Re: newbie: How to match REST URL and extract path params

2011-12-22 Thread spiffytech
What you need is the pattern-based routing system:
http://web2py.com/books/default/chapter/29/4#Pattern-based-system

The pattern-based system allows you to route URLs based on regular
expressions. You can convert certain portions of a URL into GET args
or vars.

web2py does not allow you to map URLs to arbitrary functions (i.e.,
you can't map /index to SomeObject().index() ), so instead you need to
map your desired URL to fit the way web2py routes URLs internally. So
if you created a function that would normally be accessed by

/company/store/index

you can tell web2py to route

GET /comapany/apple/store/567

to that function with the following entry in routes.py:

routes_in = (
('/company/(?P.*)/store/(?P.*)', '/company/
store/index?company=\g&store=\g')
)

This will route the request to the function associated with /company/
store/index, with "apple" in request.vars["company"] and "567" in
request.vars["store"].


On Dec 22, 1:00 pm, dum coder  wrote:
> Hello everyone, i'm new to Python and web2py , In Java Jersey REST
> framework i can map a REST URL to a function and get all the path
> parameters eg.,
>
> /comapany/{comapnyid}/store/{storeid}
>
> can be mapped to a particular function and companyid and storeid are
> accessible as
> parameters to function.
>
> i'm trying to find how can i accomplish similar functionality in
> web2py, where
>
> GET /comapany/apple/store/567
>
> gets mapped to a function and in side function i can retrieve
> companyid and storeid variables.
>
> I looked at function parse_as_rest but seems like it tried to run
> query against db, in  my
> case i just want to retrieve path parameters and then call other rest
> api  in other systems
>
> thanks


[web2py] Re: web2py for freelance work

2011-07-31 Thread spiffytech
What's the complexity of site you guys normally build with web2py? Is
it mostly CRUD stuff, or anything more complicated? Has anyone built a
CMS in web2py?


On Jul 26, 1:39 am, howesc  wrote:
> i do all my work as freelance work, and have done 98% of it in web2py in the
> last 2-3 years.  it works like a champ, and is really easy to quickly build
> well-written code that i can easily support 2 years later.  i can't say that
> for other frameworks i have worked on.  also because web2py is open source
> when it's not working right i can read the source and figure out what i did
> wrong (or occasionally report a bug)
>
> the "i've never heard of web2py" or, "noone uses python" statements are hard
> to deal with - generally gets into religious like battles.  the most
> successful approach i have to this is i respond like "have you ever used
> gmail or google docs?"  and then i inform them that most of google's stuff
> (at least initially) is python.
>
> good luck!
>
> christian


[web2py] web2py for freelance work

2011-07-25 Thread spiffytech
I'm picking out a framework to use for freelance web development. Does
anyone use web2py in that sort of situation? How does it fare? Do you
find anything particularly limiting or particularly easy? How do
clients respond when you tell them you're building the site in Python
(not PHP), and that you're building it in one of the less-common
frameworks?


[web2py] Re: Creating a many-to-many form with arbitrary number of fields

2011-04-12 Thread spiffytech
On Apr 11, 11:49 pm, JorgeRpo  wrote:
> what is ingredient_num for?

It's to keep track of what order the ingredients are in- recipes
usually list ingredients in the order you will use them.


On Apr 12, 1:14 am, pbreit  wrote:
> I'd suggest something like this:

That's essentially what I planned to do to display recipes, although
you removed the "units" table, which I require to do unit conversion
later.

The part I'm stuck on is making a form to enter a recipe into the
database. Web2py's FORM/SQLFORM/SQLFORM.factory functions all assume
your form is static, but mine is not. I need to show a set of fields
to the user (ingredient, quantity, and unit of measure), and allow the
user to click a button labeled "Add another ingredient" and have an
additional set of those same fields appear on the same form. I've
gotten close to this using FORM and JavaScript, but I keep running
into a few problems:

1) Some of Web2py's validators (e.g. IS_MATCH) don't like receiving
lists in the "value" argument instead of strings, which is what
happens when you have a bunch of fields all named "ingredient_name".

2) When I create the FORM object in my controller, it only has one set
of fields for a single ingredient. If I add more fields in JavaScript,
then the user fills out the form incorrectly, my controller gets the
form, says "oh, look, errors!", and sends the form back to the user
with only a single set of fields, instead of fields for all of the
ingredients the user typed in.

3) I need validators to work conditionally. If the user puts something
into the "ingredient_name" field, they must also put something into
the "quantity" field. However, if the user clicks "Add another
ingredient", but doesn't fill out any of those fields, the form should
be accepted.


[web2py] Creating a many-to-many form with arbitrary number of fields

2011-04-11 Thread spiffytech
I'm creating a tool to manage recipes and I'm stuck creating the
recipe entry form. Each recipe has a many-to-many database relation
with ingredients. The user needs to be able to enter an arbitrary
number of ingredients for each recipe. Each ingredient used in a
recipe must include the quantity and unit of the ingredient.

I've tried a couple of very kludgy and ineffective ways to make this
work using FORM and JavaScript, but I can't get things working. How
could I do this?

===

db.define_table("recipes",
Field("name", notnull=True, requires=IS_NOT_EMPTY()),
Field("description", "text", notnull=True),
Field("servings", "integer")
)

db.define_table("ingredients",
Field("name", notnull=True, unique=True, requires=IS_NOT_EMPTY()),
)

db.define_table("units",
Field("name", notnull=True, unique=True, requires=IS_NOT_EMPTY())
)

db.define_table("recipes_ingredients",
Field("recipe_id", "reference recipes", notnull=True,
requires=IS_IN_DB(db, "recipes.id", "%(name)s")),
Field("ingredient_id", "reference ingredients", notnull=True,
requires=IS_IN_DB(db, "ingredients.id", "%(name)s")),
Field("ingredient_num", "integer", notnull=True,
requires=IS_NOT_EMPTY()),
Field("quantity", "double", notnull=True,
requires=[IS_NOT_EMPTY(), IS_MATCH("^\d+(/\d+)?$")]),
Field("unit", "reference units", requires=IS_IN_DB(db, "units.id",
"%(name)s"))
)


[web2py] Escape JSON vars without escaping JSON control characters

2010-12-13 Thread spiffytech
I'm fetching data from my database, converting it to JSON with
simplejson.dumps(), then passing it to my view to include in my
Javascript. I need to escape the JSON vars to prevent XSS attacks
without escaping all of the brackets, braces, and quotes that make
JSON work.

How can I do this? What I've attempted so far results in either the
entire JSON string being escaped, or none of it. I've hacked together
a loop that generates and prints the JSON one variable, but that's
pretty fragile and kludgy solution. Surely there's a better way?


[web2py] Re: StackExchange for web2py community

2010-09-17 Thread spiffytech
StackExchange is designed such that people who don't know what they're
talking about get voted down, while those who have quality answers get
voted up to the top. When I'm reading StackOverflow, the reading the
highest-voted questions first makes the poor quality of the lower-
voted questions very apparent to me, and I distrust them.

Also, a web2py-centric StackExchange should only attract people who
know about web2py. This is unlike StackOverflow, which caters to a
general audience and thus gets many people with only general knowledge
and general answers.

The checks, balances, and filters seem sufficient to me. Do you
disagree?


On Sep 17, 12:30 pm, mdipierro  wrote:
> I oppose and here is why. A few people have asked web2py related
> questions on stack overflow. Almost all of them have at least one
> generic answer by somebody who knows nothing about web2py. On Stack
> overflow there is no sense of community (other than the stack overflow
> community) and people try to answer even when they know nothing about
> the topic.
>
> Massimo
>
> On Sep 17, 10:58 am, mwolfe02  wrote:
>
> > My vote:
> > - ask questions on StackOverflow using the existing web2py tag
> > - follow the questions using this RSS feed:  
> > http://stackoverflow.com/feeds/tag/web2py
>
> > I like StackOverflow a lot and I think it is a much better interface
> > than Google Groups.  I asked my first few questions about web2py on SO
> > and was a bit reluctant to have to join Google Groups just to get
> > answers to my web2py questions.  That said, the user community here is
> > second to none.  I've been amazed how quickly my questions have not
> > only been answered, but in many cases answered by _core developers_!
>
> > The problem, as I see it, is that like it or not, StackOverflow is
> > quickly becoming a tool not only for getting technical questions
> > answered, but also to gauge the popularity of various programming
> > languages, web frameworks, etc.  When I was trying to decide what web
> > framework to use for my most recent project I looked at the most
> > popular questions for Django, ASP.NET, etc. as well as the number of
> > questions, by tag name, for each of those frameworks.
>
> > The relatively low number of questions (compared to Django, for
> > example) and the apparent lack of knowledgeable users (web2py
> > questions are answered almost exclusively by Massimo) was nearly
> > enough to lead me away from web2py.  It was not until I finally
> > relented to Massimo referring me to this Google Group that I was truly
> > pleased with my decision to use web2py.
>
> > I think Google Groups remains the proper place to discuss the
> > direction of the web2py project.  However, I think we should start
> > making an effort to ask and answer web2py technical questions on SO.
>
> > On Sep 16, 10:40 am, cjrh  wrote:
>
> > > On Sep 16, 1:31 pm, Narendran  wrote:
>
> > > > What does the community
> > > > think of having a stackexchange page for web2py?
>
> > > Good idea.  The StackOverflow model is the future of technical Q&A
> > > forums.   I joined and added some good and bad questions.    We need
> > > 59 more users to join in support.
>
>


[web2py] Re: Where do you use web2py?

2010-03-12 Thread spiffytech
I use web2py for my personal website (www.spiffyte.ch). I'm also using
web2py to handle the server-side portions of a turn-based multiplayer
game I'm working on. The automatic JSON encoding is very handy for
that.


On Mar 12, 11:29 am, Thadeus Burgess  wrote:
> It blogs (thadeusb.com /http://code.google.com/p/blogitizor/)
> It does customer management / scheduling systems with project and
> resource tracking
> It does statistical analysis for research
> It manages files on the fileserver, keeping things organized
> It has tracked of the status of the GaiaOnline mini game called BootyGrab
> Soon to be a commerce site so my girlfriend can sell her cute
> hand-made stuffed animals
>
> -Thadeus
>
> On Fri, Mar 12, 2010 at 6:09 AM, Jason Brower  wrote:
> > I control advances factory robotics with web2py.  It's pretty cool, but
> > for now a secret beyond that. :D
> > Best Regards,
> > Jason
> > On Fri, 2010-03-12 at 02:38 -0800, selecta wrote:
> >> check out
> >>http://www.semanticsbml.org/aym(screeshots at sf.net will help if you
> >> do not want to input something)
> >>http://www.semanticsbml.org/semanticSBML/
> >> these are my current official web2py projects
> >> the second one will use web2py as a application gui for now only some
> >> new features are exposed that are not in the current qt based gui
>
> >> I guess my projects are a bit different since they are not classical
> >> database driven web pages. I use web2py half of the time as a gui
> >> toolkit.
>
> >> On Mar 12, 10:42 am, "Giovanni Giorgi"  wrote:
> >> > Hi all,
> >> >  in the attempt to better knowing web2py and its community,
> >> > I'd like to write some entry on my blog (gioorgi.com).
> >> > I want to do a useful work for the community itself.
>
> >> > This day I'd like to focus myself on the question: for which projects do
> >> > you use web2py?
>
> >> > I have seen the master project open sourced in the last few days
> >> > posted by Asefa Debebe on 7th March (titled 'Relase of the first HL7 
> >> > based
> >> > on web2py framework', demo at ).
>
> >> > So, how you are using web2py?
> >> > For instance, do you prefer form-entry based application (data entry,
> >> > CRM,etc) or community based one (like CMS, Facebook clone etc)?
>
> >> > ciao ciao!
>
> >> > --
> >> > Team Leader
> >> > Gioorgi.com Chief Editor
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "web2py-users" group.
> > To post to this group, send email to web...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > web2py+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/web2py?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: Unit testing in web2py : Some thoughts

2010-03-02 Thread spiffytech
I finally finished the article I promised. I couldn't post to the
wiki, so I posted to AlterEgo instead:

http://web2py.com/AlterEgo/default/show/260

Since I've done little with web2py forms and auth, they're not
covered. Feel free to change the article to include how to test them.


On Mar 2, 8:59 am, Jon Romero  wrote:
> I'll post a full example in bitbucket and then a slice :)
>
> On Mar 2, 2:30 pm, mdipierro  wrote:
>
> > Would you post a web2pyslice?
>
> > On Mar 2, 4:39 am, Jon Romero  wrote:
>
> > > ok I managed to do unit testing on forms:
>
> > >  def testForm(self):
> > >         request.vars["username"] = "great-guy"
> > >         request.vars["email"] = "b...@bla.com"
>
> > >         request.vars["_formname"] = "bla_create" #this is the form
> > > name
>
> > >         resp = index()
>
> > >         self.assertTrue(resp['form'].errors) # do we have errors?
> > >         self.assertEquals(1, len(resp["all_users"]))
>
> > > On Mar 1, 2:20 pm, Jon Romero  wrote:
>
> > > > Good job!
>
> > > > I am still having problem withunittestingforms. It seems that I
> > > > cannot do a post.
>
> > > >         # Set variables for the test function
> > > >         request.env.request_method = 'POST'
> > > >         request.post_vars["body"] = "body"
> > > >         #request.vars = Storage(body = "bod")
>
> > > >         resp = index()
> > > >         print "vars", resp['form']
>
> > > >         #self.assertTrue(resp['form'].errors) # do we have errors?
> > > >         #self.assertTrue(resp['form'].errors.has_key('name')) # is
> > > > something missing?
>
> > > > Any ideas?
>
> > > > On Feb 25, 11:15 pm, Jonathan Lundell  wrote:
>
> > > > > I'm really glad to see this work happening, and I look forward to the 
> > > > > slice.
>
> > > > > Perhaps we could eventually haveunittests as part of the welcome app, 
> > > > > or indeed all three standard apps, both for documentation purposes 
> > > > > and to set a good example.

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: Unit testing in web2py : Some thoughts

2010-02-25 Thread spiffytech
I had not tried taking the sys.argv statement out of my code. You are
correct: when using TestTextRunner, sys.argv does not need to be
cleaned. I like the idea of a command line flag. It's probably a good
idea to offer such a flag, even though it turns out it's not needed to
run unit tests.


On Feb 25, 2:49 pm, Thadeus Burgess  wrote:
> I do not like the idea of having to specify the name of the app twice,
> it breaks DRY.
>
> What about an additional command line flag that can tell whether to
> strip sys.argv or not. This will keep backwards compatibility, and
> also allow for scripts to have a simple sys.argv if required.
>
> web2py.py --clean-argv
>
> On this note, have you attempted to use unittest.TextTestRunner(...)
> without the sys.argv=sys.argv[5:]
>
> I believe that TextTestRunner should work since it shouldn't look at
> command line args.
>
> -Thadeus
>
> On Thu, Feb 25, 2010 at 1:37 PM, spiffytech  wrote:
> > ot know any reason as to why web2py passes along args that it is
> >> not using. However I think this could be beneficial in certain scripts
> >> that need to rely on certain parameters, like I have a backup script
> >> that relies on the app name, I can look at the -S arg to determine
> >> what app I am currently working on for this scr

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: Unit testing in web2py : Some thoughts

2010-02-25 Thread spiffytech
What about adding to the shell environment a variable containing the
name of the current app? Then scripts like yours could still get the
information they need, and the extra values could be removed from
sys.argv without a script having to import a helper.

Does this count as breaking backward-compatibility in web2py, or does
web2py only claim compatibility for models/views/controller code?


On Feb 25, 1:42 pm, Thadeus Burgess  wrote:
> Yes, I forgot to mention the db.commit().
>
> In fact, I would db.commit() after every successful
> insertion/delete/update this way your tests will be more in line?
>
> I do not know any reason as to why web2py passes along args that it is
> not using. However I think this could be beneficial in certain scripts
> that need to rely on certain parameters, like I have a backup script
> that relies on the app name, I can look at the -S arg to determine
> what app I am currently working on for this script.
>
> There should be a way though to easily filter out web2py args from
> sys.argv in a script perhaps a helper function in shell.py that
> can do this for you when you call it.
>
> -Thadeus
>
> On Thu, Feb 25, 2010 at 11:33 AM, spiffytech  wrote:
> > *addendum: at the bottom of applications/api/controllers/test.py add
> > the line "db.commit()" to force web2py to clear the database. web2py
> > automatically uses database transactions. They are executed
> > automatically after a controller's function is called, which is why
> > you don't normally have to call commit yourself. In external scripts,
> > though, all inserts/updates/deletes in the database have to be
> > manually committed.)
>
> > On Feb 25, 12:12 pm, spiffytech  wrote:
> >> Works great! I added an "import copy" in db.py, and added a line in my
> >> unit test to rename "test_db" to "db" so that functions in the test
> >> script will use the test DB.
>
> >> For posterity, here is a complete working example of unit tests with
> >> web2py, with access to the database, using test database. The wiki
> >> article I create will explain each piece and why it's needed.
>
> >> == To run the unit tests, type this on the command line: ==
> >> python web2py.py -S api -M -R applications/api/controllers/test.py  #
> >> Fill in your own values for the test file and controller name
> >> 
>
> >> == applications/api/controllers/test.py ==
> >> #!/usr/bin/python
> >> import sys
> >> import unittest
>
> >> from gluon.globals import Request  # So we can reset the request for
> >> each test
>
> >> sys.arvg = sys.argv[5:]  # web2py.py passes the whole command line to
> >> this script
>
> >> db = test_db  # Rename the test database so that functions will use it
> >> instead of the real database
> >> execfile("applications/api/controllers/10.py", globals())  # Brings
> >> the controller's functions into this script's scope
>
> >> class TestListActiveGames(unittest.TestCase):
> >>     def setUp(self):
> >>         request = Request()  # Use a clean request
>
> >>     def testListActiveGames(self):
> >>         # Set variables for the test function
> >>         request.post_vars["game_id"] = 1
> >>         request.post_vars["username"] = "spiffytech"
>
> >>         # Call a function from the controller "10.py" and print the
> >> dictionary it returns
> >>         resp = list_active_games()
> >>         print resp
> >>         self.assertEquals(0, len(resp["games"]))
>
> >> # Manually specify tests to run; the web2py environment breaks
> >> unittest.main()
> >> # Taken from 
> >> here:http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-1-u...
> >> suite = unittest.TestSuite()
> >> suite.addTest(unittest.makeSuite(TestListActiveGames))
> >> unittest.TextTestRunner(verbosity=2).run(suite)
>
> >> db(db.game.id>0).delete()  # Empty out the test database so it's fresh
> >> for next time
> >> ==
>
> >> == Added to the bottom of applications/api/models/db.py ==
> >> # Create a test database that's laid out just like the "real" database
> >> import copy
> >> test_db = DAL('sqlite://testing.sqlite')  # DB name and location
> >> for tablename in db.tables:  # Copy tables!
> >>     table_copy

[web2py] Re: Unit testing in web2py : Some thoughts

2010-02-25 Thread spiffytech
Last question: Is there any value in having web2py.py pass scripts the
full command line (sys.argv)? If not, would you be open to a patch to
gluon/shell.py so that it only passes the script's filename and any
CLI variables shell.py didn't use? I'd also appreciate suggestions on
how to do that more reliably than sys.argv[5:].


On Feb 25, 11:36 am, Thadeus Burgess  wrote:
> So the easiest way to use a testing db and your existing tables is to
> automatically recreate them.
>
> So assuming you are in the web2py environment and have access to ``db``
>
> >>> test_db = DAL('testing.sqlite')
> >>> for tablename in db.tables:
> >>>   table_copy = [copy.copy(f) for f in db[tablename]]
> >>>   test_db.define_table(tablename, *table_copy)
>
> This will create a new testing sqlite database. Then it will go
> through all tables defined in db, then copy their fields to a list,
> then it will define a new table in the sqlite with the copied fields.
>
> Now any functions that you might want to unit test might rely on your
> ``db`` object, which could be an issue depending on how you have your
> code structured.
>
> -Thadeus
>
> On Thu, Feb 25, 2010 at 8:02 AM, Tiago Almeida
>
>  wrote:
> > I concur. Thanks :)
>
> > On Thu, Feb 25, 2010 at 1:52 PM, Nicol van der Merwe 
> > wrote:
>
> >> Super awesome, thanks!
>
> >> On Thu, Feb 25, 2010 at 3:43 PM, spiffytech  wrote:
>
> >>> I'm going to write up a nice, clear wiki article on unit testing with
> >>> the unittest module based on what I learned in this discussion. I'll
> >>> be sure to link to it here when it's done.
>
> >>> On Feb 25, 4:20 am, Nicol van der Merwe  wrote:
> >>> > Hi guys
>
> >>> > This stuff is very interesting. I would like to request, if possible,
> >>> > that
> >>> > someone makes a web2pyslice or proper AlterEgo entry on how to setup
> >>> > and run
> >>> > these kinds of tests for web2py. I am very interested in setting up
> >>> > tests
> >>> > for my application but I'm a bit lost as I've never done so before
> >>> > (plus I'm
> >>> > unfortunately just too busy to research all this and make my own
> >>> > slice).
>
> >>> > It would be very much appreciated if this can be done :)
>
> >>> > Nicolaas
>
> >>> > On Thu, Feb 25, 2010 at 5:35 AM, spiffytech 
> >>> > wrote:
> >>> > > Thanks! Interesting article! My test cases now execute. However, I
> >>> > > have a couple new questions, including a problem accessing the db in
> >>> > > my controller.
>
> >>> > > I modified my test file as AlterEgo 213 indicates so my unit tests
> >>> > > can
> >>> > > access the controller's functions. Here is my updated test file:
>
> >>> > > ==
> >>> > > #!/usr/bin/python
> >>> > > import sys
> >>> > > import unittest
>
> >>> > > from gluon.shell import exec_environment
> >>> > > from gluon.globals import Request, Response, Session
> >>> > > from gluon.storage import Storage
>
> >>> > > sys.arvg = sys.argv[5:]  # web2py.py passes the whole command line to
> >>> > > this script
>
> >>> > > class TestListActiveGames(unittest.TestCase):
> >>> > >    def setUp(self):
> >>> > >        self.request = Request()  # Use a clean Request
> >>> > >        self.controller = exec_environment('applications/api/
> >>> > > controllers/10.py', request=self.request)
>
> >>> > >    def testListActiveGames(self):
> >>> > >        self.request.post_vars["game_id"] = 1
> >>> > >        self.request.post_vars["username"] = "spiffytech"
> >>> > >        self.controller.list_active_games()
>
> >>> > > suite = unittest.TestSuite()
> >>> > > suite.addTest(unittest.makeSuite(TestListActiveGames))
> >>> > > unittest.TextTestRunner(verbosity=2).run(suite)
> >>> > > ==
>
> >>> > > It is called with the command:
>
> >>> > > ==
> >>> > > python web2py.py -S api -M -R applications/api/tests/test.py
&

[web2py] Re: Unit testing in web2py : Some thoughts

2010-02-25 Thread spiffytech
Works great! I added an "import copy" in db.py, and added a line in my
unit test to rename "test_db" to "db" so that functions in the test
script will use the test DB.

For posterity, here is a complete working example of unit tests with
web2py, with access to the database, using test database. The wiki
article I create will explain each piece and why it's needed.

== To run the unit tests, type this on the command line: ==
python web2py.py -S api -M -R applications/api/controllers/test.py  #
Fill in your own values for the test file and controller name


== applications/api/controllers/test.py ==
#!/usr/bin/python
import sys
import unittest

from gluon.globals import Request  # So we can reset the request for
each test

sys.arvg = sys.argv[5:]  # web2py.py passes the whole command line to
this script

db = test_db  # Rename the test database so that functions will use it
instead of the real database
execfile("applications/api/controllers/10.py", globals())  # Brings
the controller's functions into this script's scope

class TestListActiveGames(unittest.TestCase):
def setUp(self):
request = Request()  # Use a clean request

def testListActiveGames(self):
# Set variables for the test function
request.post_vars["game_id"] = 1
request.post_vars["username"] = "spiffytech"

# Call a function from the controller "10.py" and print the
dictionary it returns
resp = list_active_games()
print resp
self.assertEquals(0, len(resp["games"]))

# Manually specify tests to run; the web2py environment breaks
unittest.main()
# Taken from here: 
http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-1-unittest.html
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestListActiveGames))
unittest.TextTestRunner(verbosity=2).run(suite)

db(db.game.id>0).delete()  # Empty out the test database so it's fresh
for next time
==

== Added to the bottom of applications/api/models/db.py ==
# Create a test database that's laid out just like the "real" database
import copy
test_db = DAL('sqlite://testing.sqlite')  # DB name and location
for tablename in db.tables:  # Copy tables!
table_copy = [copy.copy(f) for f in db[tablename]]
test_db.define_table(tablename, *table_copy)

===


On Feb 25, 11:36 am, Thadeus Burgess  wrote:
> So the easiest way to use a testing db and your existing tables is to
> automatically recreate them.
>
> So assuming you are in the web2py environment and have access to ``db``
>
> >>> test_db = DAL('testing.sqlite')
> >>> for tablename in db.tables:
> >>>   table_copy = [copy.copy(f) for f in db[tablename]]
> >>>   test_db.define_table(tablename, *table_copy)
>
> This will create a new testing sqlite database. Then it will go
> through all tables defined in db, then copy their fields to a list,
> then it will define a new table in the sqlite with the copied fields.
>
> Now any functions that you might want to unit test might rely on your
> ``db`` object, which could be an issue depending on how you have your
> code structured.
>
> -Thadeus
>
> On Thu, Feb 25, 2010 at 8:02 AM, Tiago Almeida
>
>  wrote:
> > I concur. Thanks :)
>
> > On Thu, Feb 25, 2010 at 1:52 PM, Nicol van der Merwe 
> > wrote:
>
> >> Super awesome, thanks!
>
> >> On Thu, Feb 25, 2010 at 3:43 PM, spiffytech  wrote:
>
> >>> I'm going to write up a nice, clear wiki article on unit testing with
> >>> the unittest module based on what I learned in this discussion. I'll
> >>> be sure to link to it here when it's done.
>
> >>> On Feb 25, 4:20 am, Nicol van der Merwe  wrote:
> >>> > Hi guys
>
> >>> > This stuff is very interesting. I would like to request, if possible,
> >>> > that
> >>> > someone makes a web2pyslice or proper AlterEgo entry on how to setup
> >>> > and run
> >>> > these kinds of tests for web2py. I am very interested in setting up
> >>> > tests
> >>> > for my application but I'm a bit lost as I've never done so before
> >>> > (plus I'm
> >>> > unfortunately just too busy to research all this and make my own
> >>> > slice).
>
> >>> > It would be very much appreciated if this can be done :)
>
> >>> > Nicolaas
>
> >>> > On Thu, Feb 25, 2010 at 5:35 AM, spiffytech 
> >>> >

[web2py] Re: Unit testing in web2py : Some thoughts

2010-02-25 Thread spiffytech
execfile() did the trick! Things are working nicely now.

Using a test database would be very helpful. How do you recommend
setting one up? Do I need to copy/paste the table/field definitions
from the 'db' object, or is there a way to make a copy of the 'db'
object and point it to a different SQLite file?


On Feb 24, 10:54 pm, Thadeus Burgess  wrote:
> The unit test already has access to web2py environment (and db or
> anything else in your models). ``exec_environment`` just recreates a
> blank environment, when executing your controller it executes it
> outside of the current global scope.
>
> Instead of running exec_environment on your controller, run
> ``execfile('/path/to/file', globals())``. This way the controller is
> executed in the current environment instead of a new one.
>
> The objects for Request Storage and Response don't exist even to your
> web2py app, you always have to import them if you are using them. So
> if you wanted to use Storage even in your models you would need an
> "from gluon.storage import Storage" somewhere.
>
> Do you want your unit tests to work on your actual database? Usually I
> define a test.sqlite database that has
> nothing in it, and during my tests gets data inserted, altered, and
> then removed at the end of the tests.
>
> -Thadeus
>
> On Wed, Feb 24, 2010 at 9:35 PM, spiffytech  wrote:
> > Thanks! Interesting article! My test cases now execute. However, I
> > have a couple new questions, including a problem accessing the db in
> > my controller.
>
> > I modified my test file as AlterEgo 213 indicates so my unit tests can
> > access the controller's functions. Here is my updated test file:
>
> > ==
> > #!/usr/bin/python
> > import sys
> > import unittest
>
> > from gluon.shell import exec_environment
> > from gluon.globals import Request, Response, Session
> > from gluon.storage import Storage
>
> > sys.arvg = sys.argv[5:]  # web2py.py passes the whole command line to
> > this script
>
> > class TestListActiveGames(unittest.TestCase):
> >    def setUp(self):
> >        self.request = Request()  # Use a clean Request
> >        self.controller = exec_environment('applications/api/
> > controllers/10.py', request=self.request)
>
> >    def testListActiveGames(self):
> >        self.request.post_vars["game_id"] = 1
> >        self.request.post_vars["username"] = "spiffytech"
> >        self.controller.list_active_games()
>
> > suite = unittest.TestSuite()
> > suite.addTest(unittest.makeSuite(TestListActiveGames))
> > unittest.TextTestRunner(verbosity=2).run(suite)
> > ==
>
> > It is called with the command:
>
> > ==
> > python web2py.py -S api -M -R applications/api/tests/test.py
> > ==
>
> > The output is this:
>
> > ==
> > web2py Enterprise Web Framework
> > Created by Massimo Di Pierro, Copyright 2007-2010
> > Version 1.75.4 (2010-02-18 20:57:56)
> > Database drivers available: pysqlite2
> > testListActiveGames (__builtin__.TestListActiveGames) ... ERROR
>
> > ==
> > ERROR: testListActiveGames (__builtin__.TestListActiveGames)
> > --
> > Traceback (most recent call last):
> >  File "applications/api/tests/test.py", line 19, in
> > testListActiveGames
> >    self.controller.list_active_games()
> >  File "applications/api/controllers/10.py", line 47, in
> > list_active_games
> >    games = db(((db.game.user1==username)|(db.game.user2==username)) &
> > (db.game.victory==-2)).select(db.game.user1, db.game.user2,
> > db.game.id, db.game.turn_number).as_list()
> > NameError: global name 'db' is not defined
>
> > --
> > Ran 1 test in 0.008s
>
> > FAILED (errors=1)
> > ==
>
> > Questions:
> > 1) How can I get my controller to see the database?
> > 2) Am I simply doing something very wrong? I would expect the web2py "-
> > S" option to set up the environment, complete with my controller's
> > functions, and Request/Storage/Response objects available for
> > instantiation. However, several posts on the mailing list indicate
> > that I need to run exec_enviroment() for access to my controllers.
> > Also, the Request/Storage/Response objects don't seem to exist in the
> > sh

[web2py] Re: Unit testing in web2py : Some thoughts

2010-02-25 Thread spiffytech
I'm going to write up a nice, clear wiki article on unit testing with
the unittest module based on what I learned in this discussion. I'll
be sure to link to it here when it's done.


On Feb 25, 4:20 am, Nicol van der Merwe  wrote:
> Hi guys
>
> This stuff is very interesting. I would like to request, if possible, that
> someone makes a web2pyslice or proper AlterEgo entry on how to setup and run
> these kinds of tests for web2py. I am very interested in setting up tests
> for my application but I'm a bit lost as I've never done so before (plus I'm
> unfortunately just too busy to research all this and make my own slice).
>
> It would be very much appreciated if this can be done :)
>
> Nicolaas
>
> On Thu, Feb 25, 2010 at 5:35 AM, spiffytech  wrote:
> > Thanks! Interesting article! My test cases now execute. However, I
> > have a couple new questions, including a problem accessing the db in
> > my controller.
>
> > I modified my test file as AlterEgo 213 indicates so my unit tests can
> > access the controller's functions. Here is my updated test file:
>
> > ==
> > #!/usr/bin/python
> > import sys
> > import unittest
>
> > from gluon.shell import exec_environment
> > from gluon.globals import Request, Response, Session
> > from gluon.storage import Storage
>
> > sys.arvg = sys.argv[5:]  # web2py.py passes the whole command line to
> > this script
>
> > class TestListActiveGames(unittest.TestCase):
> >    def setUp(self):
> >        self.request = Request()  # Use a clean Request
> >        self.controller = exec_environment('applications/api/
> > controllers/10.py', request=self.request)
>
> >    def testListActiveGames(self):
> >        self.request.post_vars["game_id"] = 1
> >        self.request.post_vars["username"] = "spiffytech"
> >        self.controller.list_active_games()
>
> > suite = unittest.TestSuite()
> > suite.addTest(unittest.makeSuite(TestListActiveGames))
> > unittest.TextTestRunner(verbosity=2).run(suite)
> > ==
>
> > It is called with the command:
>
> > ==
> > python web2py.py -S api -M -R applications/api/tests/test.py
> > ==
>
> > The output is this:
>
> > ==
> > web2py Enterprise Web Framework
> > Created by Massimo Di Pierro, Copyright 2007-2010
> > Version 1.75.4 (2010-02-18 20:57:56)
> > Database drivers available: pysqlite2
> > testListActiveGames (__builtin__.TestListActiveGames) ... ERROR
>
> > ==
> > ERROR: testListActiveGames (__builtin__.TestListActiveGames)
> > --
> > Traceback (most recent call last):
> >  File "applications/api/tests/test.py", line 19, in
> > testListActiveGames
> >    self.controller.list_active_games()
> >  File "applications/api/controllers/10.py", line 47, in
> > list_active_games
> >    games = db(((db.game.user1==username)|(db.game.user2==username)) &
> > (db.game.victory==-2)).select(db.game.user1, db.game.user2,
> > db.game.id, db.game.turn_number).as_list()
> > NameError: global name 'db' is not defined
>
> > --
> > Ran 1 test in 0.008s
>
> > FAILED (errors=1)
> > ==
>
> > Questions:
> > 1) How can I get my controller to see the database?
> > 2) Am I simply doing something very wrong? I would expect the web2py "-
> > S" option to set up the environment, complete with my controller's
> > functions, and Request/Storage/Response objects available for
> > instantiation. However, several posts on the mailing list indicate
> > that I need to run exec_enviroment() for access to my controllers.
> > Also, the Request/Storage/Response objects don't seem to exist in the
> > shell.
>
> > On Feb 24, 2:52 pm, Thadeus Burgess  wrote:
> > > Replacing the way you run test suites helps. Instead of using .main()
> > > add them manually.
>
> > > I would suggest reading the following article, as it includes methods
> > > to aggregate your test suites together.
>
> > >http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-1-u...
>
> > > import sys
> > > sys.argv = sys.argv[5:]
>
> > > import unittest
>
> > > class TestDefaultController(unittest.TestCase):
>
> > >     def testPrintSt

[web2py] Re: Unit testing in web2py : Some thoughts

2010-02-24 Thread spiffytech
Thanks! Interesting article! My test cases now execute. However, I
have a couple new questions, including a problem accessing the db in
my controller.

I modified my test file as AlterEgo 213 indicates so my unit tests can
access the controller's functions. Here is my updated test file:

==
#!/usr/bin/python
import sys
import unittest

from gluon.shell import exec_environment
from gluon.globals import Request, Response, Session
from gluon.storage import Storage

sys.arvg = sys.argv[5:]  # web2py.py passes the whole command line to
this script

class TestListActiveGames(unittest.TestCase):
def setUp(self):
self.request = Request()  # Use a clean Request
self.controller = exec_environment('applications/api/
controllers/10.py', request=self.request)

def testListActiveGames(self):
self.request.post_vars["game_id"] = 1
self.request.post_vars["username"] = "spiffytech"
self.controller.list_active_games()

suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestListActiveGames))
unittest.TextTestRunner(verbosity=2).run(suite)
==

It is called with the command:

==
python web2py.py -S api -M -R applications/api/tests/test.py
==

The output is this:

==
web2py Enterprise Web Framework
Created by Massimo Di Pierro, Copyright 2007-2010
Version 1.75.4 (2010-02-18 20:57:56)
Database drivers available: pysqlite2
testListActiveGames (__builtin__.TestListActiveGames) ... ERROR

==
ERROR: testListActiveGames (__builtin__.TestListActiveGames)
--
Traceback (most recent call last):
  File "applications/api/tests/test.py", line 19, in
testListActiveGames
self.controller.list_active_games()
  File "applications/api/controllers/10.py", line 47, in
list_active_games
games = db(((db.game.user1==username)|(db.game.user2==username)) &
(db.game.victory==-2)).select(db.game.user1, db.game.user2,
db.game.id, db.game.turn_number).as_list()
NameError: global name 'db' is not defined

--
Ran 1 test in 0.008s

FAILED (errors=1)
==

Questions:
1) How can I get my controller to see the database?
2) Am I simply doing something very wrong? I would expect the web2py "-
S" option to set up the environment, complete with my controller's
functions, and Request/Storage/Response objects available for
instantiation. However, several posts on the mailing list indicate
that I need to run exec_enviroment() for access to my controllers.
Also, the Request/Storage/Response objects don't seem to exist in the
shell.



On Feb 24, 2:52 pm, Thadeus Burgess  wrote:
> Replacing the way you run test suites helps. Instead of using .main()
> add them manually.
>
> I would suggest reading the following article, as it includes methods
> to aggregate your test suites together.
>
> http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-1-u...
>
> import sys
> sys.argv = sys.argv[5:]
>
> import unittest
>
> class TestDefaultController(unittest.TestCase):
>
>     def testPrintStatement(self):
>         print "This line should print"
>     def testDatabaseRecordCount(self):
>         print "Records in database --- ", db(db.auth_user.id>0).count()
>
> suite = unittest.TestSuite()
> suite.addTest(unittest.makeSuite(TestDefaultController))
> unittest.TextTestRunner(verbosity=2).run(suite)
>
> python web2py.py -S pms -M -R applications/pms/test/testDefaultController.py
> web2py Enterprise Web Framework
> Created by Massimo Di Pierro, Copyright 2007-2010
> Version 1.75.4 (2010-02-18 14:55:03)
> Database drivers available: SQLite3
> /home/thadeusb/web2py/applications/pms/modules/utils.py:16:
> DeprecationWarning: the md5 module is deprecated; use hashlib instead
>   import md5
> testDatabaseRecordCount (__builtin__.TestDefaultController) ...
> Records in database ---  4052
> ok
> testPrintStatement (__builtin__.TestDefaultController) ... This line
> should print
> ok
>
> --
> Ran 2 tests in 0.006s
>
> OK
>
> -Thadeus
>
> On Wed, Feb 24, 2010 at 12:50 PM, spiffytech  wrote:
> > The confusion is not with doctests, but with external unit tests
> > created with the 'unittest' module. Could you please post your
> > testControllerDefault.py so I can see what you're doing different from
> > me?
>
> > Please allow me to elaborate on my problems running unit tests with
> > web2py. Here is my (very minimal) example unit test file:
> > =

[web2py] Re: Unit testing in web2py : Some thoughts

2010-02-24 Thread spiffytech
The confusion is not with doctests, but with external unit tests
created with the 'unittest' module. Could you please post your
testControllerDefault.py so I can see what you're doing different from
me?

Please allow me to elaborate on my problems running unit tests with
web2py. Here is my (very minimal) example unit test file:
=
#!/usr/bin/python
import unittest

class TestListActiveGames(unittest.TestCase):
def testListActiveGames(self):
print "This line should print out"

if __name__ == "__main__":
unittest.main()
=

If the test is actually run, the command line will show "This line
should print out".

The file is stored at /applications/api/tests/test.py. My
current working directory is .
I run the following command:

===
python web2py.py -S api -M -R applications/api/tests/test.py
===

And I get this output:


web2py Enterprise Web Framework
Created by Massimo Di Pierro, Copyright 2007-2010
Version 1.75.4 (2010-02-18 20:57:56)
Database drivers available: pysqlite


The output does not contain the line, "This line should print out",
indicating the unit tests are not being run.

I did some debugging and found that the last two lines, which are
typical for unittest files, do not work when the file is executed by
web2py. Rather than being equal to "__main__", which indicates the
file is being executed from the command line, __name__ is equal to
"__builtin__". I modified the code to work anyway:


#!/usr/bin/python
import unittest

class TestListActiveGames(unittest.TestCase):
def testListActiveGames(self):
print "This line should print out"

unittest.main()


Now, I receive this output:

===
web2py Enterprise Web Framework
Created by Massimo Di Pierro, Copyright 2007-2010
Version 1.75.4 (2010-02-18 20:57:56)
Database drivers available: pysqlite2
option -S not recognized
Usage: web2py.py [options] [test] [...]

Options:
  -h, --help   Show this message
  -v, --verboseVerbose output
  -q, --quiet  Minimal output

Examples:
  web2py.py   - run default set of tests
  web2py.py MyTestSuite   - run suite 'MyTestSuite'
  web2py.py MyTestCase.testSomething  - run
MyTestCase.testSomething
  web2py.py MyTestCase- run all 'test*' test
methods
   in MyTestCase
===

More debugging revealed that this is output by unittest.main(). The
unittest module tries to parse arguments on the command line, sees the
"-S" option that was passed to web2py.py, says "I don't know what '-S'
means!", and exits.

To coerce unittest.main() to continue running, I made a quick hack to
shell.py to strip out the extra command line arguments in sys.argv
before test.py is run:

 gluon/shell.py, insert line 165 
sys.argv = sys.argv[5:]
===

I call the test file again, with the same command as before, and get
this:


web2py Enterprise Web Framework
Created by Massimo Di Pierro, Copyright 2007-2010
Version 1.75.4 (2010-02-18 20:57:56)
Database drivers available: pysqlite2

--
Ran 0 tests in 0.000s

OK


The line, "This line should be printed out", is still not printed.
Stepping through the code with Python's debugging module, pdb, shows
that unittest.main() thinks it's being called from web2py.py, and not
from test.py. unittest.main() looks for tests to run in web2py.py,
finds none, and quits.

So now I'm stuck: the unittest module expects test.py to be run as a
standalone script, but instead test.py is being executed within the
scope of web2py.py, which is confusing the unittest module in several
ways.



On Feb 24, 1:02 pm, Thadeus Burgess  wrote:
> If I create a unittest
>
> init/tests/testControllerDefault.py
>
> and run the following command line
>
> python web2py.py -S  -M -R
> applications/init/tests/testControllerDefault.py
>
> My test is ran.
>
> I don't see what is so confusing.
>
> -Thadeus
>
> On Wed, Feb 24, 2010 at 12:01 PM, Thadeus Burgess  
> wrote:
> > consider controllers/default.py
>
> > def index():
> > """
> >>>> db(db.people.id > 0).count()
> > '35'
> > """
> >    return db(db.people.id > 0).count()
>
> > now when I run
>
> > `python web2py.py -T init/default/index`
>
> > produces my doctest.
>
> > -Thadeus
>
> > On Wed, Feb 24, 2010 at 2:28 AM, Jon Romero  wrote:
> >> So, any idea/hint how to do it? Do we need a patch?
>
> >> On Feb 23, 10:40 pm, spiffytech  wrote

[web2py] Re: Unit testing in web2py : Some thoughts

2010-02-23 Thread spiffytech
I'm running the latest version, 1.75.4.


On Feb 23, 11:35 am, Thadeus Burgess  wrote:
> What version of web2py are you running?
>
> What is the output of ``python web2py.py --help``
>
> -Thadeus
>
> On Tue, Feb 23, 2010 at 5:23 AM, Jon Romero  wrote:
> > ust put a prin "Hello world!" inside the test file, everything
> > works ok. So, I suppose that this file tries to load AGAIN the web2py
> > environment and there is
> > some sort of mi

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: Unit testing in web2py : Some thoughts

2010-02-23 Thread spiffytech
That is unittest.main() trying to parse the arguments on the command
line. Web2py is passing the original command line (sys.argv) to the
unit test script, which sees the arguments for web2py.py and says "I
don't know what these mean". A quick hack to gluon/shell.py ("sys.argv
= sys.argv[4:]" on line 165 in web2py version 1.74.6) got me past
this. Is there a clean, reliable way to not pass scripts all of the
web2py.py CLI arguments?

Once I hacked shell.py I ran into another problem: the unittest module
has the scope of web2py.py and not my script. Stepping through the
unittest module code reveals that whenever unittest.main() tries to
find the default test, or a test you specify, or tries to run all
tests, it sees itself as being in "module '__main__'  from
'web2py.py'". since web2py.py doesn't contain any tests the unittest
sees nothing to do, and quits. If you named a specific test to run,
the unittest module throws an exception and complains that such a test
does not exist. How could this scoping issue be solved?
unittest.main() takes a 'module' argument but I don't know what to put
there to make it work.

Thadeus, I found the web2py.py help string for "-R" misleading; when I
run unit tests I don't want to launch a shell, and since the help
string says "-R" requires the shell option, I concluded that "-R" was
not what I needed.

Also, AlterEgo 213 gives no indication that the sample unit test
script should be run with web2py.py. Rather, it looks like a perfectly
ordinary script that would be run with "python test.py". AlterEgo 213
further misleads by showing the user how to set up the web2py
environment inside the unit test script, rather than relying on
web2py.py to set it up. Once I get unit tests working I'll gladly
create a wiki entry that could replace AlterEgo 213, demonstrating the
'correct' way to go about this.



On Feb 23, 6:23 am, Jon Romero  wrote:
> Thanks! That was what I was looking for!
> The problem now is that is you try to run the unit test the way it is
> described here (http://www.web2py.com/AlterEgo/default/show/213), I
> get this error:
>
> > python web2py.py -S init -M -R applications/myapp/tests/default.py
>
> option -S not recognized
> Usage: web2py.py [options] [test] [...]
>
> Options:
>   -h, --help       Show this message
>   -v, --verbose    Verbose output
>   -q, --quiet      Minimal output
>
> Examples:
>   web2py.py                               - run default set of tests
>   web2py.py MyTestSuite                   - run suite 'MyTestSuite'
>   web2py.py MyTestCase.testSomething      - run
> MyTestCase.testSomething
>   web2py.py MyTestCase                    - run all 'test*' test
> methods
>                                                in MyTestCase
>
> If I just put a prin "Hello world!" inside the test file, everything
> works ok. So, I suppose that this file tries to load AGAIN the web2py
> environment and there is
> some sort of mix up?
>
> Any idea?
>
> On Feb 23, 3:23 am, Thadeus Burgess  wrote:
>
> > python web2py.py --help
>
> >   -S APPNAME, --shell=APPNAME
> >                         run web2py in interactive shell or IPython (if
> >                         installed) with specified appname
> >   -T TEST_PATH, --test=TEST_PATH
> >                         run doctests in web2py environment; TEST_PATH like
> >                         a/c/f (c,f optiona
> >   -R PYTHON_FILE, --run=PYTHON_FILE
> >                         run PYTHON_FILE in web2py environment; should be 
> > used
> >                         with --shell o
> >   -M, --import_models   auto import model files; default is False; should be
> >                         used with --shell option
>
> > python web2py.py -T //
>
> > It executes all doctests in environment. Have a look at sql.py for
> > example doctesting with a database (using a sqlite database)
>
> > And if you want to use unittest
>
> > python web2py.py -S  -M -R
> > /path/to/web2py/applications/yourapp/tests/testControllerA.py
>
> > Will execute the file inside of the web2py environment (with access to
> > database models as denoted by the -M option)'
>
> > Now since we had such a difficult time finding these options, please
> > list links as to where the documentation on this subject can be
> > updated and explained further.
>
> > -Thadeus
>
> > On Mon, Feb 22, 2010 at 5:21 PM, spiffytech  wrote:
> > > nside to doctests is they are harder to organize; you can't
> > > cleanly separate different sorts of tests that all relate to the same
> > > function (i.e

[web2py] Re: Unit testing in web2py : Some thoughts

2010-02-22 Thread spiffytech
> The link you provided gives an example of using the unittest classes
> (not doctest), in which you can import anything you want since it is
> just a python file.

AlterEgo 213 (which Jon linked to) does not show how to get your
controllers to see your database models- the example code doesn't
interact with a database at all. I've tried every snippet of promising
code on the mailing list and haven't been successful. I, too, would
appreciate an example of exposing models to a controller in an
external unit test


The biggest downside to doctests is that they do a poor job of testing
functions that rely heavily on a database. Since doctests don't
automatically run setUp() and tearDown() functions before/after every
test (as external unit tests do) you have to devise clunky,
inconvenient ways to bring the database back to a known state for each
test.

Another downside to doctests is they are harder to organize; you can't
cleanly separate different sorts of tests that all relate to the same
function (i.e., when a function is very sensitive to initial
conditions). With external unit tests each logically distinct test can
be represented with a distinct function, and that test can be run on
it's own, without the overhead of any other tests (unlike doctests,
where everything that tests a function must be run in order to test
the part you're interested in).


As the AlterEgo example shows, web2py already supports external unit
testing. All that's missing is an example demonstrating how to test a
database-driven function.

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: storing a Python list

2010-02-17 Thread spiffytech
That would work, calling MY_PICKLE functions everywhere seems like as
much work as calling pickle functions. It would be nice if the
pickling could be done transparently behind the scenes, so my
controller code could be cleaner and less error-prone.

-Brian


On Feb 17, 2:34 pm, Thadeus Burgess  wrote:
> Could you write a function that handles the inserts/selects instead?
>
> class MY_PICKLE():
>     @classmethod
>     def get(keyname):
>          pkldump = db(db.pickle_table.keyname == keyname).select().first()
>          return pickle.loads(pkldump.value)
>     @classmethod
>     def save(keyname, value):
>         pkldump = db(db.pickle_table.keyname == keyname).select().first()
>         if pkldump:
>             pkldump.update_record(value=pickle.dumps(value))
>         else:
>             db.picke_table.insert(keyname=keyname,value=pickle.dumps(value))
>
> a_list = MY_PICKLE.get("listkey")
>
> # do some stuff to list
>
> MY_PICKLE.save("listkey", a_list)
>
> -Thadeus
>
> On Wed, Feb 17, 2010 at 1:20 PM, spiffytech  wrote:
> > I'm serializing with Pickle in my app, but it's a hassle to dump/load
> > the data every time I mess with it. Is there a way to make the
> > serializing happen automatically with DB access?
>
> > -Brian
>
> > On Feb 17, 1:46 pm, Carl  wrote:
> >> thanks Jorge; most helpful in pointing me in the right direction.
>
> >> The python to pickle is simply; for example:
> >>     import pickle
> >>     flat_retort = pickle.dumps(retort)
>
> >> and to unpickle; for example:
> >>     import pickle
> >>     options = pickle.loads(rows[0].retort)
>
> >> On Feb 17, 3:57 pm, JorgeRpo  wrote:
>
> >> > On Feb 17, 10:47 am, Carl  wrote:
>
> >> > > I have a Python list that I want to store and retrieve from the data
> >> > > store.
>
> >> > > The individual items of the list are of no use unless used with the
> >> > > items of the complete list and there are no use-cases requiring
> >> > > searching for a specified list item. The number of items in the list
> >> > > is between one and fifteen (any more is beyond end users to manage).
>
> >> > > I'd like to store and retrieve the list in a single field. On
> >> > > retrieval the data would be in a Python list object.
>
> >> > > What's an approach I can use?
>
> >> > serialize
> >> > --
> >> > sig text
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "web2py-users" group.
> > To post to this group, send email to web...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > web2py+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/web2py?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py] Re: storing a Python list

2010-02-17 Thread spiffytech
I'm serializing with Pickle in my app, but it's a hassle to dump/load
the data every time I mess with it. Is there a way to make the
serializing happen automatically with DB access?

-Brian


On Feb 17, 1:46 pm, Carl  wrote:
> thanks Jorge; most helpful in pointing me in the right direction.
>
> The python to pickle is simply; for example:
>     import pickle
>     flat_retort = pickle.dumps(retort)
>
> and to unpickle; for example:
>     import pickle
>     options = pickle.loads(rows[0].retort)
>
> On Feb 17, 3:57 pm, JorgeRpo  wrote:
>
> > On Feb 17, 10:47 am, Carl  wrote:
>
> > > I have a Python list that I want to store and retrieve from the data
> > > store.
>
> > > The individual items of the list are of no use unless used with the
> > > items of the complete list and there are no use-cases requiring
> > > searching for a specified list item. The number of items in the list
> > > is between one and fifteen (any more is beyond end users to manage).
>
> > > I'd like to store and retrieve the list in a single field. On
> > > retrieval the data would be in a Python list object.
>
> > > What's an approach I can use?
>
> > serialize
> > --
> > sig text

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.



[web2py:30971] Re: Google Apps wep2py applications

2009-09-14 Thread spiffytech

Are there plans to make web2py write admin files to the BigTable
datastore instead of the filesystem on GAE?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~--~~~~--~~--~--~---