Sunday, July 31, 2016

Re: Testing if a view have an html element with at least one attribute

Jupp, thats about what I meant :-)

Probably the best way, if you don't want to check text.

Regards,

Andréas

2016-07-31 18:01 GMT+02:00 ludovic coues <couesl@gmail.com>:
Currently, I am using lxml. More dependencies but it's the cleanest
method I've found currently.
I use it like that:

    from django.test import TestCase
    from lxml import etree

    class FormTest(TestCase):
        def test_input(self):
            response = self.client.get('/accounts/login')
            self.assertEqual(response.status_code, 200)
            doc = etree.HTML(response.content)
            self.assertEqual(len(doc.findall('.//input[@name="username"]')), 1)



2016-07-31 17:46 GMT+02:00 Andreas Kuhne <andreas.kuhne@suitopia.com>:
> 2016-07-31 15:59 GMT+02:00 ludovic coues <couesl@gmail.com>:
>>
>> Oh, sorry. A bit of misunderstanding and miscommunication on my part.
>>
>> The exemple I gave is just a quick way to reproduce my problem. The
>> real test use self.client, reverse, cast response.content to a string.
>> What I gave is a minimal exemple.
>>
>> Also, I assumed you talked about comparing bit of html element, not
>> the raw content returned by the view. I'm quite uneasy to have the
>> test failing if a class is added or removed from the element. But yes,
>> your solution work for the current state of the application.
>>
>> 2016-07-31 14:46 GMT+02:00 Andreas Kuhne <andreas.kuhne@suitopia.com>:
>> > 2016-07-31 13:56 GMT+02:00 ludovic coues <couesl@gmail.com>:
>> >>
>> >> First, thanks for the suggestion.
>> >>
>> >> I just tried that, didn't work.
>> >> Here is the test file I used:
>> >>
>> >>
>> >>     from django.test import TestCase
>> >>
>> >>     class HTMLTestCase(TestCase):
>> >>
>> >>         def test_input_in_fieldset(self):
>> >>             fieldset = """
>> >>         <fieldset class="form-group">
>> >>             <input name="login">
>> >>             <input autofocus="" class="form-control" id="id_username"
>> >> maxlength="254" name="username" rows="3" type="text" required />
>> >>         </fieldset>
>> >>     """
>> >>             self.assertInHTML('<input name=login>', fieldset)
>> >>             self.assertInHTML('<input name="username">', fieldset)
>> >>
>> >>
>> >> First input is to have a working exemple, second is taken as is from
>> >> my view. Not closing the input in assertInHTML give an error `Couldn't
>> >> find '<input name="login"' in response`. I assume I would get the same
>> >> errors with assertContains(*args, html=True)
>> >>
>> >> I could copy/past the input directly in my test but if the maxlength
>> >> or class attribute change, the test will break. Taking the input
>> >> directly from the django form will test if the django form is rendered
>> >> in the view, not if the view is displaying a suitable form.
>> >>
>> >> 2016-07-31 13:22 GMT+02:00 Andreas Kuhne <andreas.kuhne@suitopia.com>:
>> >> > 2016-07-31 12:38 GMT+02:00 ludovic coues <couesl@gmail.com>:
>> >> >>
>> >> >> Hello,
>> >> >>
>> >> >> I am trying to test if a view is displaying a form with an input
>> >> >> element with name=username.
>> >> >>
>> >> >> Currently, I have tried a lot of variation around
>> >> >> `self.assertContains( response, "<input name=\"username\">",
>> >> >> html=True)` but none work.
>> >> >> I assume that doesn't work because the view have a field input with
>> >> >> name=username but also autofocus="", a class and a bunch of other
>> >> >> attribute.
>> >> >>
>> >> >> I could extract the form from the context and check the field
>> >> >> username
>> >> >> from the form is displayed in the view but I'm not ok with that
>> >> >> solution. I'm testing if there is a input with name=username, not a
>> >> >> bunch of unrelated attribute.
>> >> >>
>> >> >> I could also use a LiveServerTestCase and selenium but that look
>> >> >> like
>> >> >> a bit overkill for my need. lxml is another option but it would
>> >> >> bring
>> >> >> more dependencies.
>> >> >>
>> >> >> A bit of help would be welcome :)
>> >> >>
>> >> >>
>> >> >>
>> >> >> --
>> >> >>
>> >> >> Cordialement, Coues Ludovic
>> >> >> +336 148 743 42
>> >> >>
>> >> >> --
>> >> >> You received this message because you are subscribed to the Google
>> >> >> Groups
>> >> >> "Django users" group.
>> >> >> To unsubscribe from this group and stop receiving emails from it,
>> >> >> send
>> >> >> an
>> >> >> email to django-users+unsubscribe@googlegroups.com.
>> >> >> To post to this group, send email to django-users@googlegroups.com.
>> >> >> Visit this group at https://groups.google.com/group/django-users.
>> >> >> To view this discussion on the web visit
>> >> >>
>> >> >>
>> >> >> https://groups.google.com/d/msgid/django-users/CAEuG%2BTah74hdZMv%2BwdZPPq5PLaJ%3DhxOFMNXuVLfFYSw2Uz4N0w%40mail.gmail.com.
>> >> >> For more options, visit https://groups.google.com/d/optout.
>> >> >
>> >> >
>> >> > Django usually creates the inputs the same way, so what I do in my
>> >> > tests
>> >> > is
>> >> > to first dump the content of the response body on the screen and then
>> >> > copy
>> >> > the input statement from there. What you probably need is '<input
>> >> > name="username"', because it doesn't matter for your test if the html
>> >> > tag is
>> >> > closed. So you should be fine with:
>> >> > self.assertContains(response, '<input name="username"')
>> >> >
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "Django users" group.
>> >> > To unsubscribe from this group and stop receiving emails from it,
>> >> > send
>> >> > an
>> >> > email to django-users+unsubscribe@googlegroups.com.
>> >> > To post to this group, send email to django-users@googlegroups.com.
>> >> > Visit this group at https://groups.google.com/group/django-users.
>> >> > To view this discussion on the web visit
>> >> >
>> >> >
>> >> > https://groups.google.com/d/msgid/django-users/CALXYUbmmotLwzjZY6ZZnAqy21xqZN1%3DiE7ah3g5JxFgEw-POZg%40mail.gmail.com.
>> >> > For more options, visit https://groups.google.com/d/optout.
>> >>
>> >>
>> >>
>> >> --
>> >>
>> >> Cordialement, Coues Ludovic
>> >> +336 148 743 42
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "Django users" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> >> an
>> >> email to django-users+unsubscribe@googlegroups.com.
>> >> To post to this group, send email to django-users@googlegroups.com.
>> >> Visit this group at https://groups.google.com/group/django-users.
>> >> To view this discussion on the web visit
>> >>
>> >> https://groups.google.com/d/msgid/django-users/CAEuG%2BTZCWDkkrZuP2N168pth1hL-gc8FrVjMwZnb3xS%2BK1X%2Bxw%40mail.gmail.com.
>> >> For more options, visit https://groups.google.com/d/optout.
>> >
>> >
>> > Hi,
>> >
>> > I think you have misunderstood me.
>> >
>> > First you need to check against the real response object, otherwise your
>> > test will only test if the item is present in your string, which is not
>> > what
>> > I meant. I meant that you should check what HTML django is generating to
>> > then get the correct information.
>> >
>> > In your case, I am now guessing that the output of django is the
>> > information
>> > you put into the fieldset variable?
>> >
>> > If so, you need to write
>> > self.assertContains(response,'<input autofocus="" class="form-control"
>> > id="id_username" maxlength="254" name="username"')
>> >
>> > The assertContains does not parse the html in any way, but uses a search
>> > for
>> > the text you entered. So if the text has 'autofocus=""
>> > class="form-control"
>> > id="id_username" maxlength="254"' before 'name="username"', then you
>> > need to
>> > add that as well, otherwise you won't find the text at all.
>> >
>> > Regards,
>> >
>> > Andréas
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Django users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to django-users+unsubscribe@googlegroups.com.
>> > To post to this group, send email to django-users@googlegroups.com.
>> > Visit this group at https://groups.google.com/group/django-users.
>> > To view this discussion on the web visit
>> >
>> > https://groups.google.com/d/msgid/django-users/CALXYUbkp-oM3Y9dUYEcb8kbQT0kS95hDBqxVWMu8Cn-8iYQv3w%40mail.gmail.com.
>> >
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>>
>> Cordialement, Coues Ludovic
>> +336 148 743 42
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscribe@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAEuG%2BTY%3DcbadWnm85-M2YEs2%3DwwH6gjLpnOGhLXjEpq-rGLGHw%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> Hi again,
>
> I understand your problem with a test failing if a class is added, however,
> there is no other way to check this (as far as I know). If you want to
> explicitly check for an input with the name "username", I would probably try
> using xml. That way you could use xpath to search quickly.
>
> Regards,
>
> Andréas
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALXYUbm5vcL%3Dz7qr7ZeS%2BMuNjH6LYscT9tr3Y3k0X3RLAAbEsQ%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTYm3Wq_zFzPaObx_5zVBpNQ0HUdnTHRzCtky45u2aZjNw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALXYUb%3Do4rzvrEP9cVFB__0qyUwpURseM_WAgRSXkY75v2iibA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: jasig cas integration

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCAAGBQJXnix2AAoJEOdSAnixd0RIS9gP/1zTtDkd8TrVCxRfM4I2Cp3Y
4T1ARLGYX/3JTeGD79WlLY0id9GddYfiGS3lK97XcXdco4IpbPgYE/4UeV9PmOdP
3pzs78ZQ58QxnN5xMeEeVDTBlyQk48p7GIqw7PLDxj4dZXLiQy6RJHeVYodjsFek
l4Sc/tsVrsqrq5Gi/RxQXE15yKm224Ihmt4UtcufsPRkFFMNWsfAjcyWUOwHpmcE
GEsZVAR9ApVLOx0l6kQTi4KoQ+B2Qrn9y+q/GB5QUI5qx2ys965XlBwLQGvJXgGl
3m5MngxE3w1uD6sjM3eCHsuwu21nFzVPxxomqgZe+iIafvNOyt8H532iX/fsMulY
P9U5oH1EsRhn4rZP80f8ARMRjPMPdlg/uyETSKb7CG3vT8wbrDo9XQQubhCnYpfr
SyEFTixBM7R3TTKhc6ZwyRrOP2W4rkbpxAOLUpI4pGdnpFZXRGNbcTDdbnXNWB6w
Eis9t/+au3G8c2IR2x7R88KkCGNZgFk2ezZ0cgszR23PgQXqLdPTOqsx9Rm9sSxE
EdQT0uOOzJCVJIkM6soqC3Wtq4Za3Wl9R3hj2sOZZtUlwmKibv/a9YrRTUb+FFT5
LGmXiQT/k8N2A83O0a5KywhGjYCWqv43A3v9Mu8GYQPY2Xqyo/jIBt68p/cpHpfq
vKyPN/ArauJg+/niBZt1
=jDaR
-----END PGP SIGNATURE-----
Hi,

Jasig works perfectly fine with django-cas but the django-cas-ng module
has to be prefered to it's old and no longer supported predecessor.

Cheers !
Martin Pépin

Le 31/07/2016 à 13:48, Mahyar Damavand a écrit :
> Hi all,
> Is it possible to integrate django-cas client with a Jasig cas server or not
> If it is not what cas server should i use?
>
>
> I have to explain that a 403 forbidden error prevent
> authentication ending successfully.
> something like this not answered question:
> 403 Forbidden and jasig cas integration
> <https://groups.google.com/d/msg/django-users/V7YxDhfIZqo/65YB6J9BtbIJ>
>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/42761647-a51d-b8fd-1d6f-dfb63323c323%40wkerl.me.
For more options, visit https://groups.google.com/d/optout.

Re: Testing if a view have an html element with at least one attribute

Currently, I am using lxml. More dependencies but it's the cleanest
method I've found currently.
I use it like that:

from django.test import TestCase
from lxml import etree

class FormTest(TestCase):
def test_input(self):
response = self.client.get('/accounts/login')
self.assertEqual(response.status_code, 200)
doc = etree.HTML(response.content)
self.assertEqual(len(doc.findall('.//input[@name="username"]')), 1)



2016-07-31 17:46 GMT+02:00 Andreas Kuhne <andreas.kuhne@suitopia.com>:
> 2016-07-31 15:59 GMT+02:00 ludovic coues <couesl@gmail.com>:
>>
>> Oh, sorry. A bit of misunderstanding and miscommunication on my part.
>>
>> The exemple I gave is just a quick way to reproduce my problem. The
>> real test use self.client, reverse, cast response.content to a string.
>> What I gave is a minimal exemple.
>>
>> Also, I assumed you talked about comparing bit of html element, not
>> the raw content returned by the view. I'm quite uneasy to have the
>> test failing if a class is added or removed from the element. But yes,
>> your solution work for the current state of the application.
>>
>> 2016-07-31 14:46 GMT+02:00 Andreas Kuhne <andreas.kuhne@suitopia.com>:
>> > 2016-07-31 13:56 GMT+02:00 ludovic coues <couesl@gmail.com>:
>> >>
>> >> First, thanks for the suggestion.
>> >>
>> >> I just tried that, didn't work.
>> >> Here is the test file I used:
>> >>
>> >>
>> >> from django.test import TestCase
>> >>
>> >> class HTMLTestCase(TestCase):
>> >>
>> >> def test_input_in_fieldset(self):
>> >> fieldset = """
>> >> <fieldset class="form-group">
>> >> <input name="login">
>> >> <input autofocus="" class="form-control" id="id_username"
>> >> maxlength="254" name="username" rows="3" type="text" required />
>> >> </fieldset>
>> >> """
>> >> self.assertInHTML('<input name=login>', fieldset)
>> >> self.assertInHTML('<input name="username">', fieldset)
>> >>
>> >>
>> >> First input is to have a working exemple, second is taken as is from
>> >> my view. Not closing the input in assertInHTML give an error `Couldn't
>> >> find '<input name="login"' in response`. I assume I would get the same
>> >> errors with assertContains(*args, html=True)
>> >>
>> >> I could copy/past the input directly in my test but if the maxlength
>> >> or class attribute change, the test will break. Taking the input
>> >> directly from the django form will test if the django form is rendered
>> >> in the view, not if the view is displaying a suitable form.
>> >>
>> >> 2016-07-31 13:22 GMT+02:00 Andreas Kuhne <andreas.kuhne@suitopia.com>:
>> >> > 2016-07-31 12:38 GMT+02:00 ludovic coues <couesl@gmail.com>:
>> >> >>
>> >> >> Hello,
>> >> >>
>> >> >> I am trying to test if a view is displaying a form with an input
>> >> >> element with name=username.
>> >> >>
>> >> >> Currently, I have tried a lot of variation around
>> >> >> `self.assertContains( response, "<input name=\"username\">",
>> >> >> html=True)` but none work.
>> >> >> I assume that doesn't work because the view have a field input with
>> >> >> name=username but also autofocus="", a class and a bunch of other
>> >> >> attribute.
>> >> >>
>> >> >> I could extract the form from the context and check the field
>> >> >> username
>> >> >> from the form is displayed in the view but I'm not ok with that
>> >> >> solution. I'm testing if there is a input with name=username, not a
>> >> >> bunch of unrelated attribute.
>> >> >>
>> >> >> I could also use a LiveServerTestCase and selenium but that look
>> >> >> like
>> >> >> a bit overkill for my need. lxml is another option but it would
>> >> >> bring
>> >> >> more dependencies.
>> >> >>
>> >> >> A bit of help would be welcome :)
>> >> >>
>> >> >>
>> >> >>
>> >> >> --
>> >> >>
>> >> >> Cordialement, Coues Ludovic
>> >> >> +336 148 743 42
>> >> >>
>> >> >> --
>> >> >> You received this message because you are subscribed to the Google
>> >> >> Groups
>> >> >> "Django users" group.
>> >> >> To unsubscribe from this group and stop receiving emails from it,
>> >> >> send
>> >> >> an
>> >> >> email to django-users+unsubscribe@googlegroups.com.
>> >> >> To post to this group, send email to django-users@googlegroups.com.
>> >> >> Visit this group at https://groups.google.com/group/django-users.
>> >> >> To view this discussion on the web visit
>> >> >>
>> >> >>
>> >> >> https://groups.google.com/d/msgid/django-users/CAEuG%2BTah74hdZMv%2BwdZPPq5PLaJ%3DhxOFMNXuVLfFYSw2Uz4N0w%40mail.gmail.com.
>> >> >> For more options, visit https://groups.google.com/d/optout.
>> >> >
>> >> >
>> >> > Django usually creates the inputs the same way, so what I do in my
>> >> > tests
>> >> > is
>> >> > to first dump the content of the response body on the screen and then
>> >> > copy
>> >> > the input statement from there. What you probably need is '<input
>> >> > name="username"', because it doesn't matter for your test if the html
>> >> > tag is
>> >> > closed. So you should be fine with:
>> >> > self.assertContains(response, '<input name="username"')
>> >> >
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "Django users" group.
>> >> > To unsubscribe from this group and stop receiving emails from it,
>> >> > send
>> >> > an
>> >> > email to django-users+unsubscribe@googlegroups.com.
>> >> > To post to this group, send email to django-users@googlegroups.com.
>> >> > Visit this group at https://groups.google.com/group/django-users.
>> >> > To view this discussion on the web visit
>> >> >
>> >> >
>> >> > https://groups.google.com/d/msgid/django-users/CALXYUbmmotLwzjZY6ZZnAqy21xqZN1%3DiE7ah3g5JxFgEw-POZg%40mail.gmail.com.
>> >> > For more options, visit https://groups.google.com/d/optout.
>> >>
>> >>
>> >>
>> >> --
>> >>
>> >> Cordialement, Coues Ludovic
>> >> +336 148 743 42
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "Django users" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> >> an
>> >> email to django-users+unsubscribe@googlegroups.com.
>> >> To post to this group, send email to django-users@googlegroups.com.
>> >> Visit this group at https://groups.google.com/group/django-users.
>> >> To view this discussion on the web visit
>> >>
>> >> https://groups.google.com/d/msgid/django-users/CAEuG%2BTZCWDkkrZuP2N168pth1hL-gc8FrVjMwZnb3xS%2BK1X%2Bxw%40mail.gmail.com.
>> >> For more options, visit https://groups.google.com/d/optout.
>> >
>> >
>> > Hi,
>> >
>> > I think you have misunderstood me.
>> >
>> > First you need to check against the real response object, otherwise your
>> > test will only test if the item is present in your string, which is not
>> > what
>> > I meant. I meant that you should check what HTML django is generating to
>> > then get the correct information.
>> >
>> > In your case, I am now guessing that the output of django is the
>> > information
>> > you put into the fieldset variable?
>> >
>> > If so, you need to write
>> > self.assertContains(response,'<input autofocus="" class="form-control"
>> > id="id_username" maxlength="254" name="username"')
>> >
>> > The assertContains does not parse the html in any way, but uses a search
>> > for
>> > the text you entered. So if the text has 'autofocus=""
>> > class="form-control"
>> > id="id_username" maxlength="254"' before 'name="username"', then you
>> > need to
>> > add that as well, otherwise you won't find the text at all.
>> >
>> > Regards,
>> >
>> > Andréas
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Django users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to django-users+unsubscribe@googlegroups.com.
>> > To post to this group, send email to django-users@googlegroups.com.
>> > Visit this group at https://groups.google.com/group/django-users.
>> > To view this discussion on the web visit
>> >
>> > https://groups.google.com/d/msgid/django-users/CALXYUbkp-oM3Y9dUYEcb8kbQT0kS95hDBqxVWMu8Cn-8iYQv3w%40mail.gmail.com.
>> >
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>>
>> Cordialement, Coues Ludovic
>> +336 148 743 42
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscribe@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAEuG%2BTY%3DcbadWnm85-M2YEs2%3DwwH6gjLpnOGhLXjEpq-rGLGHw%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> Hi again,
>
> I understand your problem with a test failing if a class is added, however,
> there is no other way to check this (as far as I know). If you want to
> explicitly check for an input with the name "username", I would probably try
> using xml. That way you could use xpath to search quickly.
>
> Regards,
>
> Andréas
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALXYUbm5vcL%3Dz7qr7ZeS%2BMuNjH6LYscT9tr3Y3k0X3RLAAbEsQ%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTYm3Wq_zFzPaObx_5zVBpNQ0HUdnTHRzCtky45u2aZjNw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Testing if a view have an html element with at least one attribute

2016-07-31 15:59 GMT+02:00 ludovic coues <couesl@gmail.com>:
Oh, sorry. A bit of misunderstanding and miscommunication on my part.

The exemple I gave is just a quick way to reproduce my problem. The
real test use self.client, reverse, cast response.content to a string.
What I gave is a minimal exemple.

Also, I assumed you talked about comparing bit of html element, not
the raw content returned by the view. I'm quite uneasy to have the
test failing if a class is added or removed from the element. But yes,
your solution work for the current state of the application.

2016-07-31 14:46 GMT+02:00 Andreas Kuhne <andreas.kuhne@suitopia.com>:
> 2016-07-31 13:56 GMT+02:00 ludovic coues <couesl@gmail.com>:
>>
>> First, thanks for the suggestion.
>>
>> I just tried that, didn't work.
>> Here is the test file I used:
>>
>>
>>     from django.test import TestCase
>>
>>     class HTMLTestCase(TestCase):
>>
>>         def test_input_in_fieldset(self):
>>             fieldset = """
>>         <fieldset class="form-group">
>>             <input name="login">
>>             <input autofocus="" class="form-control" id="id_username"
>> maxlength="254" name="username" rows="3" type="text" required />
>>         </fieldset>
>>     """
>>             self.assertInHTML('<input name=login>', fieldset)
>>             self.assertInHTML('<input name="username">', fieldset)
>>
>>
>> First input is to have a working exemple, second is taken as is from
>> my view. Not closing the input in assertInHTML give an error `Couldn't
>> find '<input name="login"' in response`. I assume I would get the same
>> errors with assertContains(*args, html=True)
>>
>> I could copy/past the input directly in my test but if the maxlength
>> or class attribute change, the test will break. Taking the input
>> directly from the django form will test if the django form is rendered
>> in the view, not if the view is displaying a suitable form.
>>
>> 2016-07-31 13:22 GMT+02:00 Andreas Kuhne <andreas.kuhne@suitopia.com>:
>> > 2016-07-31 12:38 GMT+02:00 ludovic coues <couesl@gmail.com>:
>> >>
>> >> Hello,
>> >>
>> >> I am trying to test if a view is displaying a form with an input
>> >> element with name=username.
>> >>
>> >> Currently, I have tried a lot of variation around
>> >> `self.assertContains( response, "<input name=\"username\">",
>> >> html=True)` but none work.
>> >> I assume that doesn't work because the view have a field input with
>> >> name=username but also autofocus="", a class and a bunch of other
>> >> attribute.
>> >>
>> >> I could extract the form from the context and check the field username
>> >> from the form is displayed in the view but I'm not ok with that
>> >> solution. I'm testing if there is a input with name=username, not a
>> >> bunch of unrelated attribute.
>> >>
>> >> I could also use a LiveServerTestCase and selenium but that look like
>> >> a bit overkill for my need. lxml is another option but it would bring
>> >> more dependencies.
>> >>
>> >> A bit of help would be welcome :)
>> >>
>> >>
>> >>
>> >> --
>> >>
>> >> Cordialement, Coues Ludovic
>> >> +336 148 743 42
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "Django users" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> >> an
>> >> email to django-users+unsubscribe@googlegroups.com.
>> >> To post to this group, send email to django-users@googlegroups.com.
>> >> Visit this group at https://groups.google.com/group/django-users.
>> >> To view this discussion on the web visit
>> >>
>> >> https://groups.google.com/d/msgid/django-users/CAEuG%2BTah74hdZMv%2BwdZPPq5PLaJ%3DhxOFMNXuVLfFYSw2Uz4N0w%40mail.gmail.com.
>> >> For more options, visit https://groups.google.com/d/optout.
>> >
>> >
>> > Django usually creates the inputs the same way, so what I do in my tests
>> > is
>> > to first dump the content of the response body on the screen and then
>> > copy
>> > the input statement from there. What you probably need is '<input
>> > name="username"', because it doesn't matter for your test if the html
>> > tag is
>> > closed. So you should be fine with:
>> > self.assertContains(response, '<input name="username"')
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Django users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to django-users+unsubscribe@googlegroups.com.
>> > To post to this group, send email to django-users@googlegroups.com.
>> > Visit this group at https://groups.google.com/group/django-users.
>> > To view this discussion on the web visit
>> >
>> > https://groups.google.com/d/msgid/django-users/CALXYUbmmotLwzjZY6ZZnAqy21xqZN1%3DiE7ah3g5JxFgEw-POZg%40mail.gmail.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>>
>> Cordialement, Coues Ludovic
>> +336 148 743 42
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscribe@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAEuG%2BTZCWDkkrZuP2N168pth1hL-gc8FrVjMwZnb3xS%2BK1X%2Bxw%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> Hi,
>
> I think you have misunderstood me.
>
> First you need to check against the real response object, otherwise your
> test will only test if the item is present in your string, which is not what
> I meant. I meant that you should check what HTML django is generating to
> then get the correct information.
>
> In your case, I am now guessing that the output of django is the information
> you put into the fieldset variable?
>
> If so, you need to write
> self.assertContains(response,'<input autofocus="" class="form-control"
> id="id_username" maxlength="254" name="username"')
>
> The assertContains does not parse the html in any way, but uses a search for
> the text you entered. So if the text has 'autofocus="" class="form-control"
> id="id_username" maxlength="254"' before 'name="username"', then you need to
> add that as well, otherwise you won't find the text at all.
>
> Regards,
>
> Andréas
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALXYUbkp-oM3Y9dUYEcb8kbQT0kS95hDBqxVWMu8Cn-8iYQv3w%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTY%3DcbadWnm85-M2YEs2%3DwwH6gjLpnOGhLXjEpq-rGLGHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Hi again,

I understand your problem with a test failing if a class is added, however, there is no other way to check this (as far as I know). If you want to explicitly check for an input with the name "username", I would probably try using xml. That way you could use xpath to search quickly.

Regards,

Andréas

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALXYUbm5vcL%3Dz7qr7ZeS%2BMuNjH6LYscT9tr3Y3k0X3RLAAbEsQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Testing if a view have an html element with at least one attribute

Oh, sorry. A bit of misunderstanding and miscommunication on my part.

The exemple I gave is just a quick way to reproduce my problem. The
real test use self.client, reverse, cast response.content to a string.
What I gave is a minimal exemple.

Also, I assumed you talked about comparing bit of html element, not
the raw content returned by the view. I'm quite uneasy to have the
test failing if a class is added or removed from the element. But yes,
your solution work for the current state of the application.

2016-07-31 14:46 GMT+02:00 Andreas Kuhne <andreas.kuhne@suitopia.com>:
> 2016-07-31 13:56 GMT+02:00 ludovic coues <couesl@gmail.com>:
>>
>> First, thanks for the suggestion.
>>
>> I just tried that, didn't work.
>> Here is the test file I used:
>>
>>
>> from django.test import TestCase
>>
>> class HTMLTestCase(TestCase):
>>
>> def test_input_in_fieldset(self):
>> fieldset = """
>> <fieldset class="form-group">
>> <input name="login">
>> <input autofocus="" class="form-control" id="id_username"
>> maxlength="254" name="username" rows="3" type="text" required />
>> </fieldset>
>> """
>> self.assertInHTML('<input name=login>', fieldset)
>> self.assertInHTML('<input name="username">', fieldset)
>>
>>
>> First input is to have a working exemple, second is taken as is from
>> my view. Not closing the input in assertInHTML give an error `Couldn't
>> find '<input name="login"' in response`. I assume I would get the same
>> errors with assertContains(*args, html=True)
>>
>> I could copy/past the input directly in my test but if the maxlength
>> or class attribute change, the test will break. Taking the input
>> directly from the django form will test if the django form is rendered
>> in the view, not if the view is displaying a suitable form.
>>
>> 2016-07-31 13:22 GMT+02:00 Andreas Kuhne <andreas.kuhne@suitopia.com>:
>> > 2016-07-31 12:38 GMT+02:00 ludovic coues <couesl@gmail.com>:
>> >>
>> >> Hello,
>> >>
>> >> I am trying to test if a view is displaying a form with an input
>> >> element with name=username.
>> >>
>> >> Currently, I have tried a lot of variation around
>> >> `self.assertContains( response, "<input name=\"username\">",
>> >> html=True)` but none work.
>> >> I assume that doesn't work because the view have a field input with
>> >> name=username but also autofocus="", a class and a bunch of other
>> >> attribute.
>> >>
>> >> I could extract the form from the context and check the field username
>> >> from the form is displayed in the view but I'm not ok with that
>> >> solution. I'm testing if there is a input with name=username, not a
>> >> bunch of unrelated attribute.
>> >>
>> >> I could also use a LiveServerTestCase and selenium but that look like
>> >> a bit overkill for my need. lxml is another option but it would bring
>> >> more dependencies.
>> >>
>> >> A bit of help would be welcome :)
>> >>
>> >>
>> >>
>> >> --
>> >>
>> >> Cordialement, Coues Ludovic
>> >> +336 148 743 42
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "Django users" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> >> an
>> >> email to django-users+unsubscribe@googlegroups.com.
>> >> To post to this group, send email to django-users@googlegroups.com.
>> >> Visit this group at https://groups.google.com/group/django-users.
>> >> To view this discussion on the web visit
>> >>
>> >> https://groups.google.com/d/msgid/django-users/CAEuG%2BTah74hdZMv%2BwdZPPq5PLaJ%3DhxOFMNXuVLfFYSw2Uz4N0w%40mail.gmail.com.
>> >> For more options, visit https://groups.google.com/d/optout.
>> >
>> >
>> > Django usually creates the inputs the same way, so what I do in my tests
>> > is
>> > to first dump the content of the response body on the screen and then
>> > copy
>> > the input statement from there. What you probably need is '<input
>> > name="username"', because it doesn't matter for your test if the html
>> > tag is
>> > closed. So you should be fine with:
>> > self.assertContains(response, '<input name="username"')
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Django users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to django-users+unsubscribe@googlegroups.com.
>> > To post to this group, send email to django-users@googlegroups.com.
>> > Visit this group at https://groups.google.com/group/django-users.
>> > To view this discussion on the web visit
>> >
>> > https://groups.google.com/d/msgid/django-users/CALXYUbmmotLwzjZY6ZZnAqy21xqZN1%3DiE7ah3g5JxFgEw-POZg%40mail.gmail.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>>
>> Cordialement, Coues Ludovic
>> +336 148 743 42
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscribe@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAEuG%2BTZCWDkkrZuP2N168pth1hL-gc8FrVjMwZnb3xS%2BK1X%2Bxw%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> Hi,
>
> I think you have misunderstood me.
>
> First you need to check against the real response object, otherwise your
> test will only test if the item is present in your string, which is not what
> I meant. I meant that you should check what HTML django is generating to
> then get the correct information.
>
> In your case, I am now guessing that the output of django is the information
> you put into the fieldset variable?
>
> If so, you need to write
> self.assertContains(response,'<input autofocus="" class="form-control"
> id="id_username" maxlength="254" name="username"')
>
> The assertContains does not parse the html in any way, but uses a search for
> the text you entered. So if the text has 'autofocus="" class="form-control"
> id="id_username" maxlength="254"' before 'name="username"', then you need to
> add that as well, otherwise you won't find the text at all.
>
> Regards,
>
> Andréas
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALXYUbkp-oM3Y9dUYEcb8kbQT0kS95hDBqxVWMu8Cn-8iYQv3w%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTY%3DcbadWnm85-M2YEs2%3DwwH6gjLpnOGhLXjEpq-rGLGHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Testing if a view have an html element with at least one attribute

2016-07-31 13:56 GMT+02:00 ludovic coues <couesl@gmail.com>:
First, thanks for the suggestion.

I just tried that, didn't work.
Here is the test file I used:


    from django.test import TestCase

    class HTMLTestCase(TestCase):

        def test_input_in_fieldset(self):
            fieldset = """
        <fieldset class="form-group">
            <input name="login">
            <input autofocus="" class="form-control" id="id_username"
maxlength="254" name="username" rows="3" type="text" required />
        </fieldset>
    """
            self.assertInHTML('<input name=login>', fieldset)
            self.assertInHTML('<input name="username">', fieldset)


First input is to have a working exemple, second is taken as is from
my view. Not closing the input in assertInHTML give an error `Couldn't
find '<input name="login"' in response`. I assume I would get the same
errors with assertContains(*args, html=True)

I could copy/past the input directly in my test but if the maxlength
or class attribute change, the test will break. Taking the input
directly from the django form will test if the django form is rendered
in the view, not if the view is displaying a suitable form.

2016-07-31 13:22 GMT+02:00 Andreas Kuhne <andreas.kuhne@suitopia.com>:
> 2016-07-31 12:38 GMT+02:00 ludovic coues <couesl@gmail.com>:
>>
>> Hello,
>>
>> I am trying to test if a view is displaying a form with an input
>> element with name=username.
>>
>> Currently, I have tried a lot of variation around
>> `self.assertContains( response, "<input name=\"username\">",
>> html=True)` but none work.
>> I assume that doesn't work because the view have a field input with
>> name=username but also autofocus="", a class and a bunch of other
>> attribute.
>>
>> I could extract the form from the context and check the field username
>> from the form is displayed in the view but I'm not ok with that
>> solution. I'm testing if there is a input with name=username, not a
>> bunch of unrelated attribute.
>>
>> I could also use a LiveServerTestCase and selenium but that look like
>> a bit overkill for my need. lxml is another option but it would bring
>> more dependencies.
>>
>> A bit of help would be welcome :)
>>
>>
>>
>> --
>>
>> Cordialement, Coues Ludovic
>> +336 148 743 42
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscribe@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAEuG%2BTah74hdZMv%2BwdZPPq5PLaJ%3DhxOFMNXuVLfFYSw2Uz4N0w%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> Django usually creates the inputs the same way, so what I do in my tests is
> to first dump the content of the response body on the screen and then copy
> the input statement from there. What you probably need is '<input
> name="username"', because it doesn't matter for your test if the html tag is
> closed. So you should be fine with:
> self.assertContains(response, '<input name="username"')
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALXYUbmmotLwzjZY6ZZnAqy21xqZN1%3DiE7ah3g5JxFgEw-POZg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTZCWDkkrZuP2N168pth1hL-gc8FrVjMwZnb3xS%2BK1X%2Bxw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Hi,

