Re: tests fail because of g

2008-07-07 Thread Alberto Valverde

Jonathan Vanasco wrote:
 I have several helper classes that use g from pylons
   
You have a design problem then :) pylons.g is really a substitute for
module-level singletons so you can have them associated to an app's
instance and have several of these coexisting in the same process
without conflicts (eg: several blog instances each with it's own db
connection to a different database). This is actually the same problem
you would have if you depended on global state: More difficult to
isolate tests, more difficult to set them up, etc...

If you really want to go this route you can either mock it (using the
same pattern as has been suggested to mock pylons.session) or test the
whole stack so PylonsApp takes care of setting up and tearing down the
app context on every request.

app = paste.deploy.loadapp('config:mytestconfig.ini')
app = webtest.TestApp(app)

resp = app.get('/some/test/method')
assert resp.some_test_var == 'foo'

the controller action that responds to the above url can place variables
in environ['paste.testing_variables'] and they'd be bound to the test
response that TestApp.{get,post,put,etc...} returns:

def some_controller_method(self):*
if* *'paste.testing_variables'* *in* request.environ:
 request.environ[*'paste.testing_variables'*][*'some_test_var'*]
= 'foo'

However, the right way to do it, IMHO, would be to separate the
functions/classes that depend on g in two. For example, say you needed a
pylons.g.db_connection inside a helper function bar:

def side_effect_free_bar(db_connection):
# do something with db_connection and refrain from accessing global
state
# this should be pretty easy to unit-test since it's output depends
solely on it's arguments.
# You can easily pass a db_connection you've explicitly prepared for
testing

def bar():
# This one you would test inside functional/integration tests, if at
all.
return side_effect_free_bar(pylons.g.db_connection)

HTH,
Alberto

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: tests fail because of g

2008-07-07 Thread Jonathan Vanasco

hm...

in this instance, i use g for three things:

1- on startup, i pull constants out of the DB and stash them into g
2- misc form classes refer to g as the values to use for validation
3- templates use them to generate dropdowns

i guess i could use some sort of factory function to pull g on each
form init.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: best way to get user's IP address in pylons?

2008-07-07 Thread Jonathan Vanasco



On Jul 7, 1:46 pm, Ian Bicking [EMAIL PROTECTED] wrote:
 Christopher Weimann wrote:
  REMOTE_ADDR is typically set by your webserver and can be trusted.  
  X_FORWARDED_FOR is an HTTP header typically set by proxy servers or even 
  the client and I would have to say it can NOT be trusted so should 
  certainly not replace the reliable data in REMOTE_ADDR.

 This is in part the reason why it is handled in middleware.  If you *do*
 have a proxy in your installation then you can (and should) trust
 X-Forwarded-For, and moving it to REMOTE_ADDR signifies the
 trustworthiness of the value.  If you are not behind a proxy you should
 ignore the value.  (Arguably, maybe you should even remove the header or
 reject the request, but nothing currently does that.)

Correct.

The middleware I use under modperl works like this:

Port 80 proxy-
Sets X-Forwarded-For to REMOTE_ADDR
Sets X-Forwarded-For-Lan to LAN_SECRET
Sets REMOTE_ADDR to the lan id / 127.0.0.1

ModPerl 'middleware'
Requires X-Forwarded-For headers to have:
   REMOTE_ADDR of specifc lan ips
   X-Forwarded-For-Lan  with correct lan secret
If those qualifications are met, then the X-Forwarded-For becomes
REMOTE_ADDR.  If they do not, the request is rejected.

This approach ensures that data IS reliable, and GREATLY simplifies
development and clustering across load balancers.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: tests fail because of g

2008-07-07 Thread Mike Orr

On Mon, Jul 7, 2008 at 1:33 PM, Wichert Akkerman [EMAIL PROTECTED] wrote:
 What's wrong with using paste.loadapp to properly set 'g' for every
 test that needs it?  That way your test environment is the closest to
 the production environment -- which is the purpose of having tests in
 the first place.

 Unit tests want as little as possible of the full environment. And you
 want to be able to unit test code that uses things like g.

Well, unit tests (as opposed to functional tests) should test the
target routine as closely as possible, without the interference of
something like 'g' which should be tested separately.  After all, a
value on 'g' is the same as the value standalone.

