Mailing List Archive

Mocking PSGI layers in Test WWW Mechanize Catalyst
Hi,
I wondered if there's any prior art around on inserting (mocked) PSGI
layers into Test::WWW::Mechanize:Catalyst?

Cheers,
Toby

--
Turning and turning in the widening gyre
The falcon cannot hear the falconer
Things fall apart; the center cannot hold
Mere anarchy is loosed upon the world

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Re: Mocking PSGI layers in Test WWW Mechanize Catalyst [ In reply to ]
Not sure what you mean, is there an example in another framework you can point to?

johnn



On Thursday, October 31, 2013 12:55 AM, Toby Corkindale <toby@dryft.net> wrote:

Hi,
I wondered if there's any prior art around on inserting (mocked) PSGI
layers into Test::WWW::Mechanize:Catalyst?

Cheers,
Toby

--
Turning and turning in the widening gyre
The falcon cannot hear the falconer
Things fall apart; the center cannot hold
Mere anarchy is loosed upon the world

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Re: Mocking PSGI layers in Test WWW Mechanize Catalyst [ In reply to ]
Umm, not that I know of.

I suppose another way to phrase the question is: Is there a way to
manipulate the $c->engine->env in the Catalyst application, from
within unit tests neatly?

On 1 November 2013 08:35, John Napiorkowski <jjn1056@yahoo.com> wrote:
> Not sure what you mean, is there an example in another framework you can
> point to?
>
> johnn
>
>
> On Thursday, October 31, 2013 12:55 AM, Toby Corkindale <toby@dryft.net>
> wrote:
> Hi,
> I wondered if there's any prior art around on inserting (mocked) PSGI
> layers into Test::WWW::Mechanize:Catalyst?
>
> Cheers,
> Toby
>
> --
> Turning and turning in the widening gyre
> The falcon cannot hear the falconer
> Things fall apart; the center cannot hold
> Mere anarchy is loosed upon the world
>
> _______________________________________________
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>
>
>
> _______________________________________________
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>



--
Turning and turning in the widening gyre
The falcon cannot hear the falconer
Things fall apart; the center cannot hold
Mere anarchy is loosed upon the world

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Re: Mocking PSGI layers in Test WWW Mechanize Catalyst [ In reply to ]
You mean you want two apps interacting with each other in the same script using WWW::MEchanize? Eden and I were working some docs up on that topic until real life intervened.

This was the start of it:

http://paste.scsys.co.uk/273844

On 01/11/2013, at 11:39 AM, Toby Corkindale wrote:

> Umm, not that I know of.
>
> I suppose another way to phrase the question is: Is there a way to
> manipulate the $c->engine->env in the Catalyst application, from
> within unit tests neatly?
>
> On 1 November 2013 08:35, John Napiorkowski <jjn1056@yahoo.com> wrote:
>> Not sure what you mean, is there an example in another framework you can
>> point to?
>>
>> johnn
>>
>>
>> On Thursday, October 31, 2013 12:55 AM, Toby Corkindale <toby@dryft.net>
>> wrote:
>> Hi,
>> I wondered if there's any prior art around on inserting (mocked) PSGI
>> layers into Test::WWW::Mechanize:Catalyst?
>>
>> Cheers,
>> Toby
>>
>> --
>> Turning and turning in the widening gyre
>> The falcon cannot hear the falconer
>> Things fall apart; the center cannot hold
>> Mere anarchy is loosed upon the world
>>
>> _______________________________________________
>> List: Catalyst@lists.scsys.co.uk
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>> Dev site: http://dev.catalyst.perl.org/
>>
>>
>>
>> _______________________________________________
>> List: Catalyst@lists.scsys.co.uk
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>> Dev site: http://dev.catalyst.perl.org/
>>
>
>
>
> --
> Turning and turning in the widening gyre
> The falcon cannot hear the falconer
> Things fall apart; the center cannot hold
> Mere anarchy is loosed upon the world
>
> _______________________________________________
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/