I think you have misunderstood me. 

First you need to check against the real response object, otherwise your test will only test if the item is present in your string, which is not what I meant. I meant that you should check what HTML django is generating to then get the correct information.

In your case, I am now guessing that the output of django is the information you put into the fieldset variable?

If so, you need to write
self.assertContains(response,'<input autofocus="" class="form-control" id="id_username" maxlength="254" name="username"')

The assertContains does not parse the html in any way, but uses a search for the text you entered. So if the text has 'autofocus="" class="form-control" id="id_username" maxlength="254"' before 'name="username"', then you need to add that as well, otherwise you won't find the text at all.

Regards,

Andréas


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALXYUbkp-oM3Y9dUYEcb8kbQT0kS95hDBqxVWMu8Cn-8iYQv3w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Testing if a view have an html element with at least one attribute

First, thanks for the suggestion.

I just tried that, didn't work.
Here is the test file I used:


from django.test import TestCase

class HTMLTestCase(TestCase):

def test_input_in_fieldset(self):
fieldset = """
<fieldset class="form-group">
<input name="login">
<input autofocus="" class="form-control" id="id_username"
maxlength="254" name="username" rows="3" type="text" required />
</fieldset>
"""
self.assertInHTML('<input name=login>', fieldset)
self.assertInHTML('<input name="username">', fieldset)


