Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 13 20:50

    amol- on master

    3.4 not supported by lxml anymo… (compare)

  • Jul 26 14:08

    amol- on master

    MIT License (compare)

  • Jun 17 12:24
    jneves edited #6
  • Jun 17 12:23
    jneves opened #6
  • Jun 11 21:00

    amol- on 0.5.0

    (compare)

  • Jun 11 21:00

    amol- on master

    Version 0.5.0 (compare)

  • Jun 11 20:59

    amol- on 24-configurator

    (compare)

  • Jun 11 20:58

    amol- on master

    Support for 2.4 ApplicationConf… (compare)

  • Jun 11 20:58
    amol- closed #4
  • Jun 11 20:10
    amol- opened #4
  • Jun 11 20:08

    amol- on 24-configurator

    Add support for tgext.pluggable… (compare)

  • Jun 11 16:51

    amol- on 24-configurator

    Starting support for 2.4 Applic… (compare)

  • May 30 07:53

    amol- on master

    Fix line 872 (#47) redirect ca… (compare)

  • May 30 07:53
    amol- closed #47
  • May 29 12:07
    teejo75 opened #47
  • May 22 12:31

    amol- on development

    replaced Turbogears 2.3 with Tu… fix issue https://github.com/Tu… fix issue https://github.com/Tu… (compare)

  • May 22 12:31
    amol- closed #14
  • May 22 12:28

    amol- on development

    fix for python 3.8: Deprecation… (compare)

  • May 22 12:28
    amol- closed #107
  • May 22 10:02
    CastixGitHub opened #107
Joe Knapka
@jknapka
According to the example code, it seems the extra_environ={"REMOTE_USER":"test_user"} argument to app.get() is supposed to do that, but maybe I misunderstand how this is intended to work.
(In other words by TG magic, I thought, but if I'm wrong I need to figure out how to do it right.)
Nils Philippsen
@nphilipp
Is the class in which your doing this derived from <project>.tests.TestController?
Joe Knapka
@jknapka
According to the quickstarted tests/init.py file, test suites should be run "with authentication disabled so that developers can test protected areas independently [of repoze.who]". Maybe that doesn't mean what I think it means.
Nils Philippsen
@nphilipp
I.e. you're modelling this after <project>.tests.functional.test_root?
Joe Knapka
@jknapka
Yes, exactly: I've copied test_root and am deriving from TestController.
Nils Philippsen
@nphilipp
Do the test_root tests succeed?
Joe Knapka
@jknapka
Yes.
Nils Philippsen
@nphilipp
Where are your tests located?
Joe Knapka
@jknapka
My other tests (that do not depend on particular user logins) also work fine.
project/tests/functional/test_blah.py
Nils Philippsen
@nphilipp
Hmm.
Where is your test_user created?
Ahh you mentioned it.
(Thinking aloud, I should stop that.)
Joe Knapka
@jknapka
In MyTestClass.setUp(). I can just paste the code here, although of course it won't run, but you could see the structure. It's only fifty lines or so. Shall I do that?
Nils Philippsen
@nphilipp
You could pastebin it somewhere.
E.g. as a github gist.
Joe Knapka
@jknapka
Hmm, actually it's a bit more complicated than it needs to be for clarity. I'll find a minimal reproducible case and post that somewhere in a little while.
Nils Philippsen
@nphilipp
I have a hunch that the tested method doesn't see the user because it's not committed to the DB or something similar.
Can you just pastebin the method that creates the user and adds it to the DB?
Joe Knapka
@jknapka
My "minimal reproduction" succeeds (unexpectedly), so I'm sure I'm missing something simple. I'll try to figure it out myself and post here again if I hit a brick wall. (You may very well be right about the DB issue, but I actually call the same utility method to create users in other test cases and that works. So I think it's something about how I've structured this specific test.)
Nils Philippsen
@nphilipp
Do the other test cases work against a test app, like the functional ones do?
Joe Knapka
@jknapka
Some do and some don't. I already figured out (from @amol_) that test fixtures and test cases that don't use a test app have to do manual transaction management, and I'm (probably!) handling that correctly :-D
Joe Knapka
@jknapka
Yep, my test fixture was raising an exception that was rolling back the txn! Thanks for the nudge in the right direction.
Nils Philippsen
@nphilipp
You're welcome!
Alessandro Molina
@amol-

@jknapka I suggest you verify the controller from which you are inheriting. There is a class attribute application_under_test (or something similar) that specified which configuration should be used to create the application instance used for the tests.

By default there are two applications configured in test.ini the main and mainnoauth (or something similar).

The noauth one supports faking authentication with the REMOTE_USER, while the other one requires you do to a self.app.post('/login_handler') to actually log before your can call authenticated endpoints

(It's main_without_authn the app name that accepts REMOTE_USER, just checked the name)
When you quickstart, you can see that there are two examples. test_root which uses main_without_authn (actually doesn't specify anything and main_without_authn is the default) and test_authentication which has application_under_test = 'main' at the begin of the controller.
You can see that tests in test_root can use REMOTE_USER
while the one under test_authentication do use real authentication and cookies
Joe Knapka
@jknapka
Thanks, @amol_ . I found the problem, my test fixture was causing an exception that rolled back its transaction. All the TG machinery around auth forging is working as expected.
Joe Knapka
@jknapka
Hello all, I am trying to add i18n to my TG2.4 application. This seems to have broken many of my test cases with the following exception while calling ugettext():
Traceback (most recent call last):
  File "/Users/jk/Software/py3-venv-2/lib/python3.7/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/Users/jk/Software/unter/src/tg/unter/unter/tests/functional/test_multi_alerts.py", line 86, in test_0_oneVolunteerEvent
    self.sendAlert(ev_id=1)
  File "/Users/jk/Software/unter/src/tg/unter/unter/tests/functional/test_multi_alerts.py", line 82, in sendAlert
    need.checkOneEvent(model.DBSession,ev_id=ev_id,honorLastAlertTime=False)
  File "/Users/jk/Software/unter/src/tg/unter/unter/controllers/need.py", line 27, in checkOneEvent
    debugTest(_("Checking need event {} {}").format(ev_id,notes))
  File "/Users/jk/Software/py3-venv-2/lib/python3.7/site-packages/TurboGears2-2.4.0a1-py3.7.egg/tg/i18n.py", line 87, in ugettext
    return tg.translator.gettext(value)
  File "/Users/jk/Software/py3-venv-2/lib/python3.7/site-packages/TurboGears2-2.4.0a1-py3.7.egg/tg/support/objectproxy.py", line 19, in __getattr__
    return getattr(self._current_obj(), attr)
  File "/Users/jk/Software/py3-venv-2/lib/python3.7/site-packages/TurboGears2-2.4.0a1-py3.7.egg/tg/request_local.py", line 233, in _current_obj
    return getattr(context, self.name)
  File "/Users/jk/Software/py3-venv-2/lib/python3.7/site-packages/TurboGears2-2.4.0a1-py3.7.egg/tg/support/objectproxy.py", line 19, in __getattr__
    return getattr(self._current_obj(), attr)
  File "/Users/jk/Software/py3-venv-2/lib/python3.7/site-packages/TurboGears2-2.4.0a1-py3.7.egg/tg/support/registry.py", line 72, in _current_obj
    'thread' % self.____name__)
TypeError: No object (name: context) has been registered for this thread
I don't know where to begin fixing this. Advice would be appreciated. Thanks!
(Note, need.py is not an actual TG controller, it's just a file with some utility methods that get tested separately.)
Joe Knapka
@jknapka
I guess that tg.uggettext () depends on being inside a request, so probably I need to switch to using the GNU gettext API inside these utility files.
Joe Knapka
@jknapka
...Actually using the raw gettext API seems like a bad idea, since this utility code will then need to jump through hoops to figure out what the request's locale is when it is running inside a web request. So... it looks like I need to figure out how to "register an object named context for this thread" in my non-web-request test code. I guess that's probably handled by middleware, usually?
Joe Knapka
@jknapka
Looking at the TG i18n docs, it seems to say that lazy_ugettext() should work without an active request. However, replacing all the _() calls with l_() calls in my utility code does not solve the problem. For the moment I've "solved" the problem by using my own _() and l_() functions that check whether a context exists, and if not, returns the untranslated string. This doesn't seem like an especially good solution, though.
Alessandro Molina
@amol-
@jknapka yeah, TG can't resolve the translation if it doesn't know the current request. Because the language you want to translate to is the one provided by the browser usually. But lazy_ugettext can solve that problem if you don't try to resolve the string. Like if you try to print, show or concatenate the string it will resolve it.
Nils Philippsen
@nphilipp

@jknapka another idea would be to mock-patch _() in the "offending" module, e.g. like this (careful, untested):

from unittest.mock import patch
...
    @patch('unter.controllers.need._', lambda x: x)
    def test_0_oneVolunteerEvent(self, ..., patched_gettext):
        ...
        self.sendAlert(ev_id=1)
        ...

This will replace _() in unter.controllers.need with a lambda that simply returns the untranslated text while the decorated test method is executed (and pass it into the method as patched_gettext in case you want to inspect it in your test).

Alessandro Molina
@amol-

Ah, if we are talking about tests, I think this is what you are looking for: https://turbogears.readthedocs.io/en/latest/turbogears/testing.html#testing-outside-controllers

So that you have a translator in place even without a request

Nils Philippsen
@nphilipp
I knew there was something more straightforward! :grinning:
Joe Knapka
@jknapka
Ah yes, that is exactly what I was looking for. Probably I should just read all the TG docs from start to finish :-P
Alessandro Molina
@amol-
TG trending
2.4 release made TG pop up in trending repositories on GitHub o_O
Nils Philippsen
@nphilipp

2.4 release

:raised_hands:

Berthoud Yannick
@YannickBerthoud_twitter
Hi, I need your help to change de login options to use the email_adress field. The doc refer to use "ApplicationAuthMetadata" in app_cfg.py but I don't see any options about this :(
Alessandro Molina
@amol-
It's not an option per se, but you can easily achieve that by changing the ApplicationAuthMetadata class in app_cfg to use .email_address wherever it is using .user_name
Berthoud Yannick
@YannickBerthoud_twitter
ah, ok, thanks !
it's working, good job ! thanks a lot