_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Re: Mocking PSGI layers in Test WWW Mechanize Catalyst [ In reply to ]
It looks like there is an undocumented feature in Catalyst::Test, a
callback to let you modify the request.
$args->{mangle_request}->($request) if $args->{mangle_request};
Or alternatively I can subclass the module and extend
_customize_request() to add more to the PSGI environment.


On 1 November 2013 11:39, Toby Corkindale <toby@dryft.net> wrote:
> Umm, not that I know of.
>
> I suppose another way to phrase the question is: Is there a way to
> manipulate the $c->engine->env in the Catalyst application, from
> within unit tests neatly?
>
> On 1 November 2013 08:35, John Napiorkowski <jjn1056@yahoo.com> wrote:
>> Not sure what you mean, is there an example in another framework you can
>> point to?
>>
>> johnn
>>
>>
>> On Thursday, October 31, 2013 12:55 AM, Toby Corkindale <toby@dryft.net>
>> wrote:
>> Hi,
>> I wondered if there's any prior art around on inserting (mocked) PSGI
>> layers into Test::WWW::Mechanize:Catalyst?
>>
>> Cheers,
>> Toby
>>
>> --
>> Turning and turning in the widening gyre
>> The falcon cannot hear the falconer
>> Things fall apart; the center cannot hold
>> Mere anarchy is loosed upon the world
>>
>> _______________________________________________
>> List: Catalyst@lists.scsys.co.uk
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>> Dev site: http://dev.catalyst.perl.org/
>>
>>
>>
>> _______________________________________________
>> List: Catalyst@lists.scsys.co.uk
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>> Dev site: http://dev.catalyst.perl.org/
>>
>
>
>
> --
> Turning and turning in the widening gyre
> The falcon cannot hear the falconer
> Things fall apart; the center cannot hold
> Mere anarchy is loosed upon the world



--
Turning and turning in the widening gyre
The falcon cannot hear the falconer
Things fall apart; the center cannot hold
Mere anarchy is loosed upon the world

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Re: Mocking PSGI layers in Test WWW Mechanize Catalyst [ In reply to ]
On 1 November 2013 12:01, Kieren Diment <diment@gmail.com> wrote:
> You mean you want two apps interacting with each other in the same script using WWW::MEchanize? Eden and I were working some docs up on that topic until real life intervened.
>
> This was the start of it:
>
> http://paste.scsys.co.uk/273844

Not exactly -- in this case I have a PSGI layer that is supposed to
inject some extra information into the env for consumption by the
application.

A simple example would be if you had a PSGI layer providing, say,
Basic HTTP auth, and setting the REMOTE_USER variable.
Although in my case, there's a bit more to it than that.

T

> On 01/11/2013, at 11:39 AM, Toby Corkindale wrote:
>
>> Umm, not that I know of.
>>
>> I suppose another way to phrase the question is: Is there a way to
>> manipulate the $c->engine->env in the Catalyst application, from
>> within unit tests neatly?
>>
>> On 1 November 2013 08:35, John Napiorkowski <jjn1056@yahoo.com> wrote:
>>> Not sure what you mean, is there an example in another framework you can
>>> point to?
>>>
>>> johnn
>>>
>>>
>>> On Thursday, October 31, 2013 12:55 AM, Toby Corkindale <toby@dryft.net>
>>> wrote:
>>> Hi,
>>> I wondered if there's any prior art around on inserting (mocked) PSGI
>>> layers into Test::WWW::Mechanize:Catalyst?
>>>
>>> Cheers,
>>> Toby
>>>
>>> --
>>> Turning and turning in the widening gyre
>>> The falcon cannot hear the falconer
>>> Things fall apart; the center cannot hold
>>> Mere anarchy is loosed upon the world
>>>
>>> _______________________________________________
>>> List: Catalyst@lists.scsys.co.uk
>>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>>> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>>> Dev site: http://dev.catalyst.perl.org/
>>>
>>>
>>>
>>> _______________________________________________
>>> List: Catalyst@lists.scsys.co.uk
>>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>>> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>>> Dev site: http://dev.catalyst.perl.org/
>>>
>>
>>
>>
>> --
>> Turning and turning in the widening gyre
>> The falcon cannot hear the falconer
>> Things fall apart; the center cannot hold
>> Mere anarchy is loosed upon the world
>>
>> _______________________________________________
>> List: Catalyst@lists.scsys.co.uk
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>> Dev site: http://dev.catalyst.perl.org/
>
>
> _______________________________________________
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/