First input is to have a working exemple, second is taken as is from
my view. Not closing the input in assertInHTML give an error `Couldn't
find '<input name="login"' in response`. I assume I would get the same
errors with assertContains(*args, html=True)

I could copy/past the input directly in my test but if the maxlength
or class attribute change, the test will break. Taking the input
directly from the django form will test if the django form is rendered
in the view, not if the view is displaying a suitable form.

2016-07-31 13:22 GMT+02:00 Andreas Kuhne <andreas.kuhne@suitopia.com>:
> 2016-07-31 12:38 GMT+02:00 ludovic coues <couesl@gmail.com>:
>>
>> Hello,
>>
>> I am trying to test if a view is displaying a form with an input
>> element with name=username.
>>
>> Currently, I have tried a lot of variation around
>> `self.assertContains( response, "<input name=\"username\">",
>> html=True)` but none work.
>> I assume that doesn't work because the view have a field input with
>> name=username but also autofocus="", a class and a bunch of other
>> attribute.
>>
>> I could extract the form from the context and check the field username
>> from the form is displayed in the view but I'm not ok with that
>> solution. I'm testing if there is a input with name=username, not a
>> bunch of unrelated attribute.
>>
>> I could also use a LiveServerTestCase and selenium but that look like
>> a bit overkill for my need. lxml is another option but it would bring
>> more dependencies.
>>
>> A bit of help would be welcome :)
>>
>>
>>
>> --
>>
>> Cordialement, Coues Ludovic
>> +336 148 743 42
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscribe@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAEuG%2BTah74hdZMv%2BwdZPPq5PLaJ%3DhxOFMNXuVLfFYSw2Uz4N0w%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> Django usually creates the inputs the same way, so what I do in my tests is
> to first dump the content of the response body on the screen and then copy
> the input statement from there. What you probably need is '<input
> name="username"', because it doesn't matter for your test if the html tag is
> closed. So you should be fine with:
> self.assertContains(response, '<input name="username"')
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALXYUbmmotLwzjZY6ZZnAqy21xqZN1%3DiE7ah3g5JxFgEw-POZg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTZCWDkkrZuP2N168pth1hL-gc8FrVjMwZnb3xS%2BK1X%2Bxw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