-- 
Mike Orr [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: tests fail because of g

2008-07-07 Thread Wichert Akkerman

Previously Mike Orr wrote:
 
 On Mon, Jul 7, 2008 at 1:33 PM, Wichert Akkerman [EMAIL PROTECTED] wrote:
  What's wrong with using paste.loadapp to properly set 'g' for every
  test that needs it?  That way your test environment is the closest to
  the production environment -- which is the purpose of having tests in
  the first place.
 
  Unit tests want as little as possible of the full environment. And you
  want to be able to unit test code that uses things like g.
 
 Well, unit tests (as opposed to functional tests) should test the
 target routine as closely as possible, without the interference of
 something like 'g' which should be tested separately.  After all, a
 value on 'g' is the same as the value standalone.

You might want to unittest a method that uses g in some way. More
typically you may want to unit test something that stuffs data in c.

Wichert.

-- 
Wichert Akkerman [EMAIL PROTECTED]It is simple to make things.
http://www.wiggy.net/   It is hard to make things simple.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: tests fail because of g

2008-07-07 Thread Mike Orr

On Mon, Jul 7, 2008 at 1:48 PM, Wichert Akkerman [EMAIL PROTECTED] wrote:
 Previously Mike Orr wrote:

 On Mon, Jul 7, 2008 at 1:33 PM, Wichert Akkerman [EMAIL PROTECTED] wrote:
  What's wrong with using paste.loadapp to properly set 'g' for every
  test that needs it?  That way your test environment is the closest to
  the production environment -- which is the purpose of having tests in
  the first place.
 
  Unit tests want as little as possible of the full environment. And you
  want to be able to unit test code that uses things like g.

 Well, unit tests (as opposed to functional tests) should test the
 target routine as closely as possible, without the interference of
 something like 'g' which should be tested separately.  After all, a
 value on 'g' is the same as the value standalone.

 You might want to unittest a method that uses g in some way. More
 typically you may want to unit test something that stuffs data in c.

True.  I'm just saying if you can code to avoid 'g' and 'c' in your
lib routines, so much the better.  I have never found a use for 'g',
except in one case to put a structure of static data that's parsed on
app startup (or read from a cache pickle).

-- 
Mike Orr [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: tests fail because of g

2008-07-07 Thread Mike Orr

On Mon, Jul 7, 2008 at 2:10 PM, Jonathan Vanasco [EMAIL PROTECTED] wrote:


 On Jul 7, 4:53 pm, Mike Orr [EMAIL PROTECTED] wrote:
 True.  I'm just saying if you can code to avoid 'g' and 'c' in your
 lib routines, so much the better.  I have never found a use for 'g',
 except in one case to put a structure of static data that's parsed on
 app startup (or read from a cache pickle).

 That is *exactly* what I use g for -- stashing 'static' data ( the
 names and ids of 'options' that the database fkeys on .  example:

 query= select * from _gender
 for row in rows:
   g.gender.id[ row.id ]= row.name
   g.gender.name[ row.name ]= row.id

 i also have some other misc. config data -- like amazon s3 urls, etc
 - which are initialized on startup based out of config values.

 i'm a little less-than-enthusiastic by the built in testing with
 Pylons.  not having g,c,session is annoying.

You're not initializing the application completely and you're
wondering why it isn't working?  Don't you see the contradiction
there?

 i've also noticed that
 for every test it does a full app initialization - which means ( in my
 case ) querying the database for 50 tables worth of data.

Unit tests always do that: setUp creates a full test environment,
which is discarded after each test.  Generally that's considered a
good thing even if it's slow.  Python apps have been testing this way
since long before Pylons was created. If you have to read 50 tables
worth of data, it's more a case that you have an unusual application
structure than that Python's testing is screwed up.  You may have to
test this application by pre-reading the data at module level and
putting it in place.  (And if it's place is in pylons.g, maybe have
some lightweight g-initialization routine that copies the variables
from their test module locations.  There's a module_setup function
that may persist between tests, although I'm not sure.

-- 
Mike Orr [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



supervisor questions

2008-07-07 Thread Shannon -jj Behrens

Hi,

I'm looking at 
http://wiki.pylonshq.com/display/pylonscookbook/Monitor+Pylons+application+with+supervisord.
 I have a few questions:

1. Why does it use a manually created server.py instead of using
paster like normal?

2. Does anyone have an rc script to start supervisor under Ubuntu?

3. Is anyone doing any fancy log rotation or are the defaults reasonable?

Thanks,
-jj

-- 
It's a walled garden, but the flowers sure are lovely!
http://jjinux.blogspot.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: A new SQLAlchemy migration toolkit - miruku 0.1a3 has been released

2008-07-07 Thread Shannon -jj Behrens

On Thu, Jul 3, 2008 at 6:59 PM, Olli Wang [EMAIL PROTECTED] wrote:

 On Jul 4, 9:42 am, Shannon -jj Behrens [EMAIL PROTECTED] wrote:
 How is it possible to not require an upgrade script?  What happens if
 I'm changing an email field into two fields, one for the username and
 one for the server?

 -jj

 --
 It's a walled garden, but the flowers sure are 
 lovely!http://jjinux.blogspot.com/

 What miruku does is finding the difference between original schema and
 modified schema,  then upgrade the original schema to the modified
 schema (add/drop columns/tables, etc).
 In your question, it seems you just need to add a new email column
 which may be located in the same or different table. It doesn't
 matter, just change the model schema code by add a new email column
 and run miruku upgrade command. Then you will have two email field.
 However, currently miruku only support add/drop tables/columns/index.
 So there is no way to copy the email value to the new field
 automatically. But I think it's a good idea to work it our in the
 future. :)

I think it's an 80/20 thing.  You got 80% of what everyone needs by
writing 20% of the code, and, as usual, I'm obsessed with the
remaining 20% ;)

Happy Hacking!
-jj

-- 
It's a walled garden, but the flowers sure are lovely!
http://jjinux.blogspot.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: supervisor questions

2008-07-07 Thread Ian Bicking

Shannon -jj Behrens wrote:
 Hi,
 
 I'm looking at 
 http://wiki.pylonshq.com/display/pylonscookbook/Monitor+Pylons+application+with+supervisord.

Huh... I'm getting a 404...?

  I have a few questions:
 
 1. Why does it use a manually created server.py instead of using
 paster like normal?

I use paster serve (no --reload, --monitor, --daemon, any of which would 
mess it up).

 2. Does anyone have an rc script to start supervisor under Ubuntu?

Huh, actually no.  It did occur to me that supervisor should ship with 
such a thing.  Incidentally we use a per-site supervisord.

 3. Is anyone doing any fancy log rotation or are the defaults reasonable?

The defaults have seemed reasonable to me (though there's no cleanup or 
compression AFAIK, just rotation).

-- 
Ian Bicking : [EMAIL PROTECTED] : http://blog.ianbicking.org

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: supervisor questions

2008-07-07 Thread Ian Bicking

Ian Bicking wrote:
 1. Why does it use a manually created server.py instead of using
 paster like normal?
 
 I use paster serve (no --reload, --monitor, --daemon, any of which would 
 mess it up).

Incidentally, one thing I don't think is all that well explained (at 
least in the supervisor docs), is that shell scripts must end with:

   exec paster serve production.ini

So, if you want a shell script (e.g., to setup the environment) you have 
to be sure to use exec at the end; this makes paster replace the shell 
process.

-- 
Ian Bicking : [EMAIL PROTECTED] : http://blog.ianbicking.org

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: distribute Pylons app with bytecode files only?

2008-07-07 Thread mdipierro

Hi Phlee,

it is true that it is possible to decompile bytecode python but it is
also true that it is possible to decompile or disassemble any
language. That in itself does not make it worthless for two reasons:

The first is that it is illegal (if you say so in the license). How
easy it is to open the front door of your house? that does not mean
anybody does it. People have sued and have won trials in similar
circumstances. VB and C# sell because they claim compilation
protection but it is not better than in Python.

In the specific case of web2py. web2py does one more step before
bytecode compiling. It translates all view hierarchy for every action
into a single python file (resolves all extended and included
templates into one view, and then tuns the html into python code), the
it bytecode compiles it. It manly does this to serve pages faster
without parsing and string substitution at runtime. This also means
that even if they were to decompile it, they would not get exactly the
original code and what they'd get would not be too easy to turn into a
working web2py application.

I am here temporarily so if you have questions we have a google list
for web2py.

Massimo

P.S. Sorry for intruding but I thought this was relevant. Pylons rocks!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: best way to send email w/o blocking?

2008-07-07 Thread Justin Tulloss



On Jul 6, 12:35 am, kevin [EMAIL PROTECTED] wrote:

 What are your recommendations for sending email without blocking?
 Because I can imagine several ways, but maybe there's some niceness
 I'm not aware of.

I actually spawn off a new thread that does some verification and then
sends the email and exits. It's a bit heavyweight, I admit, but it
allows you to take as much time as you want without interfering with
the user experience.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Debugging failed tests with pylons globals

2008-07-07 Thread Mike Orr

On Mon, Jul 7, 2008 at 10:04 PM, Justin Tulloss [EMAIL PROTECTED] wrote:
I have to admit that despite my digging through the source, I
 do not have a good understanding of the StackedObjectProxy class and
 am constantly doing battle with it.

I don't think there's anybody who doesn't do battle with StackedObjectProxy.

-- 
Mike Orr [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---