--
Turning and turning in the widening gyre
The falcon cannot hear the falconer
Things fall apart; the center cannot hold
Mere anarchy is loosed upon the world

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Re: Mocking PSGI layers in Test WWW Mechanize Catalyst [ In reply to ]
On 01/11/2013, at 12:26 PM, Toby Corkindale wrote:

> On 1 November 2013 12:01, Kieren Diment <diment@gmail.com> wrote:
>> You mean you want two apps interacting with each other in the same script using WWW::MEchanize? Eden and I were working some docs up on that topic until real life intervened.
>>
>> This was the start of it:
>>
>> http://paste.scsys.co.uk/273844
>
> Not exactly -- in this case I have a PSGI layer that is supposed to
> inject some extra information into the env for consumption by the
> application.
>
> A simple example would be if you had a PSGI layer providing, say,
> Basic HTTP auth, and setting the REMOTE_USER variable.
> Although in my case, there's a bit more to it than that.
>
> T

Does the paste set you in the right direction?
_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Re: Mocking PSGI layers in Test WWW Mechanize Catalyst [ In reply to ]
On 1 November 2013 12:29, Kieren Diment <diment@gmail.com> wrote:
> On 01/11/2013, at 12:26 PM, Toby Corkindale wrote:
>> On 1 November 2013 12:01, Kieren Diment <diment@gmail.com> wrote:
>>> You mean you want two apps interacting with each other in the same script using WWW::MEchanize? Eden and I were working some docs up on that topic until real life intervened.
>>>
>>> This was the start of it:
>>>
>>> http://paste.scsys.co.uk/273844
>>
>> Not exactly -- in this case I have a PSGI layer that is supposed to
>> inject some extra information into the env for consumption by the
>> application.
>>
>> A simple example would be if you had a PSGI layer providing, say,
>> Basic HTTP auth, and setting the REMOTE_USER variable.
>> Although in my case, there's a bit more to it than that.
>>
>> T
>
> Does the paste set you in the right direction?

It's helpful for showing how to build a test-www-mechanize-psgi :)

--
Turning and turning in the widening gyre
The falcon cannot hear the falconer
Things fall apart; the center cannot hold
Mere anarchy is loosed upon the world

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Re: Mocking PSGI layers in Test WWW Mechanize Catalyst [ In reply to ]
Catalyst::Test uses Plack::Test under the hood.  That mangle_response stuff is mostly evil :)

Sounds like you are saying you'd like to apply Plack Middleware during testing.  The latest dev release on CPAN lets you configure middleware via configuration, so you could have some middleware in your test configuration.  This use case is one of the reasons I added this feature, so that we could manage middleware for catalyst inside of catalyst configuration.

If you don't like that approach, I could be talked into a patch to Catalyst::Test that would let you declare additional middleware in the test case.

I'd prefer this over messing with Catalyst::Test internals.  One of the hard things about trying to move Catalyst forward is that we've expose a ton of API that we fear to change since we don't know who is overriding what in the Darkpan.  Ideally I'd like to see people use Plack Middleware for jobs involving modifying the request and response, since that is something its great at, and the API is just a code ref, so its very well decoupled (could even be used outside of Catalyst).

Good luck!

John



On Thursday, October 31, 2013 8:26 PM, Toby Corkindale <toby@dryft.net> wrote:

On 1 November 2013 12:01, Kieren Diment <diment@gmail.com> wrote:
> You mean you want two apps interacting with each other in the same script using WWW::MEchanize?  Eden and I were working some docs up on that topic until real life intervened.
>
> This was the start of it:
>
> http://paste.scsys.co.uk/273844

Not exactly -- in this case I have a PSGI layer that is supposed to
inject some extra information into the env for consumption by the
application.

A simple example would be if you had a PSGI layer providing, say,
Basic HTTP auth, and setting the REMOTE_USER variable.
Although in my case, there's a bit more to it than that.

T

> On 01/11/2013, at 11:39 AM, Toby Corkindale wrote:
>
>> Umm, not that I know of.
>>
>> I suppose another way to phrase the question is: Is there a way to
>> manipulate the $c->engine->env in the Catalyst application, from
>> within unit tests neatly?
>>
>> On 1 November 2013 08:35, John Napiorkowski <jjn1056@yahoo.com> wrote:
>>> Not sure what you mean, is there an example in another framework you can
>>> point to?
>>>
>>> johnn
>>>
>>>
>>> On Thursday, October 31, 2013 12:55 AM, Toby Corkindale <toby@dryft.net>
>>> wrote:
>>> Hi,
>>> I wondered if there's any prior art around on inserting (mocked) PSGI
>>> layers into Test::WWW::Mechanize:Catalyst?
>>>
>>> Cheers,
>>> Toby
>>>
>>> --
>>> Turning and turning in the widening gyre
>>> The falcon cannot hear the falconer
>>> Things fall apart; the center cannot hold
>>> Mere anarchy is loosed upon the world
>>>
>>> _______________________________________________
>>> List: Catalyst@lists.scsys.co.uk
>>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>>> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>>> Dev site: http://dev.catalyst.perl.org/
>>>
>>>
>>>
>>> _______________________________________________
>>> List: Catalyst@lists.scsys.co.uk
>>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>>> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>>> Dev site: http://dev.catalyst.perl.org/

>>>
>>
>>
>>
>> --
>> Turning and turning in the widening gyre
>> The falcon cannot hear the falconer
>> Things fall apart; the center cannot hold
>> Mere anarchy is loosed upon the world
>>
>> _______________________________________________
>> List: Catalyst@lists.scsys.co.uk
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>> Dev site: http://dev.catalyst.perl.org/
>
>
> _______________________________________________
> List: Catalyst@lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/



--
Turning and turning in the widening gyre
The falcon cannot hear the falconer
Things fall apart; the center cannot hold
Mere anarchy is loosed upon the world

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
Re: Mocking PSGI layers in Test WWW Mechanize Catalyst [ In reply to ]
On 2 November 2013 02:39, John Napiorkowski <jjn1056@yahoo.com> wrote:
> Catalyst::Test uses Plack::Test under the hood. That mangle_response stuff
> is mostly evil :)
>
> Sounds like you are saying you'd like to apply Plack Middleware during
> testing. The latest dev release on CPAN lets you configure middleware via
> configuration, so you could have some middleware in your test configuration.
> This use case is one of the reasons I added this feature, so that we could
> manage middleware for catalyst inside of catalyst configuration.

That's correct -- I'd like to apply some plack middleware, which is a
mocked-up-for-testing version of some middleware we run in production.
Since the app now depends upon it, being able to specify it in the
catalyst config would be fine.

> If you don't like that approach, I could be talked into a patch to
> Catalyst::Test that would let you declare additional middleware in the test
> case.
>
> I'd prefer this over messing with Catalyst::Test internals. One of the hard
> things about trying to move Catalyst forward is that we've expose a ton of
> API that we fear to change since we don't know who is overriding what in the
> Darkpan. Ideally I'd like to see people use Plack Middleware for jobs
> involving modifying the request and response, since that is something its
> great at, and the API is just a code ref, so its very well decoupled (could
> even be used outside of Catalyst).

Thanks John. I'll keep an eye out for the new release! (but will be
hacking up something nasty and temporary until then so I can get some
unit tests passing again..)

Cheers,
Toby

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/