jasig cas integration

Hi all,
Is it possible to integrate django-cas client with a Jasig cas server or not
If it is not what cas server should i use?


I have to explain that a 403 forbidden error prevent authentication ending successfully.
something like this not answered question:

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/240a1d97-3200-49ae-be35-64ec6862ce46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Testing if a view have an html element with at least one attribute

2016-07-31 12:38 GMT+02:00 ludovic coues <couesl@gmail.com>:
Hello,

I am trying to test if a view is displaying a form with an input
element with name=username.

Currently, I have tried a lot of variation around
`self.assertContains( response, "<input name=\"username\">",
html=True)` but none work.
I assume that doesn't work because the view have a field input with
name=username but also autofocus="", a class and a bunch of other
attribute.

I could extract the form from the context and check the field username
from the form is displayed in the view but I'm not ok with that
solution. I'm testing if there is a input with name=username, not a
bunch of unrelated attribute.

I could also use a LiveServerTestCase and selenium but that look like
a bit overkill for my need. lxml is another option but it would bring
more dependencies.

A bit of help would be welcome :)



--

Cordialement, Coues Ludovic
+336 148 743 42

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTah74hdZMv%2BwdZPPq5PLaJ%3DhxOFMNXuVLfFYSw2Uz4N0w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Django usually creates the inputs the same way, so what I do in my tests is to first dump the content of the response body on the screen and then copy the input statement from there. What you probably need is '<input name="username"', because it doesn't matter for your test if the html tag is closed. So you should be fine with:
self.assertContains(response, '<input name="username"')

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALXYUbmmotLwzjZY6ZZnAqy21xqZN1%3DiE7ah3g5JxFgEw-POZg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Testing if a view have an html element with at least one attribute

Hello,

I am trying to test if a view is displaying a form with an input
element with name=username.

Currently, I have tried a lot of variation around
`self.assertContains( response, "<input name=\"username\">",
html=True)` but none work.
I assume that doesn't work because the view have a field input with
name=username but also autofocus="", a class and a bunch of other
attribute.

I could extract the form from the context and check the field username
from the form is displayed in the view but I'm not ok with that
solution. I'm testing if there is a input with name=username, not a
bunch of unrelated attribute.

I could also use a LiveServerTestCase and selenium but that look like
a bit overkill for my need. lxml is another option but it would bring
more dependencies.

A bit of help would be welcome :)



--

Cordialement, Coues Ludovic
+336 148 743 42

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTah74hdZMv%2BwdZPPq5PLaJ%3DhxOFMNXuVLfFYSw2Uz4N0w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Query annotation with date difference

Hi Yoann,

I am not sure exactly but believes you are on the right way.
Try improve your expression with ExpressionWrapper, as said here.
Probably the problem is that you use values of different types in your expression.

Regards

On Sat, Jul 30, 2016 at 11:35 PM, Yoann Duriaud <yoann.duriaud@gmail.com> wrote:
Hello,
I would like to annotate a query with the following expression: ([Due Date] - [Now])/[Interval]. [Due Date] and [Interval] are fields from the database, while [Now] should be "equal" to timezone.now().

So this would look like:
.annotate(ratio=(F('due_date')-timezone.now())/F('Interval'))

but this does not work. Does someone know how the expression should be written (if it is indeed feasible with Django ORM)?

Thanks for your help!

Yoann

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/03dedd39-142f-468a-b6fd-b7ec551862e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK52boX7irnk5X8GjUACuHCTDjzHpjHvpmP0O_fbUfhJZDAP6w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Saturday, July 30, 2016

Query annotation with date difference

Hello,
I would like to annotate a query with the following expression: ([Due Date] - [Now])/[Interval]. [Due Date] and [Interval] are fields from the database, while [Now] should be "equal" to timezone.now().

So this would look like:
.annotate(ratio=(F('due_date')-timezone.now())/F('Interval'))

but this does not work. Does someone know how the expression should be written (if it is indeed feasible with Django ORM)?

Thanks for your help!

Yoann

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/03dedd39-142f-468a-b6fd-b7ec551862e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Friday, July 29, 2016

Re: django 1.9, migrations SUCK

Excellent, thanks

This method i use from django 1.4, never have problem.


2016-07-29 11:36 GMT-05:00 ludovic coues <couesl@gmail.com>:
In /home/ariatel_web/dashboard.ariatel.com.co/apps/did/forms.py, replacing
    country = forms.ChoiceField(choices=[ (d.country_name,
d.country_name) for d in DidCountry.objects.filter(is_active=True) ]

with
    country = forms.ChoiceField(choices=lambda: [ (d.country_name,
d.country_name) for d in DidCountry.objects.filter(is_active=True) ]

should do the trick. It will make the choices arguments a callable
which will be evaluated when the form is used for the first time, not
when the module is imported.

2016-07-29 17:01 GMT+02:00 Jorge Cadena <jorge.cadena@gmail.com>:
>
> Traceback (most recent call last):
>   File "manage.py", line 10, in <module>
>     execute_from_command_line(sys.argv)
>   File
> "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
> line 353, in execute_from_command_line
>     utility.execute()
>   File
> "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py",
> line 345, in execute
>     self.fetch_command(subcommand).run_from_argv(self.argv)
>   File
> "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
> line 348, in run_from_argv
>     self.execute(*args, **cmd_options)
>   File
> "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
> line 398, in execute
>     self.check()
>   File
> "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py",
> line 426, in check
>     include_deployment_checks=include_deployment_checks,
>   File
> "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py",
> line 75, in run_checks
>     new_errors = check(app_configs=app_configs)
>   File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py",
> line 13, in check_url_config
>     return check_resolver(resolver)
>   File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py",
> line 23, in check_resolver
>     for pattern in resolver.url_patterns:
>   File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py",
> line 33, in __get__
>     res = instance.__dict__[self.name] = self.func(instance)
>   File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py",
> line 417, in url_patterns
>     patterns = getattr(self.urlconf_module, "urlpatterns",
> self.urlconf_module)
>   File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py",
> line 33, in __get__
>     res = instance.__dict__[self.name] = self.func(instance)
>   File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py",
> line 410, in urlconf_module
>     return import_module(self.urlconf_name)
>   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
>     __import__(name)
>   File
> "/home/ariatel_web/dashboard.ariatel.com.co/dashaboar_ariatel/urls.py", line
> 20, in <module>
>     from apps.did.views import CountryViewSet, AreasViewSet
>   File "/home/ariatel_web/dashboard.ariatel.com.co/apps/did/views.py", line
> 15, in <module>
>     from .forms import BuySearchForm
>   File "/home/ariatel_web/dashboard.ariatel.com.co/apps/did/forms.py", line
> 11, in <module>
>     class BuySearchForm(forms.Form):
>   File "/home/ariatel_web/dashboard.ariatel.com.co/apps/did/forms.py", line
> 12, in BuySearchForm
>     country = forms.ChoiceField(choices=[ (d.country_name, d.country_name)
> for d in DidCountry.objects.filter(is_active=True) ], required=False)
>   File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py",
> line 258, in __iter__
>     self._fetch_all()
>   File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py",
> line 1074, in _fetch_all
>     self._result_cache = list(self.iterator())
>   File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py",
> line 52, in __iter__
>     results = compiler.execute_sql()
>   File
> "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py",
> line 848, in execute_sql
>     cursor.execute(sql, params)
>   File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py",
> line 79, in execute
>     return super(CursorDebugWrapper, self).execute(sql, params)
>   File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py",
> line 64, in execute
>     return self.cursor.execute(sql, params)
>   File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 95,
> in __exit__
>     six.reraise(dj_exc_type, dj_exc_value, traceback)
>   File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py",
> line 64, in execute
>     return self.cursor.execute(sql, params)
>   File
> "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py",
> line 323, in execute
>     return Database.Cursor.execute(self, query, params)
> django.db.utils.OperationalError: no such table: did_didcountry
>
>
> El viernes, 29 de julio de 2016, 9:44:05 (UTC-5), Jorge Cadena escribió:
>>
>> same error, in mariaDB, postgresql, rigth now in sqlite3
>>
>>
>> El viernes, 29 de julio de 2016, 9:07:33 (UTC-5), Jorge Cadena escribió:
>>>
>>> Hi,
>>>
>>> I am dev in django at last 4 years, i missed ./manage.py syncdb,
>>>
>>> Delete all tables from databases (MariaDB, PostgreSQL) command line from
>>> DB, and run python manage.py migrate always same error
>>>
>>> python manage.py migrate
>>> django.db.utils.ProgrammingError: (1146, "Table
>>> 'dashaboard_web.did_didcountry' doesn't exist")
>>>
>>> python manage.py migrate did
>>> django.db.utils.ProgrammingError: (1146, "Table
>>> 'dashaboard_web.did_didcountry' doesn't exist")
>>>
>>> python manage.py makemigrations
>>> django.db.utils.ProgrammingError: (1146, "Table
>>> 'dashaboard_web.did_didcountry' doesn't exist")
>>>
>>> python manage.py sqlmigrate did 0001
>>> django.db.utils.ProgrammingError: (1146, "Table
>>> 'dashaboard_web.did_didcountry' doesn't exist")
>>>
>>> python manage.py migrate --run-syncdb
>>> django.db.utils.ProgrammingError: (1146, "Table
>>> 'dashaboard_web.did_didcountry' doesn't exist")
>>>
>>>
>>> if the tables doesn't exist, why create table new ???
>>> as, create new tables run command python manage.py migrate ??
>>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/36188b9a-c477-4b9e-aa75-1c7f915e3cac%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/qqvMiE35EGg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTY4Wo_L3dd4D%2BGokUyyBeB8_ys2jK49V0iqnVLQYByV0Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Un hombre de carácter podrá ser derrotado pero jamás destruido.

ERNEST HEMINGWAY.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAC1QQjjqrUQSmg7cn9gRs1V8nyd4vac4p65ny7rDeSP_s%3DyGVg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.