Re: Call for Testing: Connection Pooling PR for Django Oracle

2024-05-09 Thread Benjamini Athanas
thanks

On Mon, 6 May 2024 at 22:41, suraj shaw  wrote:

> Dear Django Users,
>
>
> I hope this email finds you well.
>
>
> We're reaching out to the Django community today with an exciting
> opportunity to test a significant enhancement for the Oracle database
> backend: connection pooling functionality.
>
>
> A pull request has been submitted that introduces connection pooling to
> Django's Oracle backend. This enhancement promises to bring notable
> improvements in performance and scalability, particularly for applications
> handling heavy database traffic.
>
> We're inviting members of the Django community to participate in testing
> this PR.
>
>
> Your feedback and testing are invaluable in ensuring the reliability,
> efficiency, and compatibility of this feature across various Django
> projects and environments. By participating, you not only contribute to the
> enhancement of Django but also ensure that this crucial functionality meets
> the diverse needs of our community.
>
>
> *How You Can Help:*
>
>1. *Testing*: Deploy the PR in your development or testing environment
>and run your Django applications with Oracle backend. Observe its behavior,
>performance, and compatibility with your existing codebase.
>2. *Bug Reporting*: If you encounter any issues, whether they're
>related to functionality, performance, or compatibility, please report them
>promptly. Detailed bug reports with steps to reproduce are immensely
>helpful for the developers.
>3. *Feedback*: Share your thoughts, suggestions, and experiences with
>the community. Your feedback will aid in refining and improving the feature
>before it's merged into the main Django codebase.
>
>
> Testing Environment - Use python-oracledb (thin mode)
>
> Link - https://python-oracledb.readthedocs.io/en/latest/index.html
>
>
> *PR Link:* https://github.com/django/django/pull/17834
>
>
> Your contributions to this testing effort will play a crucial role in
> expediting the merging process. We highly appreciate your time and effort
> in helping make Django even better.
>
>
>
> Thank you for your support and dedication to the Django community.
>
>
> Best regards,
>
> Suraj Kumar Shaw
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAAUoqBHSZros2LGk9r2BeLYgm54LtCdTN_QURkGcTU-G9CFxwQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAAUoqBHSZros2LGk9r2BeLYgm54LtCdTN_QURkGcTU-G9CFxwQ%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPRT2e5FDk6MJf8X%3D_iFOUkcyPBP3Sc-%3DH4KpSRNtbDo-3%3DY%2Bg%40mail.gmail.com.


Call for Testing: Connection Pooling PR for Django Oracle

2024-05-06 Thread suraj shaw
Dear Django Users,


I hope this email finds you well.


We're reaching out to the Django community today with an exciting
opportunity to test a significant enhancement for the Oracle database
backend: connection pooling functionality.


A pull request has been submitted that introduces connection pooling to
Django's Oracle backend. This enhancement promises to bring notable
improvements in performance and scalability, particularly for applications
handling heavy database traffic.

We're inviting members of the Django community to participate in testing
this PR.


Your feedback and testing are invaluable in ensuring the reliability,
efficiency, and compatibility of this feature across various Django
projects and environments. By participating, you not only contribute to the
enhancement of Django but also ensure that this crucial functionality meets
the diverse needs of our community.


*How You Can Help:*

   1. *Testing*: Deploy the PR in your development or testing environment
   and run your Django applications with Oracle backend. Observe its behavior,
   performance, and compatibility with your existing codebase.
   2. *Bug Reporting*: If you encounter any issues, whether they're related
   to functionality, performance, or compatibility, please report them
   promptly. Detailed bug reports with steps to reproduce are immensely
   helpful for the developers.
   3. *Feedback*: Share your thoughts, suggestions, and experiences with
   the community. Your feedback will aid in refining and improving the feature
   before it's merged into the main Django codebase.


Testing Environment - Use python-oracledb (thin mode)

Link - https://python-oracledb.readthedocs.io/en/latest/index.html


*PR Link:* https://github.com/django/django/pull/17834


Your contributions to this testing effort will play a crucial role in
expediting the merging process. We highly appreciate your time and effort
in helping make Django even better.



Thank you for your support and dedication to the Django community.


Best regards,

Suraj Kumar Shaw

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAUoqBHSZros2LGk9r2BeLYgm54LtCdTN_QURkGcTU-G9CFxwQ%40mail.gmail.com.


Reference data while testing - interesting

2023-10-05 Thread Mike Dewhirst
I have an interesting testing problem which requires someone smarter 
than me.


I want to prove correctness of multiple outcomes from multiple 
regulatory computations based on, among other things, international 
lists of assessed chemicals and their hazards.


Hazards include both human health and environmental - land, air and 
aquatic as well as the food chain from microbes on up.


Once a qualified chemistry expert has agreed that our (Django) software 
has correctly categorised a chemical according to local regulations and 
those lists, we need to lock in that behaviour which, as already 
indicated, is based on reference data.


To do so, we wrote a (Django) management command to auto-generate a set 
of tests for that chemical which proves all those outcomes are as 
expected whenever we run our tests. That protects against unintended 
side effects as we develop but not against changes in the reference data.


The interesting problem is that things change. Every day, new 
discoveries are made which indicate individual chemicals or chemical 
groups are actually more hazardous than previously thought.


Reference data fixtures are infeasible (dozens of tables, hundreds of 
thousands of records) because they are enormous and therefore 
unmanageable for frequent testing. Even if we did use fixtures, if not 
continuously refreshed, tests just keep passing.


We need tests to fail when change happens so that our software can 
notify users that they have to rethink what they might be doing with a 
particular chemical or group of chemicals in order to avoid further 
damaging the planet or its inhabitants.


The base reference data is updated when things change. These are 
necessarily manual processes based on subscribing to emails to receive 
notifications from local and international regulators about upcoming 
changes, calls for public input and eventually publishing of actual 
adjustments and deadline dates. That is a continuous process.


I put this scenario to ChatGPT and prompted it down the db_alias path[1] 
of keeping the reference data portion of the database available 
read-only during testing so that tests are directly exposed to the 
source of truth. It came up with a complicated/complex solution which, 
due to underconfidence, I have not tried.


I cannot believe this is the first time a reference data source has been 
needed during Django testing so I'm asking here if anyone has a solution.


Many thanks

Cheers

Mike


- - - - -
[1] Given the specific requirements of your testing scenario, where you 
need to access read-only reference data from a production database while 
emptying the regular testing database between tests, you can achieve 
this by using Django's |db_alias| feature. You can configure a separate 
database alias for read-only access to the reference data.


Here's how you can set it up:

1.

   *Configure a Separate Database for Reference Data*:

   In your Django settings (|settings.py|), define a new database
   configuration for the reference data. You can specify this in the
   |DATABASES| setting using a different alias:

#

|DATABASES = { 'default': { # Your regular database configuration for 
testing 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'test_db', # 
Other settings... }, 'reference_db': { # Configuration for the reference 
data database (read-only) 'ENGINE': 'django.db.backends.postgresql', 
'NAME': 'reference_db', # Other settings... }, } |


Replace |'reference_db'| with an appropriate alias for your reference data.

#

*Create a Router for Reference Data*:

Next, you can create a database router to determine which database to 
use based on the model being accessed. In your Django project, create a 
Python module (e.g., |routers.py|) and define a database router class:


#

|class ReferenceDataRouter: def db_for_read(self, model, **hints): # Use 
the 'reference_db' alias for models that access reference data if 
model._meta.app_label == 'your_app_label': return 'reference_db' return 
None def db_for_write(self, model, **hints): # Prevent writes to the 
'reference_db' database if model._meta.app_label == 'your_app_label': 
return None return 'default' def allow_migrate(self, db, app_label, 
model_name=None, **hints): # Allow migrations only on the default 
database if db == 'default': return True return False |


Replace |'your_app_label'| with the actual app label containing your 
reference data models.


#

*Add the Router to Your Settings*:

In your Django settings (|settings.py|), add the reference data router 
to the |DATABASE_ROUTERS| setting:


#

|DATABASE_ROUTERS = ['your_project.routers.ReferenceDataRouter'] |

#

*Write Tests That Access Reference Data*:

In your test cases, you can access the reference data by using the 
|using| method to specify the database alias:


4.

   |from django.test import TestCase from your_app.models import
   YourReferenceModel class YourTestCase(TestCase): def
   test_access_reference_data(self): reference_objects

Re: Reference data while testing

2023-10-03 Thread Mike Dewhirst
Thank you but unfortunately, none of the suggestions are appropriate. 
Here is more information.


We have a complex system where - in the opinion of a chemical expert - 
it is possible to state that a particular chemical risk profile has been 
correctly calculated by the software.


In addition to molecular properties, base and comparison information 
used bythe software to perform those risk calculations - at multiple 
end-points - is imported from many international regulatory authorities 
and stored in (Django/Postgres) reference tables. There are hundreds of 
thousands of records all of which are (somewhat) regularly updated when 
those authorities notify changes.


Once an expert confirms a risk profile for a particular chemical we use 
a Django management command to generate a new Django test in our test 
harness. The objective is to run that/those tests in our regular testing 
regime to prove the software - and reference data - is still OK.


If the reference data or the software changes, we want to discover any 
discrepancies from the expert opinion.


Automating creation of those tests (underpinning the expert opinion) is 
important because it is the only way I can see to stay sane. I am not a 
chemical expert.


I was hoping someone could suggest a way - perhaps using dbalias - to 
allow read-only use of the reference portion of the database. Another 
thought I had was to load a dump of the reference data prior to starting 
the tests but I believe Django would simply wipe that after the first test.


Factory boy is really good but cannot provide accurate reference 
information. I can see SQLAlchemy might be a solution but I'd prefer to 
stay within Django/Postgres.


Still looking ...

Thanks

On 4/10/2023 5:26 am, Alessandro Madruga Correia wrote:



On Mon, Oct 2, 2023 at 11:30 PM Mike Dewhirst  
wrote:



This is probably in the docs so please drop me a link if you can.

My project has fifteen or more tables of reference data which
determine how the software behaves and therefore is critical to
unit testing.

Fixtures are unworkable and I  need to respond to the actual
reference data.

How can i do real lookups (read-only) during tests?


You can use Factory Boy https://factoryboy.readthedocs.io/en/stable/


--
  ,= ,-_-. =. [] Alessandro Madruga Correia
 ((_/)o o(\_))  [http://counter.li.org]       Debian User# 342751
   `-'(. .)`-'    "O fanatismo é a única forma de força de vontade
       \_/        acessível aos fracos." (Friedrich Nietzsche)

--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOofabfi%3DErk535OgDo5nPU%3DwM1pVp%3D93muppuGMt1c6M2vSZA%40mail.gmail.com 
<https://groups.google.com/d/msgid/django-users/CAOofabfi%3DErk535OgDo5nPU%3DwM1pVp%3D93muppuGMt1c6M2vSZA%40mail.gmail.com?utm_medium=email_source=footer>.



--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Your
email software can handle signing.

--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d50a02f1-bcf9-7ac7-0488-95cc1d54eccd%40dewhirst.com.au.


OpenPGP_signature
Description: OpenPGP digital signature


Re: Reference data while testing

2023-10-03 Thread Qayyam Hussain
Sure I'll what how much you pay me?

On Tue, Oct 3, 2023, 7:31 AM Mike Dewhirst  wrote:

>
> This is probably in the docs so please drop me a link if you can.
>
> My project has fifteen or more tables of reference data which determine
> how the software behaves and therefore is critical to unit testing.
>
> Fixtures are unworkable and I  need to respond to the actual reference
> data.
>
> How can i do real lookups (read-only) during tests?
>
> Thanks
>
> Mike
>
>
>
>
> --
> (Unsigned mail from my phone)
>
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/651b7cc1.170a0220.54b8d.3ebcSMTPIN_ADDED_MISSING%40gmr-mx.google.com
> <https://groups.google.com/d/msgid/django-users/651b7cc1.170a0220.54b8d.3ebcSMTPIN_ADDED_MISSING%40gmr-mx.google.com?utm_medium=email_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOx6qv-kapk%2Bxm8%3DBzpF32M1JveZ01Xk4SaBts%2BxLMjEg5_k8g%40mail.gmail.com.


Re: Reference data while testing

2023-10-03 Thread Alessandro Madruga Correia
On Mon, Oct 2, 2023 at 11:30 PM Mike Dewhirst  wrote:

>
> This is probably in the docs so please drop me a link if you can.
>
> My project has fifteen or more tables of reference data which determine
> how the software behaves and therefore is critical to unit testing.
>
> Fixtures are unworkable and I  need to respond to the actual reference
> data.
>
> How can i do real lookups (read-only) during tests?
>

You can use Factory Boy https://factoryboy.readthedocs.io/en/stable/


-- 
  ,= ,-_-. =.   [] Alessandro Madruga Correia
 ((_/)o o(\_))  [http://counter.li.org]   Debian User# 342751
   `-'(. .)`-'"O fanatismo é a única forma de força de vontade
   \_/acessível aos fracos." (Friedrich Nietzsche)

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOofabfi%3DErk535OgDo5nPU%3DwM1pVp%3D93muppuGMt1c6M2vSZA%40mail.gmail.com.


Re: Reference data while testing

2023-10-03 Thread herve bineli
Hi Mike,

I will suggest you use a database framework like SQLAlchemy to access your
tables' data with read-only queries.
Then you use the data queried to set your test cases using a testing
library like Pytest.

Do let know if you have other concerns with this approach.

Best Regards,
BINELI Arsene


On Tue, Oct 3, 2023 at 3:30 AM Mike Dewhirst  wrote:

>
> This is probably in the docs so please drop me a link if you can.
>
> My project has fifteen or more tables of reference data which determine
> how the software behaves and therefore is critical to unit testing.
>
> Fixtures are unworkable and I  need to respond to the actual reference
> data.
>
> How can i do real lookups (read-only) during tests?
>
> Thanks
>
> Mike
>
>
>
>
> --
> (Unsigned mail from my phone)
>
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/651b7cc1.170a0220.54b8d.3ebcSMTPIN_ADDED_MISSING%40gmr-mx.google.com
> <https://groups.google.com/d/msgid/django-users/651b7cc1.170a0220.54b8d.3ebcSMTPIN_ADDED_MISSING%40gmr-mx.google.com?utm_medium=email_source=footer>
> .
>


-- 
*BINELI MANGA Hervé Arsène*
Ingénieur Informaticien - ENSPY
binelima...@gmail.com
(+237) 691388922 / 699946323

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJm63Om2A-EwJdm7ck60rOOK%2By7kQCoSsaLb-mSmwzWAvM%2B92w%40mail.gmail.com.


Re: Reference data while testing

2023-10-02 Thread Jun Say
Thank you for your email.
https://hahaha0505.netlify.app/
If  you have any questions, please share with me.
Thank you.

On Tue, Oct 3, 2023 at 10:30 AM Mike Dewhirst  wrote:

>
> This is probably in the docs so please drop me a link if you can.
>
> My project has fifteen or more tables of reference data which determine
> how the software behaves and therefore is critical to unit testing.
>
> Fixtures are unworkable and I  need to respond to the actual reference
> data.
>
> How can i do real lookups (read-only) during tests?
>
> Thanks
>
> Mike
>
>
>
>
> --
> (Unsigned mail from my phone)
>
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/651b7cc1.170a0220.54b8d.3ebcSMTPIN_ADDED_MISSING%40gmr-mx.google.com
> <https://groups.google.com/d/msgid/django-users/651b7cc1.170a0220.54b8d.3ebcSMTPIN_ADDED_MISSING%40gmr-mx.google.com?utm_medium=email_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJyUeCSv4iEGViXc%2B2%2BGP4TyA7RaBzV1P%2B0A731HLJDPTB8--w%40mail.gmail.com.


Reference data while testing

2023-10-02 Thread Mike Dewhirst
This is probably in the docs so please drop me a link if you can.My project has 
fifteen or more tables of reference data which determine how the software 
behaves and therefore is critical to unit testing.Fixtures are unworkable and I 
 need to respond to the actual reference data.How can i do real lookups 
(read-only) during tests?ThanksMike--(Unsigned mail from my phone)

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/651b7cc1.170a0220.54b8d.3ebcSMTPIN_ADDED_MISSING%40gmr-mx.google.com.


Re: testing newbie - help requested: app works, tests give errors

2023-05-10 Thread 'Bob Aalsma' via Django users
Hmm, when I remove the raise CommandError statement and replace it with 
self.stdout.write, everything works well.

This helps me to point further studies. Thx!
On Wednesday, May 10, 2023 at 2:33:18 PM UTC+2 Bob Aalsma wrote:

> Ah, yes, thanks.
>
> I hesitate to comment on "If I understood the error right." ;)
>
> Umm, my problem here is that I think I'm using the exact same *code* 
> "manually" without errors. 
> I think I'm also using the same *values* for the manual and test runs.
> So I don't understand the reason for the differences in output.
>
> On Wednesday, May 10, 2023 at 2:18:33 PM UTC+2 Vishesh Mangla wrote:
>
>> If I understood the error right.
>>
>> On Wed, May 10, 2023 at 5:47 PM Vishesh Mangla  
>> wrote:
>>
>>> Probably this would help: 
>>> https://stackoverflow.com/questions/8609192/what-is-the-difference-between-null-true-and-blank-true-in-django
>>>
>>> On Wed, May 10, 2023 at 5:45 PM 'Bob Aalsma' via Django users <
>>> django...@googlegroups.com> wrote:
>>>
 Sorry Vishesh, thanks for the quick answer but I have no idea what you 
 mean.

 On Wednesday, May 10, 2023 at 2:00:51 PM UTC+2 Vishesh Mangla wrote:

> False or True check for yourself.
>
> On Wed, 10 May, 2023, 17:29 Vishesh Mangla,  
> wrote:
>
>> It looks like you are passing a null but null=False is not set
>>
>> On Wed, 10 May, 2023, 17:27 'Bob Aalsma' via Django users, <
>> django...@googlegroups.com> wrote:
>>
>>> I'm trying to test a django-admin command and don't understand why 
>>> the tests give errors on the code while the code works as expected.
>>>
>>> I'm under the impression that the *raise CommandError* is ignored 
>>> by the test, but don't understand why this would be.
>>>
>>> Please help.
>>>
>>> Running the code shows:
>>>
>>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py 
>>> populate_source 0
>>>
>>> *CommandError: Alleen hele getallen > 0 toegestaan*
>>>
>>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py 
>>> populate_source 1
>>>
>>> *Teksten zijn gegenereerd voor tekstlengte 1*
>>>
>>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py 
>>> populate_source 1
>>>
>>> *CommandError: Teksten voor nummer 1 zijn al eerder gegenereerd*
>>>
>>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py 
>>> populate_source 7
>>>
>>> *CommandError: Opgegeven sleutel 7 niet gevonden*
>>>
>>> Running the tests shows
>>>
>>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py 
>>> test tests.test_sources_app_command_populate
>>>
>>> Found 3 test(s).
>>>
>>> Creating test database for alias 'default'...
>>>
>>> System check identified no issues (0 silenced).
>>>
>>> EEE
>>>
>>>
>>> ==
>>>
>>> ERROR: test_command_output_been_there 
>>> (tests.test_sources_app_command_populate.PopulateSourceTests.test_command_output_been_there)
>>>
>>> Test for failure: in_use = True.
>>>
>>>
>>> --
>>>
>>> Traceback (most recent call last):
>>>
>>>   File 
>>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
>>>  
>>> line 89, in _execute
>>>
>>> return self.cursor.execute(sql, params)
>>>
>>>
>>>
>>>   File 
>>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/sqlite3/base.py",
>>>  
>>> line 328, in execute
>>>
>>> return super().execute(query, params)
>>>
>>>^^
>>>
>>> sqlite3.IntegrityError: NOT NULL constraint failed: 
>>> domain_sources_app_characternumber.number_of_combinations
>>>
>>>
>>> The above exception was the direct cause of the following exception:
>>>
>>>
>>> Traceback (most recent call last):
>>>
>>>   File 
>>> "/Users/werker/Projects/domain_reader/tests/test_sources_app_command_populate.py",
>>>  
>>> line 30, in test_command_output_been_there
>>>
>>> thingy.save()
>>>
>>>   File 
>>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
>>>  
>>> line 814, in save
>>>
>>> self.save_base(
>>>
>>>   File 
>>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
>>>  
>>> line 877, in save_base
>>>
>>> updated = self._save_table(
>>>
>>>   ^
>>>
>>>   File 
>>> 

Re: testing newbie - help requested: app works, tests give errors

2023-05-10 Thread 'Bob Aalsma' via Django users
Ah, yes, thanks.

I hesitate to comment on "If I understood the error right." ;)

Umm, my problem here is that I think I'm using the exact same *code* 
"manually" without errors. 
I think I'm also using the same *values* for the manual and test runs.
So I don't understand the reason for the differences in output.

On Wednesday, May 10, 2023 at 2:18:33 PM UTC+2 Vishesh Mangla wrote:

> If I understood the error right.
>
> On Wed, May 10, 2023 at 5:47 PM Vishesh Mangla  
> wrote:
>
>> Probably this would help: 
>> https://stackoverflow.com/questions/8609192/what-is-the-difference-between-null-true-and-blank-true-in-django
>>
>> On Wed, May 10, 2023 at 5:45 PM 'Bob Aalsma' via Django users <
>> django...@googlegroups.com> wrote:
>>
>>> Sorry Vishesh, thanks for the quick answer but I have no idea what you 
>>> mean.
>>>
>>> On Wednesday, May 10, 2023 at 2:00:51 PM UTC+2 Vishesh Mangla wrote:
>>>
 False or True check for yourself.

 On Wed, 10 May, 2023, 17:29 Vishesh Mangla,  
 wrote:

> It looks like you are passing a null but null=False is not set
>
> On Wed, 10 May, 2023, 17:27 'Bob Aalsma' via Django users, <
> django...@googlegroups.com> wrote:
>
>> I'm trying to test a django-admin command and don't understand why 
>> the tests give errors on the code while the code works as expected.
>>
>> I'm under the impression that the *raise CommandError* is ignored by 
>> the test, but don't understand why this would be.
>>
>> Please help.
>>
>> Running the code shows:
>>
>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py 
>> populate_source 0
>>
>> *CommandError: Alleen hele getallen > 0 toegestaan*
>>
>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py 
>> populate_source 1
>>
>> *Teksten zijn gegenereerd voor tekstlengte 1*
>>
>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py 
>> populate_source 1
>>
>> *CommandError: Teksten voor nummer 1 zijn al eerder gegenereerd*
>>
>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py 
>> populate_source 7
>>
>> *CommandError: Opgegeven sleutel 7 niet gevonden*
>>
>> Running the tests shows
>>
>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py 
>> test tests.test_sources_app_command_populate
>>
>> Found 3 test(s).
>>
>> Creating test database for alias 'default'...
>>
>> System check identified no issues (0 silenced).
>>
>> EEE
>>
>> ==
>>
>> ERROR: test_command_output_been_there 
>> (tests.test_sources_app_command_populate.PopulateSourceTests.test_command_output_been_there)
>>
>> Test for failure: in_use = True.
>>
>> --
>>
>> Traceback (most recent call last):
>>
>>   File 
>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
>>  
>> line 89, in _execute
>>
>> return self.cursor.execute(sql, params)
>>
>>
>>
>>   File 
>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/sqlite3/base.py",
>>  
>> line 328, in execute
>>
>> return super().execute(query, params)
>>
>>^^
>>
>> sqlite3.IntegrityError: NOT NULL constraint failed: 
>> domain_sources_app_characternumber.number_of_combinations
>>
>>
>> The above exception was the direct cause of the following exception:
>>
>>
>> Traceback (most recent call last):
>>
>>   File 
>> "/Users/werker/Projects/domain_reader/tests/test_sources_app_command_populate.py",
>>  
>> line 30, in test_command_output_been_there
>>
>> thingy.save()
>>
>>   File 
>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
>>  
>> line 814, in save
>>
>> self.save_base(
>>
>>   File 
>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
>>  
>> line 877, in save_base
>>
>> updated = self._save_table(
>>
>>   ^
>>
>>   File 
>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
>>  
>> line 1020, in _save_table
>>
>> results = self._do_insert(
>>
>>   
>>
>>   File 
>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
>>  
>> line 1061, in _do_insert
>>
>> return 

Re: testing newbie - help requested: app works, tests give errors

2023-05-10 Thread Vishesh Mangla
If I understood the error right.

On Wed, May 10, 2023 at 5:47 PM Vishesh Mangla 
wrote:

> Probably this would help:
> https://stackoverflow.com/questions/8609192/what-is-the-difference-between-null-true-and-blank-true-in-django
>
> On Wed, May 10, 2023 at 5:45 PM 'Bob Aalsma' via Django users <
> django-users@googlegroups.com> wrote:
>
>> Sorry Vishesh, thanks for the quick answer but I have no idea what you
>> mean.
>>
>> On Wednesday, May 10, 2023 at 2:00:51 PM UTC+2 Vishesh Mangla wrote:
>>
>>> False or True check for yourself.
>>>
>>> On Wed, 10 May, 2023, 17:29 Vishesh Mangla, 
>>> wrote:
>>>
 It looks like you are passing a null but null=False is not set

 On Wed, 10 May, 2023, 17:27 'Bob Aalsma' via Django users, <
 django...@googlegroups.com> wrote:

> I'm trying to test a django-admin command and don't understand why the
> tests give errors on the code while the code works as expected.
>
> I'm under the impression that the *raise CommandError* is ignored by
> the test, but don't understand why this would be.
>
> Please help.
>
> Running the code shows:
>
> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py
> populate_source 0
>
> *CommandError: Alleen hele getallen > 0 toegestaan*
>
> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py
> populate_source 1
>
> *Teksten zijn gegenereerd voor tekstlengte 1*
>
> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py
> populate_source 1
>
> *CommandError: Teksten voor nummer 1 zijn al eerder gegenereerd*
>
> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py
> populate_source 7
>
> *CommandError: Opgegeven sleutel 7 niet gevonden*
>
> Running the tests shows
>
> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py
> test tests.test_sources_app_command_populate
>
> Found 3 test(s).
>
> Creating test database for alias 'default'...
>
> System check identified no issues (0 silenced).
>
> EEE
>
> ==
>
> ERROR: test_command_output_been_there
> (tests.test_sources_app_command_populate.PopulateSourceTests.test_command_output_been_there)
>
> Test for failure: in_use = True.
>
> --
>
> Traceback (most recent call last):
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
> line 89, in _execute
>
> return self.cursor.execute(sql, params)
>
>
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/sqlite3/base.py",
> line 328, in execute
>
> return super().execute(query, params)
>
>^^
>
> sqlite3.IntegrityError: NOT NULL constraint failed:
> domain_sources_app_characternumber.number_of_combinations
>
>
> The above exception was the direct cause of the following exception:
>
>
> Traceback (most recent call last):
>
>   File
> "/Users/werker/Projects/domain_reader/tests/test_sources_app_command_populate.py",
> line 30, in test_command_output_been_there
>
> thingy.save()
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
> line 814, in save
>
> self.save_base(
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
> line 877, in save_base
>
> updated = self._save_table(
>
>   ^
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
> line 1020, in _save_table
>
> results = self._do_insert(
>
>   
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
> line 1061, in _do_insert
>
> return manager._insert(
>
>
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/manager.py",
> line 87, in manager_method
>
> return getattr(self.get_queryset(), name)(*args, **kwargs)
>
>^^^
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/query.py",
> line 1805, in _insert
>
> return
> query.get_compiler(using=using).execute_sql(returning_fields)
>

Re: testing newbie - help requested: app works, tests give errors

2023-05-10 Thread Vishesh Mangla
Probably this would help:
https://stackoverflow.com/questions/8609192/what-is-the-difference-between-null-true-and-blank-true-in-django

On Wed, May 10, 2023 at 5:45 PM 'Bob Aalsma' via Django users <
django-users@googlegroups.com> wrote:

> Sorry Vishesh, thanks for the quick answer but I have no idea what you
> mean.
>
> On Wednesday, May 10, 2023 at 2:00:51 PM UTC+2 Vishesh Mangla wrote:
>
>> False or True check for yourself.
>>
>> On Wed, 10 May, 2023, 17:29 Vishesh Mangla,  wrote:
>>
>>> It looks like you are passing a null but null=False is not set
>>>
>>> On Wed, 10 May, 2023, 17:27 'Bob Aalsma' via Django users, <
>>> django...@googlegroups.com> wrote:
>>>
 I'm trying to test a django-admin command and don't understand why the
 tests give errors on the code while the code works as expected.

 I'm under the impression that the *raise CommandError* is ignored by
 the test, but don't understand why this would be.

 Please help.

 Running the code shows:

 (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py
 populate_source 0

 *CommandError: Alleen hele getallen > 0 toegestaan*

 (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py
 populate_source 1

 *Teksten zijn gegenereerd voor tekstlengte 1*

 (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py
 populate_source 1

 *CommandError: Teksten voor nummer 1 zijn al eerder gegenereerd*

 (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py
 populate_source 7

 *CommandError: Opgegeven sleutel 7 niet gevonden*

 Running the tests shows

 (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py test
 tests.test_sources_app_command_populate

 Found 3 test(s).

 Creating test database for alias 'default'...

 System check identified no issues (0 silenced).

 EEE

 ==

 ERROR: test_command_output_been_there
 (tests.test_sources_app_command_populate.PopulateSourceTests.test_command_output_been_there)

 Test for failure: in_use = True.

 --

 Traceback (most recent call last):

   File
 "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
 line 89, in _execute

 return self.cursor.execute(sql, params)



   File
 "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/sqlite3/base.py",
 line 328, in execute

 return super().execute(query, params)

^^

 sqlite3.IntegrityError: NOT NULL constraint failed:
 domain_sources_app_characternumber.number_of_combinations


 The above exception was the direct cause of the following exception:


 Traceback (most recent call last):

   File
 "/Users/werker/Projects/domain_reader/tests/test_sources_app_command_populate.py",
 line 30, in test_command_output_been_there

 thingy.save()

   File
 "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
 line 814, in save

 self.save_base(

   File
 "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
 line 877, in save_base

 updated = self._save_table(

   ^

   File
 "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
 line 1020, in _save_table

 results = self._do_insert(

   

   File
 "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
 line 1061, in _do_insert

 return manager._insert(



   File
 "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/manager.py",
 line 87, in manager_method

 return getattr(self.get_queryset(), name)(*args, **kwargs)

^^^

   File
 "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/query.py",
 line 1805, in _insert

 return query.get_compiler(using=using).execute_sql(returning_fields)

^

   File
 "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/sql/compiler.py",
 line 1820, in execute_sql

 

Re: testing newbie - help requested: app works, tests give errors

2023-05-10 Thread 'Bob Aalsma' via Django users
Sorry Vishesh, thanks for the quick answer but I have no idea what you mean.

On Wednesday, May 10, 2023 at 2:00:51 PM UTC+2 Vishesh Mangla wrote:

> False or True check for yourself.
>
> On Wed, 10 May, 2023, 17:29 Vishesh Mangla,  wrote:
>
>> It looks like you are passing a null but null=False is not set
>>
>> On Wed, 10 May, 2023, 17:27 'Bob Aalsma' via Django users, <
>> django...@googlegroups.com> wrote:
>>
>>> I'm trying to test a django-admin command and don't understand why the 
>>> tests give errors on the code while the code works as expected.
>>>
>>> I'm under the impression that the *raise CommandError* is ignored by 
>>> the test, but don't understand why this would be.
>>>
>>> Please help.
>>>
>>> Running the code shows:
>>>
>>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py 
>>> populate_source 0
>>>
>>> *CommandError: Alleen hele getallen > 0 toegestaan*
>>>
>>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py 
>>> populate_source 1
>>>
>>> *Teksten zijn gegenereerd voor tekstlengte 1*
>>>
>>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py 
>>> populate_source 1
>>>
>>> *CommandError: Teksten voor nummer 1 zijn al eerder gegenereerd*
>>>
>>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py 
>>> populate_source 7
>>>
>>> *CommandError: Opgegeven sleutel 7 niet gevonden*
>>>
>>> Running the tests shows
>>>
>>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py test 
>>> tests.test_sources_app_command_populate
>>>
>>> Found 3 test(s).
>>>
>>> Creating test database for alias 'default'...
>>>
>>> System check identified no issues (0 silenced).
>>>
>>> EEE
>>>
>>> ==
>>>
>>> ERROR: test_command_output_been_there 
>>> (tests.test_sources_app_command_populate.PopulateSourceTests.test_command_output_been_there)
>>>
>>> Test for failure: in_use = True.
>>>
>>> --
>>>
>>> Traceback (most recent call last):
>>>
>>>   File 
>>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
>>>  
>>> line 89, in _execute
>>>
>>> return self.cursor.execute(sql, params)
>>>
>>>
>>>
>>>   File 
>>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/sqlite3/base.py",
>>>  
>>> line 328, in execute
>>>
>>> return super().execute(query, params)
>>>
>>>^^
>>>
>>> sqlite3.IntegrityError: NOT NULL constraint failed: 
>>> domain_sources_app_characternumber.number_of_combinations
>>>
>>>
>>> The above exception was the direct cause of the following exception:
>>>
>>>
>>> Traceback (most recent call last):
>>>
>>>   File 
>>> "/Users/werker/Projects/domain_reader/tests/test_sources_app_command_populate.py",
>>>  
>>> line 30, in test_command_output_been_there
>>>
>>> thingy.save()
>>>
>>>   File 
>>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
>>>  
>>> line 814, in save
>>>
>>> self.save_base(
>>>
>>>   File 
>>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
>>>  
>>> line 877, in save_base
>>>
>>> updated = self._save_table(
>>>
>>>   ^
>>>
>>>   File 
>>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
>>>  
>>> line 1020, in _save_table
>>>
>>> results = self._do_insert(
>>>
>>>   
>>>
>>>   File 
>>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
>>>  
>>> line 1061, in _do_insert
>>>
>>> return manager._insert(
>>>
>>>
>>>
>>>   File 
>>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/manager.py",
>>>  
>>> line 87, in manager_method
>>>
>>> return getattr(self.get_queryset(), name)(*args, **kwargs)
>>>
>>>^^^
>>>
>>>   File 
>>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/query.py",
>>>  
>>> line 1805, in _insert
>>>
>>> return query.get_compiler(using=using).execute_sql(returning_fields)
>>>
>>>^
>>>
>>>   File 
>>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/sql/compiler.py",
>>>  
>>> line 1820, in execute_sql
>>>
>>> cursor.execute(sql, params)
>>>
>>>   File 
>>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
>>>  
>>> line 67, in execute
>>>
>>> return self._execute_with_wrappers(
>>>
>>>
>>>
>>>   File 
>>> 

Re: testing newbie - help requested: app works, tests give errors

2023-05-10 Thread Vishesh Mangla
False or True check for yourself.

On Wed, 10 May, 2023, 17:29 Vishesh Mangla, 
wrote:

> It looks like you are passing a null but null=False is not set
>
> On Wed, 10 May, 2023, 17:27 'Bob Aalsma' via Django users, <
> django-users@googlegroups.com> wrote:
>
>> I'm trying to test a django-admin command and don't understand why the
>> tests give errors on the code while the code works as expected.
>>
>> I'm under the impression that the *raise CommandError* is ignored by the
>> test, but don't understand why this would be.
>>
>> Please help.
>>
>> Running the code shows:
>>
>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py
>> populate_source 0
>>
>> *CommandError: Alleen hele getallen > 0 toegestaan*
>>
>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py
>> populate_source 1
>>
>> *Teksten zijn gegenereerd voor tekstlengte 1*
>>
>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py
>> populate_source 1
>>
>> *CommandError: Teksten voor nummer 1 zijn al eerder gegenereerd*
>>
>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py
>> populate_source 7
>>
>> *CommandError: Opgegeven sleutel 7 niet gevonden*
>>
>> Running the tests shows
>>
>> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py test
>> tests.test_sources_app_command_populate
>>
>> Found 3 test(s).
>>
>> Creating test database for alias 'default'...
>>
>> System check identified no issues (0 silenced).
>>
>> EEE
>>
>> ==
>>
>> ERROR: test_command_output_been_there
>> (tests.test_sources_app_command_populate.PopulateSourceTests.test_command_output_been_there)
>>
>> Test for failure: in_use = True.
>>
>> --
>>
>> Traceback (most recent call last):
>>
>>   File
>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
>> line 89, in _execute
>>
>> return self.cursor.execute(sql, params)
>>
>>
>>
>>   File
>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/sqlite3/base.py",
>> line 328, in execute
>>
>> return super().execute(query, params)
>>
>>^^
>>
>> sqlite3.IntegrityError: NOT NULL constraint failed:
>> domain_sources_app_characternumber.number_of_combinations
>>
>>
>> The above exception was the direct cause of the following exception:
>>
>>
>> Traceback (most recent call last):
>>
>>   File
>> "/Users/werker/Projects/domain_reader/tests/test_sources_app_command_populate.py",
>> line 30, in test_command_output_been_there
>>
>> thingy.save()
>>
>>   File
>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
>> line 814, in save
>>
>> self.save_base(
>>
>>   File
>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
>> line 877, in save_base
>>
>> updated = self._save_table(
>>
>>   ^
>>
>>   File
>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
>> line 1020, in _save_table
>>
>> results = self._do_insert(
>>
>>   
>>
>>   File
>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
>> line 1061, in _do_insert
>>
>> return manager._insert(
>>
>>
>>
>>   File
>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/manager.py",
>> line 87, in manager_method
>>
>> return getattr(self.get_queryset(), name)(*args, **kwargs)
>>
>>^^^
>>
>>   File
>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/query.py",
>> line 1805, in _insert
>>
>> return query.get_compiler(using=using).execute_sql(returning_fields)
>>
>>^
>>
>>   File
>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/sql/compiler.py",
>> line 1820, in execute_sql
>>
>> cursor.execute(sql, params)
>>
>>   File
>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
>> line 67, in execute
>>
>> return self._execute_with_wrappers(
>>
>>
>>
>>   File
>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
>> line 80, in _execute_with_wrappers
>>
>> return executor(sql, params, many, context)
>>
>>
>>
>>   File
>> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
>> line 84, in _execute
>>
>> with 

Re: testing newbie - help requested: app works, tests give errors

2023-05-10 Thread Vishesh Mangla
It looks like you are passing a null but null=False is not set

On Wed, 10 May, 2023, 17:27 'Bob Aalsma' via Django users, <
django-users@googlegroups.com> wrote:

> I'm trying to test a django-admin command and don't understand why the
> tests give errors on the code while the code works as expected.
>
> I'm under the impression that the *raise CommandError* is ignored by the
> test, but don't understand why this would be.
>
> Please help.
>
> Running the code shows:
>
> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py
> populate_source 0
>
> *CommandError: Alleen hele getallen > 0 toegestaan*
>
> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py
> populate_source 1
>
> *Teksten zijn gegenereerd voor tekstlengte 1*
>
> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py
> populate_source 1
>
> *CommandError: Teksten voor nummer 1 zijn al eerder gegenereerd*
>
> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py
> populate_source 7
>
> *CommandError: Opgegeven sleutel 7 niet gevonden*
>
> Running the tests shows
>
> (.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py test
> tests.test_sources_app_command_populate
>
> Found 3 test(s).
>
> Creating test database for alias 'default'...
>
> System check identified no issues (0 silenced).
>
> EEE
>
> ==
>
> ERROR: test_command_output_been_there
> (tests.test_sources_app_command_populate.PopulateSourceTests.test_command_output_been_there)
>
> Test for failure: in_use = True.
>
> --
>
> Traceback (most recent call last):
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
> line 89, in _execute
>
> return self.cursor.execute(sql, params)
>
>
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/sqlite3/base.py",
> line 328, in execute
>
> return super().execute(query, params)
>
>^^
>
> sqlite3.IntegrityError: NOT NULL constraint failed:
> domain_sources_app_characternumber.number_of_combinations
>
>
> The above exception was the direct cause of the following exception:
>
>
> Traceback (most recent call last):
>
>   File
> "/Users/werker/Projects/domain_reader/tests/test_sources_app_command_populate.py",
> line 30, in test_command_output_been_there
>
> thingy.save()
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
> line 814, in save
>
> self.save_base(
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
> line 877, in save_base
>
> updated = self._save_table(
>
>   ^
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
> line 1020, in _save_table
>
> results = self._do_insert(
>
>   
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
> line 1061, in _do_insert
>
> return manager._insert(
>
>
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/manager.py",
> line 87, in manager_method
>
> return getattr(self.get_queryset(), name)(*args, **kwargs)
>
>^^^
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/query.py",
> line 1805, in _insert
>
> return query.get_compiler(using=using).execute_sql(returning_fields)
>
>^
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/sql/compiler.py",
> line 1820, in execute_sql
>
> cursor.execute(sql, params)
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
> line 67, in execute
>
> return self._execute_with_wrappers(
>
>
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
> line 80, in _execute_with_wrappers
>
> return executor(sql, params, many, context)
>
>
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
> line 84, in _execute
>
> with self.db.wrap_database_errors:
>
>   File
> "/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/utils.py",
> line 91, in __exit__
>
> raise dj_exc_value.with_traceback(traceback) from exc_value
>
>   File
> 

testing newbie - help requested: app works, tests give errors

2023-05-10 Thread 'Bob Aalsma' via Django users
I'm trying to test a django-admin command and don't understand why the 
tests give errors on the code while the code works as expected.

I'm under the impression that the *raise CommandError* is ignored by the 
test, but don't understand why this would be.

Please help.

Running the code shows:

(.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py 
populate_source 0

*CommandError: Alleen hele getallen > 0 toegestaan*

(.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py 
populate_source 1

*Teksten zijn gegenereerd voor tekstlengte 1*

(.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py 
populate_source 1

*CommandError: Teksten voor nummer 1 zijn al eerder gegenereerd*

(.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py 
populate_source 7

*CommandError: Opgegeven sleutel 7 niet gevonden*

Running the tests shows

(.venv) werker@Werkers-Mac-mini domain_reader % python3 manage.py test 
tests.test_sources_app_command_populate

Found 3 test(s).

Creating test database for alias 'default'...

System check identified no issues (0 silenced).

EEE

==

ERROR: test_command_output_been_there 
(tests.test_sources_app_command_populate.PopulateSourceTests.test_command_output_been_there)

Test for failure: in_use = True.

--

Traceback (most recent call last):

  File 
"/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
 
line 89, in _execute

return self.cursor.execute(sql, params)

   

  File 
"/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/sqlite3/base.py",
 
line 328, in execute

return super().execute(query, params)

   ^^

sqlite3.IntegrityError: NOT NULL constraint failed: 
domain_sources_app_characternumber.number_of_combinations


The above exception was the direct cause of the following exception:


Traceback (most recent call last):

  File 
"/Users/werker/Projects/domain_reader/tests/test_sources_app_command_populate.py",
 
line 30, in test_command_output_been_there

thingy.save()

  File 
"/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
 
line 814, in save

self.save_base(

  File 
"/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
 
line 877, in save_base

updated = self._save_table(

  ^

  File 
"/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
 
line 1020, in _save_table

results = self._do_insert(

  

  File 
"/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/base.py",
 
line 1061, in _do_insert

return manager._insert(

   

  File 
"/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/manager.py",
 
line 87, in manager_method

return getattr(self.get_queryset(), name)(*args, **kwargs)

   ^^^

  File 
"/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/query.py",
 
line 1805, in _insert

return query.get_compiler(using=using).execute_sql(returning_fields)

   ^

  File 
"/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/models/sql/compiler.py",
 
line 1820, in execute_sql

cursor.execute(sql, params)

  File 
"/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
 
line 67, in execute

return self._execute_with_wrappers(

   

  File 
"/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
 
line 80, in _execute_with_wrappers

return executor(sql, params, many, context)

   

  File 
"/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
 
line 84, in _execute

with self.db.wrap_database_errors:

  File 
"/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/utils.py",
 
line 91, in __exit__

raise dj_exc_value.with_traceback(traceback) from exc_value

  File 
"/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/utils.py",
 
line 89, in _execute

return self.cursor.execute(sql, params)

   

  File 
"/Users/werker/Projects/domain_reader/.venv/lib/python3.11/site-packages/django/db/backends/sqlite3/base.py",
 
line 328, in execute

return super().execute(query, 

Re: Testing django

2023-03-16 Thread Ayush Bisht
Yeah, I got you..
My concern is on the documentation, the way it has provided the commands
for executing test cases.

That
path.to.settings seems confusing sometimes..

On Fri, 17 Mar, 2023, 1:20 am Bhuvnesh Sharma, 
wrote:

> We can run django tests with custom settings by using --settings flag and
> providing the path to the custom settings file . For example:
> ./runtests.py --settings=new_app.test_settings
>
> What do you want to do exactly?
>
> On Fri, Mar 17, 2023 at 1:00 AM Ayush Bisht 
> wrote:
>
>> Seems like, it is for defining how actually we are selecting the specific
>> test case. It is very confusing at first.
>> Can't we just explain it with an example..
>>
>> On Friday, March 17, 2023 at 12:54:27 AM UTC+5:30 Ayush Bisht wrote:
>>
>>> * ./runtests.py --settings=path.to.settings i18n.tests.TranslationTests*
>>>
>>> what exactly is the purpose of *path.to.settings,* I'm getting an error
>>> while running the above line.
>>> Can anyone please explain?
>>>
>>> *Error*
>>> Testing against Django installed in '/home/ayush/OS/django/django' with
>>> up to 8 processes
>>> Traceback (most recent call last):
>>>   File "/home/ayush/OS/django/tests/./runtests.py", line 770, in 
>>> failures = django_tests(
>>>   File "/home/ayush/OS/django/tests/./runtests.py", line 398, in
>>> django_tests
>>> test_labels, state = setup_run_tests(*process_setup_args)
>>>   File "/home/ayush/OS/django/tests/./runtests.py", line 300, in
>>> setup_run_tests
>>> test_modules, state = setup_collect_tests(
>>>   File "/home/ayush/OS/django/tests/./runtests.py", line 201, in
>>> setup_collect_tests
>>> "INSTALLED_APPS": settings.INSTALLED_APPS,
>>>   File "/home/ayush/OS/django/django/conf/__init__.py", line 84, in
>>> __getattr__
>>> self._setup(name)
>>>   File "/home/ayush/OS/django/django/conf/__init__.py", line 71, in
>>> _setup
>>> self._wrapped = Settings(settings_module)
>>>   File "/home/ayush/OS/django/django/conf/__init__.py", line 185, in
>>> __init__
>>> mod = importlib.import_module(self.SETTINGS_MODULE)
>>>   File "/usr/lib/python3.10/importlib/__init__.py", line 126, in
>>> import_module
>>> return _bootstrap._gcd_import(name[level:], package, level)
>>>   File "", line 1050, in _gcd_import
>>>   File "", line 1027, in _find_and_load
>>>   File "", line 992, in
>>> _find_and_load_unlocked
>>>   File "", line 241, in
>>> _call_with_frames_removed
>>>   File "", line 1050, in _gcd_import
>>>   File "", line 1027, in _find_and_load
>>>   File "", line 992, in
>>> _find_and_load_unlocked
>>>   File "", line 241, in
>>> _call_with_frames_removed
>>>   File "", line 1050, in _gcd_import
>>>   File "", line 1027, in _find_and_load
>>>   File "", line 1004, in
>>> _find_and_load_unlocked
>>> ModuleNotFoundError: No module named 'path'
>>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/dd827ca8-704e-4ffc-8d7a-2c56d100cdd7n%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/dd827ca8-704e-4ffc-8d7a-2c56d100cdd7n%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2BZJHEqMWEj8dE9gpVW0f5QajXy1b9GPp-Qur4457GMoWAoUbQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CA%2BZJHEqMWEj8dE9gpVW0f5QajXy1b9GPp-Qur4457GMoWAoUbQ%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B%2BM4H5-M%2B6T5PvfctNYJR7o0ebry_4f-JUGec8QewJs%2BhASNg%40mail.gmail.com.


Re: Testing django

2023-03-16 Thread Bhuvnesh Sharma
We can run django tests with custom settings by using --settings flag and
providing the path to the custom settings file . For example:
./runtests.py --settings=new_app.test_settings

What do you want to do exactly?

On Fri, Mar 17, 2023 at 1:00 AM Ayush Bisht 
wrote:

> Seems like, it is for defining how actually we are selecting the specific
> test case. It is very confusing at first.
> Can't we just explain it with an example..
>
> On Friday, March 17, 2023 at 12:54:27 AM UTC+5:30 Ayush Bisht wrote:
>
>> * ./runtests.py --settings=path.to.settings i18n.tests.TranslationTests*
>>
>> what exactly is the purpose of *path.to.settings,* I'm getting an error
>> while running the above line.
>> Can anyone please explain?
>>
>> *Error*
>> Testing against Django installed in '/home/ayush/OS/django/django' with
>> up to 8 processes
>> Traceback (most recent call last):
>>   File "/home/ayush/OS/django/tests/./runtests.py", line 770, in 
>> failures = django_tests(
>>   File "/home/ayush/OS/django/tests/./runtests.py", line 398, in
>> django_tests
>> test_labels, state = setup_run_tests(*process_setup_args)
>>   File "/home/ayush/OS/django/tests/./runtests.py", line 300, in
>> setup_run_tests
>> test_modules, state = setup_collect_tests(
>>   File "/home/ayush/OS/django/tests/./runtests.py", line 201, in
>> setup_collect_tests
>> "INSTALLED_APPS": settings.INSTALLED_APPS,
>>   File "/home/ayush/OS/django/django/conf/__init__.py", line 84, in
>> __getattr__
>> self._setup(name)
>>   File "/home/ayush/OS/django/django/conf/__init__.py", line 71, in _setup
>> self._wrapped = Settings(settings_module)
>>   File "/home/ayush/OS/django/django/conf/__init__.py", line 185, in
>> __init__
>> mod = importlib.import_module(self.SETTINGS_MODULE)
>>   File "/usr/lib/python3.10/importlib/__init__.py", line 126, in
>> import_module
>> return _bootstrap._gcd_import(name[level:], package, level)
>>   File "", line 1050, in _gcd_import
>>   File "", line 1027, in _find_and_load
>>   File "", line 992, in
>> _find_and_load_unlocked
>>   File "", line 241, in
>> _call_with_frames_removed
>>   File "", line 1050, in _gcd_import
>>   File "", line 1027, in _find_and_load
>>   File "", line 992, in
>> _find_and_load_unlocked
>>   File "", line 241, in
>> _call_with_frames_removed
>>   File "", line 1050, in _gcd_import
>>   File "", line 1027, in _find_and_load
>>   File "", line 1004, in
>> _find_and_load_unlocked
>> ModuleNotFoundError: No module named 'path'
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/dd827ca8-704e-4ffc-8d7a-2c56d100cdd7n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/dd827ca8-704e-4ffc-8d7a-2c56d100cdd7n%40googlegroups.com?utm_medium=email_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BZJHEqMWEj8dE9gpVW0f5QajXy1b9GPp-Qur4457GMoWAoUbQ%40mail.gmail.com.


Re: Testing django

2023-03-16 Thread Ayush Bisht
Seems like, it is for defining how actually we are selecting the specific 
test case. It is very confusing at first. 
Can't we just explain it with an example..

On Friday, March 17, 2023 at 12:54:27 AM UTC+5:30 Ayush Bisht wrote:

> * ./runtests.py --settings=path.to.settings i18n.tests.TranslationTests*
>
> what exactly is the purpose of *path.to.settings,* I'm getting an error 
> while running the above line.
> Can anyone please explain?
>
> *Error*  
> Testing against Django installed in '/home/ayush/OS/django/django' with up 
> to 8 processes
> Traceback (most recent call last):
>   File "/home/ayush/OS/django/tests/./runtests.py", line 770, in 
> failures = django_tests(
>   File "/home/ayush/OS/django/tests/./runtests.py", line 398, in 
> django_tests
> test_labels, state = setup_run_tests(*process_setup_args)
>   File "/home/ayush/OS/django/tests/./runtests.py", line 300, in 
> setup_run_tests
> test_modules, state = setup_collect_tests(
>   File "/home/ayush/OS/django/tests/./runtests.py", line 201, in 
> setup_collect_tests
> "INSTALLED_APPS": settings.INSTALLED_APPS,
>   File "/home/ayush/OS/django/django/conf/__init__.py", line 84, in 
> __getattr__
> self._setup(name)
>   File "/home/ayush/OS/django/django/conf/__init__.py", line 71, in _setup
> self._wrapped = Settings(settings_module)
>   File "/home/ayush/OS/django/django/conf/__init__.py", line 185, in 
> __init__
> mod = importlib.import_module(self.SETTINGS_MODULE)
>   File "/usr/lib/python3.10/importlib/__init__.py", line 126, in 
> import_module
> return _bootstrap._gcd_import(name[level:], package, level)
>   File "", line 1050, in _gcd_import
>   File "", line 1027, in _find_and_load
>   File "", line 992, in 
> _find_and_load_unlocked
>   File "", line 241, in 
> _call_with_frames_removed
>   File "", line 1050, in _gcd_import
>   File "", line 1027, in _find_and_load
>   File "", line 992, in 
> _find_and_load_unlocked
>   File "", line 241, in 
> _call_with_frames_removed
>   File "", line 1050, in _gcd_import
>   File "", line 1027, in _find_and_load
>   File "", line 1004, in 
> _find_and_load_unlocked
> ModuleNotFoundError: No module named 'path'
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dd827ca8-704e-4ffc-8d7a-2c56d100cdd7n%40googlegroups.com.


Testing django

2023-03-16 Thread Ayush Bisht
* ./runtests.py --settings=path.to.settings i18n.tests.TranslationTests*

what exactly is the purpose of *path.to.settings,* I'm getting an error 
while running the above line.
Can anyone please explain?

*Error*  
Testing against Django installed in '/home/ayush/OS/django/django' with up 
to 8 processes
Traceback (most recent call last):
  File "/home/ayush/OS/django/tests/./runtests.py", line 770, in 
failures = django_tests(
  File "/home/ayush/OS/django/tests/./runtests.py", line 398, in 
django_tests
test_labels, state = setup_run_tests(*process_setup_args)
  File "/home/ayush/OS/django/tests/./runtests.py", line 300, in 
setup_run_tests
test_modules, state = setup_collect_tests(
  File "/home/ayush/OS/django/tests/./runtests.py", line 201, in 
setup_collect_tests
"INSTALLED_APPS": settings.INSTALLED_APPS,
  File "/home/ayush/OS/django/django/conf/__init__.py", line 84, in 
__getattr__
self._setup(name)
  File "/home/ayush/OS/django/django/conf/__init__.py", line 71, in _setup
self._wrapped = Settings(settings_module)
  File "/home/ayush/OS/django/django/conf/__init__.py", line 185, in 
__init__
mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in 
import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 1050, in _gcd_import
  File "", line 1027, in _find_and_load
  File "", line 992, in _find_and_load_unlocked
  File "", line 241, in 
_call_with_frames_removed
  File "", line 1050, in _gcd_import
  File "", line 1027, in _find_and_load
  File "", line 992, in _find_and_load_unlocked
  File "", line 241, in 
_call_with_frames_removed
  File "", line 1050, in _gcd_import
  File "", line 1027, in _find_and_load
  File "", line 1004, in 
_find_and_load_unlocked
ModuleNotFoundError: No module named 'path'

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f3d46fc7-0b31-4f28-844a-16462982a439n%40googlegroups.com.


Anyone testing async views with django test client?

2022-09-20 Thread 'SP' via Django users
My async  CBV works when accessed through my url endpoint with REQUESTS 
package.  But with the django test client it seems to think the database 
doesn't contain the information I'm trying to pull using ORM. I've 
confirmed that the data DOES exist in the newly recreated DB (populated 
with fixtures in my TestCase based class. 

Any suggestions would be appreciated!

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1e727d43-93ae-462d-985f-853f3ed418ccn%40googlegroups.com.


Re: Database objects do not implement truth value testing

2022-02-24 Thread Kasper Laudrup

On 24/02/2022 16.18, Pradumn Maurya wrote:
Dear Sir/Mam I just face this problem when i am using makemigrations 
cmd, how can i fix this. Can any one help me solve this problem?




I'm fairly certain no one will be able to help you solve this problem if 
you don't describe it a bit more in detail.


Keep in mind no one here has any idea what you are trying to do or what 
your code looks like.


Kind regards,

Kasper Laudrup

--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c53d5ba4-12db-2659-a688-a770fa2e4849%40stacktrace.dk.


OpenPGP_0xE5D9CAC64AAA55EB.asc
Description: OpenPGP public key


OpenPGP_signature
Description: OpenPGP digital signature


NotImplementedError: Database objects do not implement truth value testing or bool(). Please compare with None instead: database is not None

2022-01-21 Thread Oumar Thiombane
NotImplementedError: Database objects do not implement truth value testing 
or bool(). Please compare with None instead: database is not None

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/908bcc74-732a-4805-b94b-9922a9c8c2a8n%40googlegroups.com.


[Solved]: Unit testing migrations [Was: Related model 'company.user' cannot be resolved]

2021-07-07 Thread Mike Dewhirst

On 7/07/2021 9:56 am, Mike Dewhirst wrote:
It seems I have to meddle with history and persuade the testing 
harness that my custom user model has been in the company app from the 
beginning of time. See story below.


Upside is that testing will (might) start working again. Downside is 
I'll go mad.


All upside!

So in summary ...

0. The mission was to move all models (User and UserProfile) from the 
common app to the company app so users and companies would both appear 
in the Admin in the same app. This simplifies the site adminstration 
main menu for new users.


1. In class Meta: in both models User/UserProfile, add db_table = 
common_user/userprofile[1]. This will have no effect and should be 
committed, migrated and deployed to production.


2. Branch the code and switch to create an escape route.

3. Relocate User and UserProfile models from app common to app company[2]

4. Refactor entire codebase using company_ instead of common_ [3]

5. makemigrations[4] but do not migrate to avoid deleting tables.

Now the tricky bit. What I did was probably wrong and any expert is 
welcome to suggest an improvement but because of steps 1 and 2 there was 
always a retreat. The mission here is to tweak the migrations so the 
test harness can create a test database without error.


6. Delete the migration which deletes User and UserProfile tables from 
common


7. Edit company/migrations/0001_initial.py to include the contents of 
the latest migration which created User and UserProfile in company so 
that the test harness thinks they have been there since the beginning. 
Then delete that latest company migration too.


8. Delete all migrations in common/migrations including __pycache__ [5]

9. Cross fingers and run your tests. Resolve any errors by adjusting 
dependencies which includes positioning User and UserProfile higher or 
lower in 0001_initial.py in company/migrations[6].


10. Consider editing your django_migrations table to remove rows 
relating to deleted migrations. This is for future-proofing in case you 
ever decide to put any tables back in the common app. If 0001_initial is 
mentioned in that table it will be a confusing preventer.


11. Merge your successful changes back to your main branch and deploy.


[1] One day I will rename the tables so everything lines up but for now 
that is a step too far


[2] I did try leaving the models in place and importing them into the 
company app but things quickly got messy. Much easier to bite the bullet 
and just physically move the files.


[3] At this point the software should work but unit testing will fail 
because the test database is always generated from the sum total of all 
migrations


[4] This will make table deletions from common and table creations in 
company BUT the creations will be for the current state. This becomes 
significant later in the process.


[5] All migrations in common/migrations were for the only two models in 
the common app. Because the creation migration was for the current 
state, none of the other migrations were needed. However, your mileage 
may vary perhaps if your migrations did other things than just changing 
structure etc. If you also did some data tweaking in some migrations you 
will want to think a bit harder before deleting them.


[6] In my case I needed to put User at the beginning and UserProfile at 
the end of that migration. Here is the relevant piece of my 
company/migrations/0001_initial.py  ... note the db_table in options ...


 


class Migration(migrations.Migration):

initial = True

dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, 
serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, 
verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, 
verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, 
help_text='Designates that this user has all permissions without explicitly 
assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user 
with that username already exists.'}, help_text='Required. 150 characters or 
fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, 
validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], 
verbose_name='username')),
('date_joined', 
models.DateTimeField(default=django.utils.timezone.now, verbose_name='date 
joined')),
('first_name', models.CharField(blank=True, max_length=30, 
verbose_name='short name')),
('last_name', models.CharField(blank=True, max_length=150, 
verbose_name='full name

Unit testing migrations [Was: Related model 'company.user' cannot be resolved]

2021-07-06 Thread Mike Dewhirst
It seems I have to meddle with history and persuade the testing harness 
that my custom user model has been in the company app from the beginning 
of time. See story below.


Upside is that testing will (might) start working again. Downside is 
I'll go mad.


Any ideas?

Thanks

Mike

On 6/07/2021 11:40 am, Mike Dewhirst wrote:
I moved my custom user and userprofile models from my 'common' app 
into my 'company' app by way of locking the model tables first 
(db_table = "common_user" and so on) and just plain refactoring.


That has all worked sort of as expected in that Company and User 
models now appear in the company app space in the Admin which was my 
original motivation.


makemigrations wanted to destroy data with delete/create models in 
order to move them and of course I couldn't let that happen. migrate 
--fake and migrate --fake-initial wouldn't work due to lots of other 
models looking for settings.AUTH_USER_MODEL which Django couldn't find 
in the company app so I finessed my own fake migrations. That also 
seemed to work and the job seemed done.


BUT manage.py test now fails with "Related model 'company.user' cannot 
be resolved"


StackOverflow seems to indicate my finessed migrations are at fault. I 
have tried to tweak the dependencies with no luck as follows ...


# company.migrations.0005_user_userprofile.py
...
    dependencies = [
    ('auth', '0012_alter_user_first_name_max_length'),
    ('company', '0004_auto_20210510_1431'),       # older pre move 
migration

    ('common', '0008_auto_20210705_1740'),        # see below
    ]

    operations = [
    migrations.CreateModel(
    name='User',
    fields=[
    ('id', models.BigAutoField(auto_created=True, 
primary_key=True, serialize=False, verbose_name='ID')),
    ('password', models.CharField(max_length=128, 
verbose_name='password')),

... etc for creating both User and UserProfile models

# common.migrations.0008_auto_20210705_1740.py
...
    dependencies = [
    ('common', '0007_userprofile_job_title'),    # older pre-move 
migration

    ]

    operations = [
    migrations.RemoveField(
    model_name='userprofile',
    name='company',
    ),
    migrations.RemoveField(
    model_name='userprofile',
    name='user',
    ),
    migrations.DeleteModel(
    name='User',
    ),
    migrations.DeleteModel(
    name='UserProfile',
    ),
    ]


Django 3.2.5, Python 3.8

I feel I should have zigged when I should've zagged. Thanks for any 
suggestions


Mike

Traceback (most recent call last):
  File "manage.py", line 21, in 
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File 
"D:\Users\mike\envs\xxai\lib\site-packages\django\core\management\__init__.py", 
line 419, in execute_from_command_line

    utility.execute()
  File 
"D:\Users\mike\envs\xxai\lib\site-packages\django\core\management\__init__.py", 
line 413, in execute

    self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"D:\Users\mike\envs\xxai\lib\site-packages\django\core\management\commands\test.py", 
line 23, in run_from_argv

    super().run_from_argv(argv)
  File 
"D:\Users\mike\envs\xxai\lib\site-packages\django\core\management\base.py", 
line 354, in run_from_argv

    self.execute(*args, **cmd_options)
  File 
"D:\Users\mike\envs\xxai\lib\site-packages\django\core\management\base.py", 
line 398, in execute

    output = self.handle(*args, **options)
  File 
"D:\Users\mike\envs\xxai\lib\site-packages\django\core\management\commands\test.py", 
line 55, in handle

    failures = test_runner.run_tests(test_labels)
  File 
"D:\Users\mike\envs\xxai\lib\site-packages\django\test\runner.py", 
line 725, in run_tests

    old_config = self.setup_databases(aliases=databases)
  File 
"D:\Users\mike\envs\xxai\lib\site-packages\django\test\runner.py", 
line 643, in setup_databases

    return _setup_databases(
  File 
"D:\Users\mike\envs\xxai\lib\site-packages\django\test\utils.py", line 
179, in setup_databases

    connection.creation.create_test_db(
  File 
"D:\Users\mike\envs\xxai\lib\site-packages\django\db\backends\base\creation.py", 
line 74, in create_test_db

    call_command(
  File 
"D:\Users\mike\envs\xxai\lib\site-packages\django\core\management\__init__.py", 
line 181, in call_command

    return command.execute(*args, **defaults)
  File 
"D:\Users\mike\envs\xxai\lib\site-packages\django\core\management\base.py", 
line 398, in execute

    output = self.handle(*args, **options)
  File 
"D:\Users\mike\envs\xxai\lib\site-packages\django\core\management\base.py", 
line 89, in wrapped

    res = handle_func(*args, **kwargs)
  File 
"D:\Users\mike\envs\xxai\lib\site-packages\django\core\management\command

A/B testing recommendations

2021-04-27 Thread Andréas Kühne
Hi all,

I am working on a website where we now want to do A/B testing. Now I have
previously looked into this - but have never found any good packages for
doing that. The landscape may have changed now then, so I was wondering if
anyone has any good suggestions for A/B testing packages? Or if anyone has
any good experiences that they want to share?

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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK4qSCdaWWi8VyaWLDaW3tLOpgff8fB8sPHDzUMysU%2BheiS69A%40mail.gmail.com.


Re: Testing Django User Login Form

2021-04-23 Thread lone...@gmail.com
Thank you for the reply!  I will totally try this tonight!

On Thursday, April 22, 2021 at 7:31:40 PM UTC-4 David Nugent wrote:

> Try creating a request using RequestFactory and use that to input the 
> credentials. I don't think the way you are creating the form is valid.
>
> rf = RequestFactory()
> request = rf.post('/some_mock_url', dict(username='abc', 
> password='password'))
> form = AuthenticationForm(request)
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e3079f83-6175-4852-9a6a-f94625079af4n%40googlegroups.com.


Re: Testing Django User Login Form

2021-04-22 Thread David Nugent
Try creating a request using RequestFactory and use that to input the
credentials. I don't think the way you are creating the form is valid.

rf = RequestFactory()
request = rf.post('/some_mock_url', dict(username='abc',
password='password'))
form = AuthenticationForm(request)

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAE5VhgWBM7dqPBzMc4P8eGCOuksM54kcnPnVA83ciE93C6bqWw%40mail.gmail.com.


Testing Django User Login Form

2021-04-18 Thread lone...@gmail.com
Hello all,

I am not sure what I am doing incorrectly with the below test case 
information.  I am simply trying to test the default authentication form of 
django 3.1.  This test should be a good/True login test.

Here is the Test case:-
class TestForms(TestCase):
def test_invalid_username(self):
# The user submits an invalid username.
data = {
'username': 'abc',
'password': 'password',
}
form = AuthenticationForm(None, data)
self.assertTrue(form.is_valid())


Here is what I am getting for output:

FAIL: test_invalid_username (rucklogs.tests.TestForms)
--
Traceback (most recent call last):
  File "/home/lonesoac0/django/rucker2021/rucklogs/tests.py", line 39, in 
test_invalid_username
self.assertTrue(form.is_valid())
AssertionError: False is not true
---

As you can see in the attached screenshot, the user abc is a good user.

Thank you.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5acae9ea-ae51-438b-8c31-6b926581d3d1n%40googlegroups.com.


Django reverse lookup fails during unit testing

2021-03-16 Thread Derek
Hi

When I open the Django shell (python manage.py shell) and test a reverse
URL:

>>> from django.urls import reverse
>>> reverse('admin:locales_site_changelist')
'/admin/locales/site/'

then it works as expected.

However, when I try and use the same lookup string via a unit test:

from django.test import TestCase
from core.models import CustomUser as User

class TestCaseSimple(TestCase):

def setUp(self):
User.objects.create_superuser(
email='t...@example.com',
password='password')
self.login = self.client.login(
email='t...@example.com',
password='password')
print('Login successful? ', self.login)  # True
url = reverse('admin:locales_site_changelist')


I get this error:

E   django.urls.exceptions.NoReverseMatch: Reverse for
'locales_site_changelist' not found. 'locales_site_changelist' is not a
valid view function or pattern name.


Is there some simple reason why reverse lookup does not work when testing?
(I actually need to use it in a client post request.)

Thanks
Derek

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAF1Wu3NmqC%2BqWK9v%3DNXa%3DOaLc2N3p1dkZ40r1n7gXuCk1gDaQQ%40mail.gmail.com.


Django Channels - Monitoring and Testing Performance in Prod

2021-01-05 Thread Myer Nore
I work on an app that has Django Channels 1 deployed in production with 
CPU-based auto-scaling. Most of the time, it works fine, but sometimes, 
when the site is busy and many users are utilizing the parts of our 
application that are channels-intensive, users are unable to utilize their 
websocket, and we need better metrics to help us determine the root cause 
fix.   

   1. How do you monitor Django Channels in production? 
   2. What are your favorite strategies for integrating with DataDog or New 
   Relic? 
   3. I'm considering writing some JS that detects a degraded websocket 
   connection and posts a DataDog custom event 
   (https://docs.datadoghq.com/api/v1/events/). What's a better way to 
   accomplish the same thing?

Many thanks,
Myer

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/30ea0e94-bf98-43f4-a514-848db9e4d688n%40googlegroups.com.


Re: Hello ! I'm having some issues in django unit testing. Is there anybody to help ?

2020-11-06 Thread Monaco investment
Am having hard time learning django...can someone please get in touch...I will 
be really grateful... thanks

Get Outlook for Android<https://aka.ms/ghei36>


From: django-users@googlegroups.com  on behalf 
of Nilima Dahal 
Sent: Friday, November 6, 2020 1:11:59 PM
To: Django users 
Subject: Hello ! I'm having some issues in django unit testing. Is there 
anybody to help ?

Hello ! I'm having some issues in django unit testing. Is there anybody to help 
?
I'm having confusion in testing django mixins . Can anyone share his/her git 
with such unit testing or have some experienced shareable codes.

how do I test this ?

def dispatch(self,request,*args,**kwargs):
if self.request.user.is_superuser:
return super().dispatch(request, *args, **kwargs)
return self.handle_no_permission()




--
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+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/44f22b97-7499-4762-92d2-59fa6dd6ad8bn%40googlegroups.com<https://groups.google.com/d/msgid/django-users/44f22b97-7499-4762-92d2-59fa6dd6ad8bn%40googlegroups.com?utm_medium=email_source=footer>.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/AM6PR03MB595708923241D013CF47325AA7EC0%40AM6PR03MB5957.eurprd03.prod.outlook.com.


Hello ! I'm having some issues in django unit testing. Is there anybody to help ?

2020-11-06 Thread Nilima Dahal
Hello ! I'm having some issues in django unit testing. Is there anybody to 
help ? 
I'm having confusion in testing django mixins . Can anyone share his/her 
git with such unit testing or have some experienced shareable codes.

how do I test this ?

def dispatch(self,request,*args,**kwargs):
if self.request.user.is_superuser:
return super().dispatch(request, *args, **kwargs)
return self.handle_no_permission()



-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/44f22b97-7499-4762-92d2-59fa6dd6ad8bn%40googlegroups.com.


RES: testing class based generic views

2020-10-26 Thread Samuel Nogueira
I don’t know a test tutorial, but I think you can get some help in the Django docs. https://docs.djangoproject.com/en/3.1/topics/testing/tools/  -Samuel Nogueira Bacelar GitHub: https://github.com/SamuelNoB Linkedin: https://www.linkedin.com/in/samuel-nogueira-87800b1aa/ - De: Patrick CarraEnviado:sábado, 24 de outubro de 2020 16:53Para: Django usersAssunto: testing class based generic views Can anyone point me towards a tutorial for how to test a CreateView function?  -- 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+unsubscr...@googlegroups.com.To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/76d377cf-a6e2-46ec-b4ee-5d1279988b32n%40googlegroups.com. 



-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0D30453B-EAF5-4EDB-AC48-3C451052E055%40hxcore.ol.


testing class based generic views

2020-10-24 Thread Patrick Carra
Can anyone point me towards a tutorial for how to test a CreateView 
function? 

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/76d377cf-a6e2-46ec-b4ee-5d1279988b32n%40googlegroups.com.


Re: django testing: widgets

2020-10-11 Thread Dvs Khamele
Hi do you hire contract based python/django freelancer?
 We can help you in this and related tasks at fair prices. Reply or send
email to divy...@pythonmate.com
Best Regards,
Divyesh Khamele,
Pythonmate

On Thu, 1 Oct 2020, 6:32 pm albert,  wrote:

> Hi
> due to the impact of corona/covid19 I am working in a django-web-project.
> (I am a beginner to those Technologies...)
>
> At the moment I am writing tests for a django application. Basic tests for
> creating get- and post-request with the test server (client) are working.
>
> But now I am facing a file upload request which is triggered by a widget
> of a html page. After reading some settings it calls ajax file upload -
> resulting in a complex request with multiple settings...
>
> Now I'm looking for a way to refer this funcionality mentioned above from
> a django test to get exactly the same request.
>
> Is there a way to do this? (Any hints are welcome... !)
>
> Thanks in advance
> Albert.
>
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/433bc5ea-ed05-4efa-bd02-96335126b541o%40googlegroups.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAH9mneWBi1ztu68N%3DH5EGuEk1MYrLH6Z4MaMBwcF6w7O%3D3%3D6rw%40mail.gmail.com.


django testing: widgets

2020-10-01 Thread albert
Hi
due to the impact of corona/covid19 I am working in a django-web-project. 
(I am a beginner to those Technologies...)

At the moment I am writing tests for a django application. Basic tests for 
creating get- and post-request with the test server (client) are working.

But now I am facing a file upload request which is triggered by a widget of 
a html page. After reading some settings it calls ajax file upload - 
resulting in a complex request with multiple settings...

Now I'm looking for a way to refer this funcionality mentioned above from a 
django test to get exactly the same request.

Is there a way to do this? (Any hints are welcome... !)

Thanks in advance
Albert.


-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/433bc5ea-ed05-4efa-bd02-96335126b541o%40googlegroups.com.


Django access the Default database (prod/dev) when testing and Fatal Error

2020-08-13 Thread Carlos Leite
Hello everyone, 

I run into a odd situation while trying to run some tests in an old project 
(dj 1.8)
Then I tried the same on a django 3.1 and the problem is still there. 

# models.py  #
class Disco(models.Model):
nome = models.CharField('disco', max_length=50)

class Musica(models.Model):
disco = models.ForeignKey(Disco, on_delete=models.CASCADE)
nome = models.CharField('nome do disco', max_length=50)

# forms.py  #
class MusicForm(forms.Form):
 ''' ... like a search form, I need option from database '''
 disco = forms.ChoiceField(choices=Disco.objects.all())

# tests.py  #
# in the tests.py I just need to import the form to have the odd bahaviour

from django.test import TestCase
from .forms import MusicForm

... I just need to import the `MusicForm` to have the erros 
# the error #
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
   django.db.utils.OperationalError: FATAL:  database "disccollection" does 
not exist

I was trying to run tests, so the database to hit should be  `test_
disccollection`
but not `disccollection` (in my settings.py). 
That may happends because django test framework only changes the 
settings.database.default alias after my form was initialized.

Is it a known bug or a bug at all ? 

I dont kknow not even search for this on django bugs . 

Have anybody seem there before ?

PS: I put a sample code on 
https://github.com/cadu-leite/django18py2testdb/tree/dj33py3test



-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/91dcb131-749c-4065-bd37-e94d62249398n%40googlegroups.com.


Exception During Testing on Windows, Python 3.8

2020-06-11 Thread Matthew Pava
I continue to receive the following exception error at every single one of 
my tests. I'm running Python 3.8.2 on Windows 10.


Exception happened during processing of request from ('127.0.0.1', 54962)
Traceback (most recent call last):
  File "c:\program files\python38\lib\socketserver.py", line 650, in 
process_request_thread
self.finish_request(request, client_address)
  File "c:\program files\python38\lib\socketserver.py", line 360, in 
finish_request
self.RequestHandlerClass(request, client_address, self)
  File "c:\program files\python38\lib\socketserver.py", line 720, in 
__init__
self.handle()
  File 
"C:\...\.virtualenvs\HWohXs6h\lib\site-packages\django\core\servers\basehttp.py"
, line 174, in handle
self.handle_one_request()
  File 
"C:\...\.virtualenvs\HWohXs6h\lib\site-packages\django\core\servers\basehttp.py"
, line 182, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
  File "c:\program files\python38\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
ConnectionAbortedError: [WinError 10053] An established connection was 
aborted by the software in your host machine



I've reviewed a few possible solutions found on the web, but they don't 
seem to help. Besides these exceptions, the tests actually do pass.
Thank you so much!

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f4613b3e-2f69-4d07-acc5-85c6ae2128ado%40googlegroups.com.


Testing an online payment Form using Django Keep getting Not Authenticated Error. Is it because of the Testing Credit Card numbers?

2020-04-27 Thread Ahmed Khairy


I am making a project for an online payment e-commerce

I think I got everything right as am following a Tutorial

Keep getting this Error: Not Authenticated Error I used the testing CC 
Numbers for testing purposes

My question is the following codes correct and I'm getting Not 
Authenticated Error because they are testing Credit Card Numbers.?


class PaymentView(View):
def get(self, *args, **kwargs):
# order
return render(self.request, "payment.html")
# `source` is obtained with Stripe.js; see 
https://stripe.com/docs/payments/accept-a-payment-charges#web-create-token
def post(self, *args, **kwargs):
order = Order.objects.get(user=self.request.user, ordered=False)
token = self.request.POST.get('stripeToken')
amount = int(order.get_total() * 100)

try:
charge = stripe.Charge.create(
amount=amount,  # cents
currency="usd",
source=token,
)
# create payment
payment = Payment()
payment.stripe_charge_id = charge['id']
payment.user = self.request.user
payment.amount = order.get_total()
payment.save()

# assign the payment to the order
order.ordered = True
order.payment = payment
order.save()

messages.success(self.request, "Your Order was Successful ! ")
return redirect("/")

except stripe.error.CardError as e:
body = e.json_body
err = body.get('error', {})
messages.error(self.request, f"{err.get('message')}")
# Since it's a decline, stripe.error.CardError will be caught
return redirect("/")

except stripe.error.RateLimitError as e:
# Too many requests made to the API too quickly
messages.error(self.request, "Rate Limit Error")
return redirect("/")

except stripe.error.InvalidRequestError as e:
# Invalid parameters were supplied to Stripe's API
messages.error(self.request, "Invalid Parameters")
return redirect("/")

except stripe.error.AuthenticationError as e:
# Authentication with Stripe's API failed
# (maybe you changed API keys recently)
messages.error(self.request, "Not Authenticated")
return redirect("/")

except stripe.error.APIConnectionError as e:
# Network communication with Stripe failed
messages.error(self.request, "Network Error")
return redirect("/")

except stripe.error.StripeError as e:
# Display a very generic error to the user, and maybe send
# yourself an email
messages.error(
self.request, "Something went wrong. You were not charged. 
Please Try Again.")
return redirect("/")

except Exception as e:
# Something else happened, completely unrelated to Stripe
# send an email to ourselves
messages.error(
self.request, "A serious Error Occured. We have been notified.")
return redirect("/")

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bba17951-6ca3-4480-9423-e5d39e6ed270%40googlegroups.com.


Re: Django Testing

2020-04-10 Thread Jatin Agrawal
The main reason behind learning about Testing is to check if the views that 
we have written for, are generating the expected results or not. Suppose 
you are writing an APIView to get a list of something, then you should 
write a testcase to check whether that APIView is giving you the result 
that you are expecting or not.

Suppose a company has manufactured a laptop and then they test it to check 
if the new laptop design is working as expected or not. In the same way, if 
you are doing any development work, be it backend development or frontend 
development, you are supposed to and must write test cases to check if the 
feature that you have just developed is giving the expected response or not.


I hope, now, the basic idea of testing is clear to you.

On Tuesday, March 31, 2020 at 8:03:53 PM UTC+5:30, Abrar Ahmad wrote:
>
> Hello Sir 
> I have trouble in learnig Testing tutorial of Djanog Documentation.
> Can any one tell me what is the main concept of learnign test and how can 
> we learn it in easiest way.
> I am waiting for reply
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0ded0bda-b251-4fc3-bff3-dc1a2e147f76%40googlegroups.com.


Re: Django Testing

2020-03-31 Thread Lunga Baliwe
Good day,

I hope this (
https://docs.djangoproject.com/en/3.0/intro/tutorial05/#writing-our-first-test)
can help, its part of the Django tutorials.

On Tue, Mar 31, 2020 at 4:35 PM ekong, emmanuel 
wrote:

> I’m having the same difficulty...
>
> On Tue, 31 Mar 2020 at 3:32 PM, Abrar Ahmad 
> wrote:
>
>> Hello Sir
>> I have trouble in learnig Testing tutorial of Djanog Documentation.
>> Can any one tell me what is the main concept of learnign test and how can
>> we learn it in easiest way.
>> I am waiting for reply
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/6e807ef4-09b6-459d-9d7f-ddb42931c4d9%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/6e807ef4-09b6-459d-9d7f-ddb42931c4d9%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>
> *Disclaimer*
> This e-mail is intended solely for the named recipient. The information
> contained in this message is strictly confidential.
>
>- If you are not the named recipient, you are hereby notified that any
>use, dissemination or reproduction of this document and or its content is
>prohibited and may be deemed unlawful.
>- If you are not the named recipient of this e-mail, please notify the
>sender by a return e-mail and delete all copies of it from your computer
>and mail.
>
> Any views expressed in this e-mail are those of the individual sender,
> except where the sender specifically states them to be those of Landmark
> University <http://lmu.edu.ng>, to whom no liability shall be attached
> whatsoever.
>
> Thank you
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAAP9wcyqaBJLLdc86wkSOtiNoCUDuQVHOh7mpPtCnCmRAbtRxw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAAP9wcyqaBJLLdc86wkSOtiNoCUDuQVHOh7mpPtCnCmRAbtRxw%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANDnEWfZuDeX7_0tvSdVY3-gWxdhinwyMGYQE3_ftri7e3OmjA%40mail.gmail.com.


Re: Django Testing

2020-03-31 Thread ekong, emmanuel
I’m having the same difficulty...

On Tue, 31 Mar 2020 at 3:32 PM, Abrar Ahmad 
wrote:

> Hello Sir
> I have trouble in learnig Testing tutorial of Djanog Documentation.
> Can any one tell me what is the main concept of learnign test and how can
> we learn it in easiest way.
> I am waiting for reply
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/6e807ef4-09b6-459d-9d7f-ddb42931c4d9%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/6e807ef4-09b6-459d-9d7f-ddb42931c4d9%40googlegroups.com?utm_medium=email_source=footer>
> .
>

-- 
**Disclaimer**
This e-mail is intended solely for the named recipient. The 
information contained in this message is strictly confidential. 


  * If 
you are not the named recipient, you are hereby notified that any use, 
dissemination or reproduction of this document and or its content is 
prohibited and may be deemed unlawful.
  * If you are not the named 
recipient of this e-mail, please notify the sender by a return e-mail and 
delete all copies of it from your computer and mail.Any views expressed in 
this e-mail are those of the individual sender, except where the sender 
specifically states them to be those of Landmark University 
<http://lmu.edu.ng>, to whom no liability shall be attached whatsoever.


Thank you

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAP9wcyqaBJLLdc86wkSOtiNoCUDuQVHOh7mpPtCnCmRAbtRxw%40mail.gmail.com.


Django Testing

2020-03-31 Thread Abrar Ahmad
Hello Sir 
I have trouble in learnig Testing tutorial of Djanog Documentation.
Can any one tell me what is the main concept of learnign test and how can 
we learn it in easiest way.
I am waiting for reply

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6e807ef4-09b6-459d-9d7f-ddb42931c4d9%40googlegroups.com.


Re: Testing my Django App

2020-03-23 Thread Motaz Hejaze
Delete the sqlite database and migrate again to remake it

On Mon, 23 Mar 2020, 7:56 pm victor awakan,  wrote:

> Check your book.user_id. It shouldn’t be null. That’s what the last error
> is saying.
>
> On Mon 23. Mar 2020 at 17.44, Ejike Enyinnaya 
> wrote:
>
>> Good day All,
>>
>> I am currently running a test for my Django app call 'Books'.
>>
>> Anytime I run an INDEX test, I get the following error below:
>>
>> "File
>> "/Users/macbookpro/.local/share/virtualenvs/first_django_app-mymO4nCn/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py",
>> line 396, in execute
>> return Database.Cursor.execute(self, query, params)
>> django.db.utils.IntegrityError: NOT NULL constraint failed:
>> books_book.user_id"
>>
>> Please can anyone point to what the issue is or what I am doing wrong.
>>
>> Thanks and Regards,
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/6de24eab-953f-49b9-9dc4-7aa65dc9e229%40googlegroups.com
>> 
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAAipwd_qa%3DVbB0XLQ%3D-93XrqWV%3D6OY9%2BKNWUTD5HJ2yRfac24w%40mail.gmail.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHV4E-dKnqSzAJnxmtSPFJPQNQ7bVgPQC%2Bv9xiN2ZTOzV2VCaA%40mail.gmail.com.


Re: Testing my Django App

2020-03-23 Thread victor awakan
Check your book.user_id. It shouldn’t be null. That’s what the last error
is saying.

On Mon 23. Mar 2020 at 17.44, Ejike Enyinnaya 
wrote:

> Good day All,
>
> I am currently running a test for my Django app call 'Books'.
>
> Anytime I run an INDEX test, I get the following error below:
>
> "File
> "/Users/macbookpro/.local/share/virtualenvs/first_django_app-mymO4nCn/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py",
> line 396, in execute
> return Database.Cursor.execute(self, query, params)
> django.db.utils.IntegrityError: NOT NULL constraint failed:
> books_book.user_id"
>
> Please can anyone point to what the issue is or what I am doing wrong.
>
> Thanks and Regards,
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/6de24eab-953f-49b9-9dc4-7aa65dc9e229%40googlegroups.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAipwd_qa%3DVbB0XLQ%3D-93XrqWV%3D6OY9%2BKNWUTD5HJ2yRfac24w%40mail.gmail.com.


Testing my Django App

2020-03-23 Thread Ejike Enyinnaya
Good day All,

I am currently running a test for my Django app call 'Books'.

Anytime I run an INDEX test, I get the following error below:

"File 
"/Users/macbookpro/.local/share/virtualenvs/first_django_app-mymO4nCn/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py",
 
line 396, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: NOT NULL constraint failed: 
books_book.user_id"

Please can anyone point to what the issue is or what I am doing wrong. 

Thanks and Regards,

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6de24eab-953f-49b9-9dc4-7aa65dc9e229%40googlegroups.com.


Re: Unit Testing POST request

2020-02-13 Thread onlinejudge95
On Thu, Feb 13, 2020 at 8:14 PM sachinbg sachin 
wrote:

> Fistly for setup create use instance for setup user credentials then call
> that the reverse url in that post put delite
>

I have already created my test users in the *setUpClass()* method. As
mentioned my problem was not something related to URL dispatching but more
on how to prepare a POST request with the proper payload. I looked into the
documentation and RequestFactory is exactly what i was looking for.


> On Thu, Feb 13, 2020, 8:01 PM Adam Mičuda  wrote:
>
>> Hi,
>> or you can extract the business logic from view to some service and unit
>> test it instead. =)
>>
>> Regards.
>>
>> Adam
>>
>> st 12. 2. 2020 v 21:15 odesílatel onlinejudge95 
>> napsal:
>>
>>> On Wed, Feb 12, 2020 at 6:22 PM onlinejudge95 
>>> wrote:
>>>
>>>> Hi Devs,
>>>>
>>>> I was implementing unit-tests in my Django project and stumbled upon
>>>> the following issue.
>>>>
>>>> I want to unit-test my POST route. I do not want to use the test client
>>>> already shipped with Django (using it in my e2e tests). I want to know how
>>>> do I prepare my request object to pass to my view. Here is what I have done
>>>> currently.
>>>>
>>>> test_views.py
>>>>
>>>>> class CreateBlogTest(BaseViewTest):
>>>>
>>>> @classmethod
>>>>> def setUpClass(cls):
>>>>> cls.request.method = "POST"
>>>>
>>>> def test_create_valid_blog(self):
>>>>> self.request.content_type = "application/json"
>>>>> self.request._body = json.dumps({"title": "new title", "body":
>>>>> "new body"})
>>>>>
>>>>> response = views.blog_collection(self.request)
>>>>> self.assertEqual(response.status_code, 201)
>>>>>
>>>>
>>>> In my view, I am accessing the data through *request.data* and passing
>>>> it to a serializer.
>>>>
>>>> In my current setting, I am getting a 400 error message when I have
>>>> checked that the user does not exist.
>>>>
>>>> Any suggestions regarding the same?
>>>>
>>>> Thanks,
>>>> onlinejudge95
>>>>
>>>
>>> In case if someone needs it in the future, go and look at
>>> *django.test.RequestFactory *
>>>
>>> https://docs.djangoproject.com/en/3.0/topics/testing/advanced/#django.test.RequestFactory
>>>
>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%40mail.gmail.com?utm_medium=email_source=footer>
>>> .
>>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAB9%3DGXaU4QvmV%3D9fMCcm-NaRUogFtq2Fwd-3MFB5q6QOCxgRhQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAB9%3DGXaU4QvmV%3D9fMCcm-NaRUogFtq2Fwd-3MFB5q6QOCxgRhQ%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAOs61rxaSRrE239aZrbBpZSo7QBoZx2BKxx4nBiERhio0RGSJg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAOs61rxaSRrE239aZrbBpZSo7QBoZx2BKxx4nBiERhio0RGSJg%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eTyjickDTJVCMgHOGWVpXrTdS%2BRsyiJOtJSBpfWPrb44g%40mail.gmail.com.


Re: Unit Testing POST request

2020-02-13 Thread onlinejudge95
On Thu, Feb 13, 2020 at 8:02 PM Adam Mičuda  wrote:

> Hi,
> or you can extract the business logic from view to some service and unit
> test it instead. =)
>

I am following the same, it's just that I am also performing serialization
as of now in my views, since I want to push it out first, and have
documented the refactor I would be performing. My question was on how to
prepare a post request with proper payload, while i was running this test
my response object was an empty dictionary.

>
> Regards.
>
> Adam
>
> st 12. 2. 2020 v 21:15 odesílatel onlinejudge95 
> napsal:
>
>> On Wed, Feb 12, 2020 at 6:22 PM onlinejudge95 
>> wrote:
>>
>>> Hi Devs,
>>>
>>> I was implementing unit-tests in my Django project and stumbled upon the
>>> following issue.
>>>
>>> I want to unit-test my POST route. I do not want to use the test client
>>> already shipped with Django (using it in my e2e tests). I want to know how
>>> do I prepare my request object to pass to my view. Here is what I have done
>>> currently.
>>>
>>> test_views.py
>>>
>>>> class CreateBlogTest(BaseViewTest):
>>>
>>> @classmethod
>>>> def setUpClass(cls):
>>>> cls.request.method = "POST"
>>>
>>> def test_create_valid_blog(self):
>>>> self.request.content_type = "application/json"
>>>> self.request._body = json.dumps({"title": "new title", "body":
>>>> "new body"})
>>>>
>>>> response = views.blog_collection(self.request)
>>>> self.assertEqual(response.status_code, 201)
>>>>
>>>
>>> In my view, I am accessing the data through *request.data* and passing
>>> it to a serializer.
>>>
>>> In my current setting, I am getting a 400 error message when I have
>>> checked that the user does not exist.
>>>
>>> Any suggestions regarding the same?
>>>
>>> Thanks,
>>> onlinejudge95
>>>
>>
>> In case if someone needs it in the future, go and look at
>> *django.test.RequestFactory *
>>
>> https://docs.djangoproject.com/en/3.0/topics/testing/advanced/#django.test.RequestFactory
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAB9%3DGXaU4QvmV%3D9fMCcm-NaRUogFtq2Fwd-3MFB5q6QOCxgRhQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAB9%3DGXaU4QvmV%3D9fMCcm-NaRUogFtq2Fwd-3MFB5q6QOCxgRhQ%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eTWpMRcZ%2BG_zRf%2B9hB2Xds3SKB%3Dm6PT5C60cCDvGUa5EA%40mail.gmail.com.


Re: Unit Testing POST request

2020-02-13 Thread sachinbg sachin
Fistly for setup create use instance for setup user credentials then call
that the reverse url in that post put delite

On Thu, Feb 13, 2020, 8:01 PM Adam Mičuda  wrote:

> Hi,
> or you can extract the business logic from view to some service and unit
> test it instead. =)
>
> Regards.
>
> Adam
>
> st 12. 2. 2020 v 21:15 odesílatel onlinejudge95 
> napsal:
>
>> On Wed, Feb 12, 2020 at 6:22 PM onlinejudge95 
>> wrote:
>>
>>> Hi Devs,
>>>
>>> I was implementing unit-tests in my Django project and stumbled upon the
>>> following issue.
>>>
>>> I want to unit-test my POST route. I do not want to use the test client
>>> already shipped with Django (using it in my e2e tests). I want to know how
>>> do I prepare my request object to pass to my view. Here is what I have done
>>> currently.
>>>
>>> test_views.py
>>>
>>>> class CreateBlogTest(BaseViewTest):
>>>
>>> @classmethod
>>>> def setUpClass(cls):
>>>> cls.request.method = "POST"
>>>
>>> def test_create_valid_blog(self):
>>>> self.request.content_type = "application/json"
>>>> self.request._body = json.dumps({"title": "new title", "body":
>>>> "new body"})
>>>>
>>>> response = views.blog_collection(self.request)
>>>> self.assertEqual(response.status_code, 201)
>>>>
>>>
>>> In my view, I am accessing the data through *request.data* and passing
>>> it to a serializer.
>>>
>>> In my current setting, I am getting a 400 error message when I have
>>> checked that the user does not exist.
>>>
>>> Any suggestions regarding the same?
>>>
>>> Thanks,
>>> onlinejudge95
>>>
>>
>> In case if someone needs it in the future, go and look at
>> *django.test.RequestFactory *
>>
>> https://docs.djangoproject.com/en/3.0/topics/testing/advanced/#django.test.RequestFactory
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAB9%3DGXaU4QvmV%3D9fMCcm-NaRUogFtq2Fwd-3MFB5q6QOCxgRhQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAB9%3DGXaU4QvmV%3D9fMCcm-NaRUogFtq2Fwd-3MFB5q6QOCxgRhQ%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOs61rxaSRrE239aZrbBpZSo7QBoZx2BKxx4nBiERhio0RGSJg%40mail.gmail.com.


Re: Unit Testing POST request

2020-02-13 Thread Adam Mičuda
Hi,
or you can extract the business logic from view to some service and unit
test it instead. =)

Regards.

Adam

st 12. 2. 2020 v 21:15 odesílatel onlinejudge95 
napsal:

> On Wed, Feb 12, 2020 at 6:22 PM onlinejudge95 
> wrote:
>
>> Hi Devs,
>>
>> I was implementing unit-tests in my Django project and stumbled upon the
>> following issue.
>>
>> I want to unit-test my POST route. I do not want to use the test client
>> already shipped with Django (using it in my e2e tests). I want to know how
>> do I prepare my request object to pass to my view. Here is what I have done
>> currently.
>>
>> test_views.py
>>
>>> class CreateBlogTest(BaseViewTest):
>>
>> @classmethod
>>> def setUpClass(cls):
>>> cls.request.method = "POST"
>>
>> def test_create_valid_blog(self):
>>> self.request.content_type = "application/json"
>>> self.request._body = json.dumps({"title": "new title", "body":
>>> "new body"})
>>>
>>> response = views.blog_collection(self.request)
>>> self.assertEqual(response.status_code, 201)
>>>
>>
>> In my view, I am accessing the data through *request.data* and passing
>> it to a serializer.
>>
>> In my current setting, I am getting a 400 error message when I have
>> checked that the user does not exist.
>>
>> Any suggestions regarding the same?
>>
>> Thanks,
>> onlinejudge95
>>
>
> In case if someone needs it in the future, go and look at
> *django.test.RequestFactory *
>
> https://docs.djangoproject.com/en/3.0/topics/testing/advanced/#django.test.RequestFactory
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB9%3DGXaU4QvmV%3D9fMCcm-NaRUogFtq2Fwd-3MFB5q6QOCxgRhQ%40mail.gmail.com.


Re: Unit Testing POST request

2020-02-12 Thread onlinejudge95
On Wed, Feb 12, 2020 at 6:22 PM onlinejudge95 
wrote:

> Hi Devs,
>
> I was implementing unit-tests in my Django project and stumbled upon the
> following issue.
>
> I want to unit-test my POST route. I do not want to use the test client
> already shipped with Django (using it in my e2e tests). I want to know how
> do I prepare my request object to pass to my view. Here is what I have done
> currently.
>
> test_views.py
>
>> class CreateBlogTest(BaseViewTest):
>
> @classmethod
>> def setUpClass(cls):
>> cls.request.method = "POST"
>
> def test_create_valid_blog(self):
>> self.request.content_type = "application/json"
>> self.request._body = json.dumps({"title": "new title", "body":
>> "new body"})
>>
>> response = views.blog_collection(self.request)
>> self.assertEqual(response.status_code, 201)
>>
>
> In my view, I am accessing the data through *request.data* and passing it
> to a serializer.
>
> In my current setting, I am getting a 400 error message when I have
> checked that the user does not exist.
>
> Any suggestions regarding the same?
>
> Thanks,
> onlinejudge95
>

In case if someone needs it in the future, go and look at
*django.test.RequestFactory *
https://docs.djangoproject.com/en/3.0/topics/testing/advanced/#django.test.RequestFactory

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%40mail.gmail.com.


Re: Unit Testing POST request

2020-02-12 Thread onlinejudge95
Hi Guys,

Any leads would be appreciated


On Wed, Feb 12, 2020 at 6:22 PM onlinejudge95 
wrote:

> Hi Devs,
>
> I was implementing unit-tests in my Django project and stumbled upon the
> following issue.
>
> I want to unit-test my POST route. I do not want to use the test client
> already shipped with Django (using it in my e2e tests). I want to know how
> do I prepare my request object to pass to my view. Here is what I have done
> currently.
>
> test_views.py
>
>> class CreateBlogTest(BaseViewTest):
>
> @classmethod
>> def setUpClass(cls):
>> cls.request.method = "POST"
>
> def test_create_valid_blog(self):
>> self.request.content_type = "application/json"
>> self.request._body = json.dumps({"title": "new title", "body":
>> "new body"})
>>
>> response = views.blog_collection(self.request)
>> self.assertEqual(response.status_code, 201)
>>
>
> In my view, I am accessing the data through *request.data* and passing it
> to a serializer.
>
> In my current setting, I am getting a 400 error message when I have
> checked that the user does not exist.
>
> Any suggestions regarding the same?
>
> Thanks,
> onlinejudge95
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eS3nFRxHm_aSqSt8YxFhaZGahF%3DP6Uj0Zco7wafM1%2BHOQ%40mail.gmail.com.


Unit Testing POST request

2020-02-12 Thread onlinejudge95
Hi Devs,

I was implementing unit-tests in my Django project and stumbled upon the
following issue.

I want to unit-test my POST route. I do not want to use the test client
already shipped with Django (using it in my e2e tests). I want to know how
do I prepare my request object to pass to my view. Here is what I have done
currently.

test_views.py

> class CreateBlogTest(BaseViewTest):

@classmethod
> def setUpClass(cls):
> cls.request.method = "POST"

def test_create_valid_blog(self):
> self.request.content_type = "application/json"
> self.request._body = json.dumps({"title": "new title", "body":
> "new body"})
>
> response = views.blog_collection(self.request)
> self.assertEqual(response.status_code, 201)
>

In my view, I am accessing the data through *request.data* and passing it
to a serializer.

In my current setting, I am getting a 400 error message when I have checked
that the user does not exist.

Any suggestions regarding the same?

Thanks,
onlinejudge95

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD%3DM5eSYo5vSZc8SNGnCET-A10%2B%2Bz6q9j0vqy85TU6r0tE957A%40mail.gmail.com.


Django does not Override Settings in Template Tag Testing

2019-12-11 Thread Eray Erdin
I have actually provided quite much verbose information in Stackoverflow 
<https://stackoverflow.com/questions/59251954/django-does-not-override-settings-in-template-tag-testing>.
 
I have a problem overriding settings as testing template tags. I leave this 
here in case you are interested.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8fa4ce5c-cdd1-4c1c-a00d-97554cf86633%40googlegroups.com.


Reading the timeout value for a django cache entry (for testing)

2019-11-11 Thread guettli
We had a bug in our production system. The timeout was set incorrectly.

Now I want to write a test which checks, that the value of the timeout is 
correct.

I look at the docs and don't see a way to **read** the timeout value of a 
particular cache-key:


https://docs.djangoproject.com/en/2.2/topics/cache/


How could I test that the timeout value in my test is correct?

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c6b55205-8a3b-40d3-9b59-ddd19a2c14b8%40googlegroups.com.


Testing the validity of a form which has inline formsets from a View subclass

2019-09-03 Thread Shaheed Haque
Hi all,

I have a set of views in a superclass/subclass hierarchy like this:

   - mobile_view is a subclass of
   - generic___view is a subclass of
   - django-extra-views formset support view

As expected, the django-extra-views formset support's "post()" logic does a
"if form.is_valid() then form.save(commit=False)", and then proceeds to
save the contents of the formsets after testing them with formset
"is_valid" logic, before returning an HttpResponse. AFAICS, no exceptions
are raised to signal the error.

Let's say I now want to do some additional work in generic_object_view,
based on whether the superclass had an error or not:

   - I could construct the form again, and the formsets again, and
   basically redo what the superclass did
   - And of course, it would need redoing again one layer up in
   "mobile_view".

Or have I missed something I can test in the view itself (i.e.
self.) or the return HTTPResponse?

Thanks, Shaheed

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHAc2jd842he83j77xP4phU4-CfyiqvNWhQ3T2wd2yWoGFuNJA%40mail.gmail.com.


Re: Using plus sign in email adresses for testing purposes

2019-07-14 Thread Benjamin Boy
As I said it's for testing purposes. You can have a mailbox t...@google.com, 
emails to tes...@google.com are also routed to the t...@google.com mailbox.

-- 
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+unsubscr...@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/af7c6d60-5e55-4921-a63d-9b1d8a401378%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using plus sign in email adresses for testing purposes

2019-07-14 Thread Charlotte Wood
why are you doing this?  is the e-mail address really test+z or are you
adding the plus sign for some specific reason?


Charlotte Wood, MEd

Educator

(405) 578-5701

Zoom Meeting ID#: 4055785701

*Zoom URL:* https://epiccharterschools.zoom.us/j/2970513912

Classroom Google Site:
https://sites.google.com/epiccharterschools.org/charlottewoodclassroom/home

Epic Technical Support: (405) 652-0935



Jordan McKesson Principal

405-749-4550 ext. 309

jordan.mckes...@epiccharterschools.org

<http://facebook.com/epiccharterschools> <https://twitter.com/epiccharter>
<https://www.instagram.com/epiccharterschools/>
<https://www.youtube.com/user/EpicCharterSchools>




On Sun, Jul 14, 2019 at 6:31 AM Benjamin Boy 
wrote:

> Im currently developping a small app. For testing purposes i want to send
> emails to google with a plus sign in the email adress.
> The smtp backend sends the mail but i never leaves the server.
> What i tried:
> "
> from django.core.mail import EmailMessage
> email = EmailMessage('Subject', 'Body', to=['t...@googlemail.com'])
> email.send()
> "
> Works as supposed.
>
> "
> from django.core.mail import EmailMessage
> email = EmailMessage('Subject', 'Body', to=['tes...@googlemail.com'])
> email.send()
> "
> Does not work, but smtp backend reacts with status code 1, email never
> reach the mailbox
>
> Anyone knows this issue, bug?
>
> B.R.
> Benjamin Boy
>
> --
> 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+unsubscr...@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/955b1e20-9d24-45f5-8fae-3b550d59a6c6%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/955b1e20-9d24-45f5-8fae-3b550d59a6c6%40googlegroups.com?utm_medium=email_source=footer>
> .
> 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+unsubscr...@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/CAPZR0N7%3DBxVrP6tVFRwbZBgN%2BTzW2EL6k0CMwo_fkMuQMSShDg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Using plus sign in email adresses for testing purposes

2019-07-14 Thread Benjamin Boy
Im currently developping a small app. For testing purposes i want to send 
emails to google with a plus sign in the email adress. 
The smtp backend sends the mail but i never leaves the server.
What i tried:
"
from django.core.mail import EmailMessage
email = EmailMessage('Subject', 'Body', to=['t...@googlemail.com'])
email.send()
"
Works as supposed.

"
from django.core.mail import EmailMessage
email = EmailMessage('Subject', 'Body', to=['tes...@googlemail.com'])
email.send()
"
Does not work, but smtp backend reacts with status code 1, email never 
reach the mailbox

Anyone knows this issue, bug?

B.R.
Benjamin Boy

-- 
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+unsubscr...@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/955b1e20-9d24-45f5-8fae-3b550d59a6c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Different types of testing

2019-07-13 Thread Scot Hacker
On Friday, July 12, 2019 at 5:33:38 AM UTC-7, Chandrashekhar Singh wrote:
>
> Hello Developers,
> I am curious to know  what are testing methods do we use in django. Does 
> any has good examples or codes except django documentation.?
> thanks
>

 I don't have numbers, but subjectively, it feels like most modern Django 
projects use pytest with pytest-django, while older projects use the native 
unittest module.

./s

-- 
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+unsubscr...@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/131b6ca1-d526-46c3-a2b1-343b3525ec72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Different types of testing

2019-07-12 Thread Chandrashekhar Singh
Hello Developers,
I am curious to know  what are testing methods do we use in django. Does 
any has good examples or codes except django documentation.?
thanks

-- 
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+unsubscr...@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/f4f3eaa8-d6ec-49aa-bba6-0c7d445e77cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing - get_object_or_404 returns 200 status code

2019-06-10 Thread Cristhiam Gabriel Fernández
Hi RyuCoder

Should not get_object_or_404 shortcut retry 404 status code?

El lunes, 10 de junio de 2019, 15:29:24 (UTC-5), RyuCoder escribió:
>
> Whats your question?
> I failed to understand that 
>
> On Tue, Jun 11, 2019, 1:45 AM Cristhiam Gabriel Fernández <
> cristh...@gmail.com > wrote:
>
>> Hi Django super heroes
>>
>> I'm making of test cases for my simple Django application. When I test a 
>> view with get_object_or_404 shortcut it returns 200 status code.
>>
>> def my_view(self, request):
>>   obj_id = request.POST.get('id')
>>   obj = get_object_or_404(MyModel, pk=id)
>>   
>>
>>
>> # Test case
>> ...data = {'id': 999}
>>  response = self.client.post(reverse('view.name'), data=data)
>>  self.assertEqual(response.status_code, 404)
>>
>>
>> I'm getting *AssertionError: 200 != 404*
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/488aa077-1b11-4404-8d4e-0dad1885707b%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+unsubscr...@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/c6605bef-45e0-431f-8861-f4b3e38f8856%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing - get_object_or_404 returns 200 status code

2019-06-10 Thread Chetan Ganji
Whats your question?
I failed to understand that 

On Tue, Jun 11, 2019, 1:45 AM Cristhiam Gabriel Fernández <
cristhiang...@gmail.com> wrote:

> Hi Django super heroes
>
> I'm making of test cases for my simple Django application. When I test a
> view with get_object_or_404 shortcut it returns 200 status code.
>
> def my_view(self, request):
>   obj_id = request.POST.get('id')
>   obj = get_object_or_404(MyModel, pk=id)
>   
>
>
> # Test case
> ...data = {'id': 999}
>  response = self.client.post(reverse('view.name'), data=data)
>  self.assertEqual(response.status_code, 404)
>
>
> I'm getting *AssertionError: 200 != 404*
>
> --
> 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+unsubscr...@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/488aa077-1b11-4404-8d4e-0dad1885707b%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+unsubscr...@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/CAMKMUjsTgjvtxO84VRLwz6sAc6YSXVMguQGXRHPjoehMYD8W-g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Testing - get_object_or_404 returns 200 status code

2019-06-10 Thread Cristhiam Gabriel Fernández
Hi Django super heroes

I'm making of test cases for my simple Django application. When I test a 
view with get_object_or_404 shortcut it returns 200 status code.

def my_view(self, request):
  obj_id = request.POST.get('id')
  obj = get_object_or_404(MyModel, pk=id)
  


# Test case
...data = {'id': 999}
 response = self.client.post(reverse('view.name'), data=data)
 self.assertEqual(response.status_code, 404)


I'm getting *AssertionError: 200 != 404*

-- 
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+unsubscr...@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/488aa077-1b11-4404-8d4e-0dad1885707b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


testing automl vision

2019-04-23 Thread jc jeth
im getting an error when running the python predict.py scripts.

it returns "google.api_core.exceptions.ServiceUnavailable: 503 Deadline 
Exceeded"

-- 
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+unsubscr...@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/adbc1895-d6ba-47bd-a008-4ee34564c61e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: testing API

2019-04-22 Thread Jani Tiainen
Hi,

DRF does have built-in API viewer. To enable that you need to add
rest_framework app in your INSTALLED_APPS so it can find necessary
templates for showing.

On Tue, Apr 23, 2019 at 7:15 AM Shubham Joshi  wrote:

> I have created the custom model authentication in django rest , so far I
> dont have front end , so my question is , Im I done with the API, since on
> browser it gives an error TemplateDoesNotExist at /
> rest_framework/api.html that of course due to I dont have template, in
> postmen its giving {
> "detail": "Method \"GET\" not allowed."
> } , Am I going right?
>
> https://github.com/shubham1507/school
> 
>
> --
> 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+unsubscr...@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/5596723f-0358-41b5-9b0f-cf0f9dc84057%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Jani Tiainen
Software wizard

https://blog.jani.tiainen.cc/

Always open for short term jobs or contracts to work with Django.

-- 
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+unsubscr...@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/CAHn91ocacYW95Gq%3DwH9DrWZMFjN9mWu_xEssBo%2BePh_VhbHStQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


testing API

2019-04-22 Thread Shubham Joshi
I have created the custom model authentication in django rest , so far I 
dont have front end , so my question is , Im I done with the API, since on 
browser it gives an error TemplateDoesNotExist at /
rest_framework/api.html that of course due to I dont have template, in 
postmen its giving {
"detail": "Method \"GET\" not allowed."
} , Am I going right?

https://github.com/shubham1507/school 


-- 
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+unsubscr...@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/5596723f-0358-41b5-9b0f-cf0f9dc84057%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unit-Testing Django Views

2019-03-30 Thread Jorge Gimeno
The online version of the book is pinned to Django 1.11. You may want to
check that out.

-Jorge

On Sat, Mar 30, 2019 at 4:40 AM Test Bot  wrote:

> Sorry for the bother but I finally solved it by using Django's Test Client
> and checking for status_code and template used to render the response in my
> unit-test.
>
> Regards,
> Test Bot
>
> On Sat, Mar 30, 2019 at 5:00 PM Test Bot  wrote:
>
>> I tried removing the {% csrf_token %} from my index.html But it seemed to
>> have no effect. I got the following traceback for further clarity
>>
>> *
>>   START OF TRACEBACK*
>>
>> ===
>> python superlists/manage.py test
>> Creating test database for alias 'default'...
>> System check identified no issues (0 silenced).
>> .F.
>> Destroying test database for alias 'default'...
>> ==
>> FAIL: test_index_view_returns_correct_html (lists.tests.HomePageTest)
>> --
>> Traceback (most recent call last):
>>   File "superlists/lists/tests.py", line 25, in
>> test_index_view_returns_correct_html
>> self.assertEqual(expected_html, actual_html)
>> AssertionError: '> chars]lue="UUl2QtIopzqg9Co4uPlTlSuEPP2O44aMhda056gd4[201 chars]l>\n' !=
>> '> chars]l>\n'
>>
>> --
>> Ran 3 tests in 0.005s
>>
>> FAILED (failures=1)
>>
>> Process finished with exit code 1
>>
>> ===
>> *
>>END OF TRACEBACK*
>>
>>
>> On Fri, Mar 29, 2019 at 12:58 AM Aldian Fazrihady 
>> wrote:
>>
>>> There are several things you can try:
>>> 1. Mocking csrf token functions
>>> 2. Passing the csrf token context from first HTML generation to the
>>> second HTML generation
>>> 3. Wiping out the csrf token parts from both HTML before comparing them.
>>>
>>> On Thu, 28 Mar 2019, 23:54 Simon Charette,  wrote:
>>>
>>>> This is effectively failing because of a mechanism added in 1.10 to
>>>> protect
>>>> against BREACH attacks[0] by salting the CSRF token.
>>>>
>>>> I'm not aware of any way to disable this mechanism but testing against
>>>> the
>>>> exact HTML returned from a view seems fragile.
>>>>
>>>> I suggest you use assertContains[1] (with or without html=True) and
>>>> assertTemplateUsed[2] instead.
>>>>
>>>> Cheers,
>>>> Simon
>>>>
>>>> [0] https://docs.djangoproject.com/en/2.1/ref/csrf/#how-it-works
>>>> [1]
>>>> https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertContains
>>>> [2]
>>>> https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertTemplateUsed
>>>>
>>>> Le jeudi 28 mars 2019 12:16:43 UTC-4, OnlineJudge95 a écrit :
>>>>>
>>>>> Hi people,
>>>>>
>>>>> I am following the book Test-Driven Development with Python
>>>>> <https://www.amazon.in/Test-Driven-Development-Python-Selenium-JavaScript/dp/1491958707>
>>>>>  by
>>>>> *Harry J.W. Perceval.* The book is using Django version 1.7 which is
>>>>> outdated as of now so I started with version 2.1.
>>>>>
>>>>> I am trying to unit test my index view. One unit-test that I have
>>>>> written is testing whether the index view returns correct HTML or not by
>>>>> comparing the input received through
>>>>> django.template.loader.render_to_string
>>>>> the unit-test fail with the following traceback
>>>>> python manage.py test
>>>>> Creating test database for alias 'default'...
>>>>> .System check identified no issues (0 silenced).
>>>>> F.
>>>>> ==
>>>>> FAIL: test_index_view_returns_correct_html (lists.tests.IndexViewTest)
>>>>> --
>>>>> Traceb

Re: Unit-Testing Django Views

2019-03-30 Thread Test Bot
Sorry for the bother but I finally solved it by using Django's Test Client
and checking for status_code and template used to render the response in my
unit-test.

Regards,
Test Bot

On Sat, Mar 30, 2019 at 5:00 PM Test Bot  wrote:

> I tried removing the {% csrf_token %} from my index.html But it seemed to
> have no effect. I got the following traceback for further clarity
>
> *
> START OF TRACEBACK*
>
> ===
> python superlists/manage.py test
> Creating test database for alias 'default'...
> System check identified no issues (0 silenced).
> .F.
> Destroying test database for alias 'default'...
> ==
> FAIL: test_index_view_returns_correct_html (lists.tests.HomePageTest)
> --
> Traceback (most recent call last):
>   File "superlists/lists/tests.py", line 25, in
> test_index_view_returns_correct_html
> self.assertEqual(expected_html, actual_html)
> AssertionError: ' chars]lue="UUl2QtIopzqg9Co4uPlTlSuEPP2O44aMhda056gd4[201 chars]l>\n' !=
> ' chars]l>\n'
>
> --
> Ran 3 tests in 0.005s
>
> FAILED (failures=1)
>
> Process finished with exit code 1
>
> ===
> *
>  END OF TRACEBACK*
>
>
> On Fri, Mar 29, 2019 at 12:58 AM Aldian Fazrihady 
> wrote:
>
>> There are several things you can try:
>> 1. Mocking csrf token functions
>> 2. Passing the csrf token context from first HTML generation to the
>> second HTML generation
>> 3. Wiping out the csrf token parts from both HTML before comparing them.
>>
>> On Thu, 28 Mar 2019, 23:54 Simon Charette,  wrote:
>>
>>> This is effectively failing because of a mechanism added in 1.10 to
>>> protect
>>> against BREACH attacks[0] by salting the CSRF token.
>>>
>>> I'm not aware of any way to disable this mechanism but testing against
>>> the
>>> exact HTML returned from a view seems fragile.
>>>
>>> I suggest you use assertContains[1] (with or without html=True) and
>>> assertTemplateUsed[2] instead.
>>>
>>> Cheers,
>>> Simon
>>>
>>> [0] https://docs.djangoproject.com/en/2.1/ref/csrf/#how-it-works
>>> [1]
>>> https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertContains
>>> [2]
>>> https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertTemplateUsed
>>>
>>> Le jeudi 28 mars 2019 12:16:43 UTC-4, OnlineJudge95 a écrit :
>>>>
>>>> Hi people,
>>>>
>>>> I am following the book Test-Driven Development with Python
>>>> <https://www.amazon.in/Test-Driven-Development-Python-Selenium-JavaScript/dp/1491958707>
>>>>  by
>>>> *Harry J.W. Perceval.* The book is using Django version 1.7 which is
>>>> outdated as of now so I started with version 2.1.
>>>>
>>>> I am trying to unit test my index view. One unit-test that I have
>>>> written is testing whether the index view returns correct HTML or not by
>>>> comparing the input received through
>>>> django.template.loader.render_to_string
>>>> the unit-test fail with the following traceback
>>>> python manage.py test
>>>> Creating test database for alias 'default'...
>>>> .System check identified no issues (0 silenced).
>>>> F.
>>>> ==
>>>> FAIL: test_index_view_returns_correct_html (lists.tests.IndexViewTest)
>>>> --
>>>> Traceback (most recent call last):
>>>>   File "tests.py", line 24, in test_index_view_returns_correct_html
>>>> self.assertEqual(expected_html, actual_html)
>>>> AssertionError: '>>> chars]lue="BJMT1b9fxuXOGugp00SDypeTYZxvlmc6KtBSYMDon[198 chars]l>\n' !=
>>>> '>>> chars]l>\n'
>>>>
>>>> --
>>>> Ran 3 tests in 0.006s
>>>>
>>>> FAILED (failures=1)
&

Re: Unit-Testing Django Views

2019-03-30 Thread Test Bot
I tried removing the {% csrf_token %} from my index.html But it seemed to
have no effect. I got the following traceback for further clarity

*
START OF TRACEBACK*
===
python superlists/manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
.F.
Destroying test database for alias 'default'...
==
FAIL: test_index_view_returns_correct_html (lists.tests.HomePageTest)
--
Traceback (most recent call last):
  File "superlists/lists/tests.py", line 25, in
test_index_view_returns_correct_html
self.assertEqual(expected_html, actual_html)
AssertionError: '\n' !=
'\n'

--
Ran 3 tests in 0.005s

FAILED (failures=1)

Process finished with exit code 1
===
*
 END OF TRACEBACK*


On Fri, Mar 29, 2019 at 12:58 AM Aldian Fazrihady  wrote:

> There are several things you can try:
> 1. Mocking csrf token functions
> 2. Passing the csrf token context from first HTML generation to the second
> HTML generation
> 3. Wiping out the csrf token parts from both HTML before comparing them.
>
> On Thu, 28 Mar 2019, 23:54 Simon Charette,  wrote:
>
>> This is effectively failing because of a mechanism added in 1.10 to
>> protect
>> against BREACH attacks[0] by salting the CSRF token.
>>
>> I'm not aware of any way to disable this mechanism but testing against the
>> exact HTML returned from a view seems fragile.
>>
>> I suggest you use assertContains[1] (with or without html=True) and
>> assertTemplateUsed[2] instead.
>>
>> Cheers,
>> Simon
>>
>> [0] https://docs.djangoproject.com/en/2.1/ref/csrf/#how-it-works
>> [1]
>> https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertContains
>> [2]
>> https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertTemplateUsed
>>
>> Le jeudi 28 mars 2019 12:16:43 UTC-4, OnlineJudge95 a écrit :
>>>
>>> Hi people,
>>>
>>> I am following the book Test-Driven Development with Python
>>> <https://www.amazon.in/Test-Driven-Development-Python-Selenium-JavaScript/dp/1491958707>
>>>  by
>>> *Harry J.W. Perceval.* The book is using Django version 1.7 which is
>>> outdated as of now so I started with version 2.1.
>>>
>>> I am trying to unit test my index view. One unit-test that I have
>>> written is testing whether the index view returns correct HTML or not by
>>> comparing the input received through
>>> django.template.loader.render_to_string
>>> the unit-test fail with the following traceback
>>> python manage.py test
>>> Creating test database for alias 'default'...
>>> .System check identified no issues (0 silenced).
>>> F.
>>> ==
>>> FAIL: test_index_view_returns_correct_html (lists.tests.IndexViewTest)
>>> --
>>> Traceback (most recent call last):
>>>   File "tests.py", line 24, in test_index_view_returns_correct_html
>>> self.assertEqual(expected_html, actual_html)
>>> AssertionError: '>> chars]lue="BJMT1b9fxuXOGugp00SDypeTYZxvlmc6KtBSYMDon[198 chars]l>\n' !=
>>> '>> chars]l>\n'
>>>
>>> --
>>> Ran 3 tests in 0.006s
>>>
>>> FAILED (failures=1)
>>> Destroying test database for alias 'default'...
>>>
>>> Process finished with exit code 1
>>>
>>>
>>> It was clear that the csrf token is causing the test to fail. Is there
>>> any way to test it, or should it be tested? I ask this as when I changed my
>>> Django version to 1.7, the tests were passing, even after giving the csrf
>>> token field in the form. I tried going through the changelogs but 1.7 is
>>> far behind (beginner here). Please find the code snippets, directory
>>> structure provided below.
>>>
>>>
>>> *lists/views.py*
>>>
>>>
>>>
>>>
>>>
>>>
>>

Re: Unit-Testing Django Views

2019-03-30 Thread Test Bot
Thanks everyone for the clearance of the problem. I will remove the unit
test's logic to check fir template, it seems a viable test case along with
the status code value.

On Fri, Mar 29, 2019, 2:24 AM Chetan Ganji  wrote:

> There is one more way you could do it
>
>
> class TestIndexPageLoad(TestCase):
>
> def setUp(self):
> self.client = Client()
> self.response = self.client.get('/')
>
> def test_check_response(self):
> self.assertTemplateUsed(self.response, 'index.html')
>
>
>
> Regards,
> Chetan Ganji
> +91-900-483-4183
> ganji.che...@gmail.com
> http://ryucoder.in
>
>
> On Fri, Mar 29, 2019 at 1:56 AM Chetan Ganji 
> wrote:
>
>> I would prefer to just check the status code of the response object.
>> This is what I have done. You have to check if it works for forms with
>> csrf_token or not.
>>
>>
>> class TestReverseUrls(TestCase):
>>
>> def setUp(self):
>> self.client = Client()
>> self.reverseUrls = ['index', 'login', 'register']
>> self.response = {url:self.client.get(reverse(url)) for url in self
>> .reverseUrls}
>>
>> def test_reverse_urls(self):
>> for url in self.reverseUrls:
>> self.assertEqual(self.response[url].status_code, 200)
>>
>>
>>
>> Regards,
>> Chetan Ganji
>> +91-900-483-4183
>> ganji.che...@gmail.com
>> http://ryucoder.in
>>
>>
>> On Fri, Mar 29, 2019 at 12:57 AM Aldian Fazrihady 
>> wrote:
>>
>>> There are several things you can try:
>>> 1. Mocking csrf token functions
>>> 2. Passing the csrf token context from first HTML generation to the
>>> second HTML generation
>>> 3. Wiping out the csrf token parts from both HTML before comparing them.
>>>
>>> On Thu, 28 Mar 2019, 23:54 Simon Charette,  wrote:
>>>
>>>> This is effectively failing because of a mechanism added in 1.10 to
>>>> protect
>>>> against BREACH attacks[0] by salting the CSRF token.
>>>>
>>>> I'm not aware of any way to disable this mechanism but testing against
>>>> the
>>>> exact HTML returned from a view seems fragile.
>>>>
>>>> I suggest you use assertContains[1] (with or without html=True) and
>>>> assertTemplateUsed[2] instead.
>>>>
>>>> Cheers,
>>>> Simon
>>>>
>>>> [0] https://docs.djangoproject.com/en/2.1/ref/csrf/#how-it-works
>>>> [1]
>>>> https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertContains
>>>> [2]
>>>> https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertTemplateUsed
>>>>
>>>> Le jeudi 28 mars 2019 12:16:43 UTC-4, OnlineJudge95 a écrit :
>>>>>
>>>>> Hi people,
>>>>>
>>>>> I am following the book Test-Driven Development with Python
>>>>> <https://www.amazon.in/Test-Driven-Development-Python-Selenium-JavaScript/dp/1491958707>
>>>>>  by
>>>>> *Harry J.W. Perceval.* The book is using Django version 1.7 which is
>>>>> outdated as of now so I started with version 2.1.
>>>>>
>>>>> I am trying to unit test my index view. One unit-test that I have
>>>>> written is testing whether the index view returns correct HTML or not by
>>>>> comparing the input received through
>>>>> django.template.loader.render_to_string
>>>>> the unit-test fail with the following traceback
>>>>> python manage.py test
>>>>> Creating test database for alias 'default'...
>>>>> .System check identified no issues (0 silenced).
>>>>> F.
>>>>> ==
>>>>> FAIL: test_index_view_returns_correct_html (lists.tests.IndexViewTest)
>>>>> --
>>>>> Traceback (most recent call last):
>>>>>   File "tests.py", line 24, in test_index_view_returns_correct_html
>>>>> self.assertEqual(expected_html, actual_html)
>>>>> AssertionError: '>>>> chars]lue="BJMT1b9fxuXOGugp00SDypeTYZxvlmc6KtBSYMDon[198 chars]l>\n' !=
>>>>> '>>>> chars]l>\n'
>>>>>
>>>>> 

Re: Unit-Testing Django Views

2019-03-28 Thread Chetan Ganji
There is one more way you could do it


class TestIndexPageLoad(TestCase):

def setUp(self):
self.client = Client()
self.response = self.client.get('/')

def test_check_response(self):
self.assertTemplateUsed(self.response, 'index.html')



Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Fri, Mar 29, 2019 at 1:56 AM Chetan Ganji  wrote:

> I would prefer to just check the status code of the response object.
> This is what I have done. You have to check if it works for forms with
> csrf_token or not.
>
>
> class TestReverseUrls(TestCase):
>
> def setUp(self):
> self.client = Client()
> self.reverseUrls = ['index', 'login', 'register']
> self.response = {url:self.client.get(reverse(url)) for url in self
> .reverseUrls}
>
> def test_reverse_urls(self):
> for url in self.reverseUrls:
> self.assertEqual(self.response[url].status_code, 200)
>
>
>
> Regards,
> Chetan Ganji
> +91-900-483-4183
> ganji.che...@gmail.com
> http://ryucoder.in
>
>
> On Fri, Mar 29, 2019 at 12:57 AM Aldian Fazrihady 
> wrote:
>
>> There are several things you can try:
>> 1. Mocking csrf token functions
>> 2. Passing the csrf token context from first HTML generation to the
>> second HTML generation
>> 3. Wiping out the csrf token parts from both HTML before comparing them.
>>
>> On Thu, 28 Mar 2019, 23:54 Simon Charette,  wrote:
>>
>>> This is effectively failing because of a mechanism added in 1.10 to
>>> protect
>>> against BREACH attacks[0] by salting the CSRF token.
>>>
>>> I'm not aware of any way to disable this mechanism but testing against
>>> the
>>> exact HTML returned from a view seems fragile.
>>>
>>> I suggest you use assertContains[1] (with or without html=True) and
>>> assertTemplateUsed[2] instead.
>>>
>>> Cheers,
>>> Simon
>>>
>>> [0] https://docs.djangoproject.com/en/2.1/ref/csrf/#how-it-works
>>> [1]
>>> https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertContains
>>> [2]
>>> https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertTemplateUsed
>>>
>>> Le jeudi 28 mars 2019 12:16:43 UTC-4, OnlineJudge95 a écrit :
>>>>
>>>> Hi people,
>>>>
>>>> I am following the book Test-Driven Development with Python
>>>> <https://www.amazon.in/Test-Driven-Development-Python-Selenium-JavaScript/dp/1491958707>
>>>>  by
>>>> *Harry J.W. Perceval.* The book is using Django version 1.7 which is
>>>> outdated as of now so I started with version 2.1.
>>>>
>>>> I am trying to unit test my index view. One unit-test that I have
>>>> written is testing whether the index view returns correct HTML or not by
>>>> comparing the input received through
>>>> django.template.loader.render_to_string
>>>> the unit-test fail with the following traceback
>>>> python manage.py test
>>>> Creating test database for alias 'default'...
>>>> .System check identified no issues (0 silenced).
>>>> F.
>>>> ==
>>>> FAIL: test_index_view_returns_correct_html (lists.tests.IndexViewTest)
>>>> --
>>>> Traceback (most recent call last):
>>>>   File "tests.py", line 24, in test_index_view_returns_correct_html
>>>> self.assertEqual(expected_html, actual_html)
>>>> AssertionError: '>>> chars]lue="BJMT1b9fxuXOGugp00SDypeTYZxvlmc6KtBSYMDon[198 chars]l>\n' !=
>>>> '>>> chars]l>\n'
>>>>
>>>> --
>>>> Ran 3 tests in 0.006s
>>>>
>>>> FAILED (failures=1)
>>>> Destroying test database for alias 'default'...
>>>>
>>>> Process finished with exit code 1
>>>>
>>>>
>>>> It was clear that the csrf token is causing the test to fail. Is there
>>>> any way to test it, or should it be tested? I ask this as when I changed my
>>>> Django version to 1.7, the tests were passing, even after giving the csrf
>>>> token field in the form. I tried going through the changelogs but 1.7 is
>>>> far behind (beginner here). Please find the code snippets, directory
>>>> structure provided below.
>>>>
>>>>

Re: Unit-Testing Django Views

2019-03-28 Thread Chetan Ganji
I would prefer to just check the status code of the response object.
This is what I have done. You have to check if it works for forms with
csrf_token or not.


class TestReverseUrls(TestCase):

def setUp(self):
self.client = Client()
self.reverseUrls = ['index', 'login', 'register']
self.response = {url:self.client.get(reverse(url)) for url in self
.reverseUrls}

def test_reverse_urls(self):
for url in self.reverseUrls:
self.assertEqual(self.response[url].status_code, 200)



Regards,
Chetan Ganji
+91-900-483-4183
ganji.che...@gmail.com
http://ryucoder.in


On Fri, Mar 29, 2019 at 12:57 AM Aldian Fazrihady  wrote:

> There are several things you can try:
> 1. Mocking csrf token functions
> 2. Passing the csrf token context from first HTML generation to the second
> HTML generation
> 3. Wiping out the csrf token parts from both HTML before comparing them.
>
> On Thu, 28 Mar 2019, 23:54 Simon Charette,  wrote:
>
>> This is effectively failing because of a mechanism added in 1.10 to
>> protect
>> against BREACH attacks[0] by salting the CSRF token.
>>
>> I'm not aware of any way to disable this mechanism but testing against the
>> exact HTML returned from a view seems fragile.
>>
>> I suggest you use assertContains[1] (with or without html=True) and
>> assertTemplateUsed[2] instead.
>>
>> Cheers,
>> Simon
>>
>> [0] https://docs.djangoproject.com/en/2.1/ref/csrf/#how-it-works
>> [1]
>> https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertContains
>> [2]
>> https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertTemplateUsed
>>
>> Le jeudi 28 mars 2019 12:16:43 UTC-4, OnlineJudge95 a écrit :
>>>
>>> Hi people,
>>>
>>> I am following the book Test-Driven Development with Python
>>> <https://www.amazon.in/Test-Driven-Development-Python-Selenium-JavaScript/dp/1491958707>
>>>  by
>>> *Harry J.W. Perceval.* The book is using Django version 1.7 which is
>>> outdated as of now so I started with version 2.1.
>>>
>>> I am trying to unit test my index view. One unit-test that I have
>>> written is testing whether the index view returns correct HTML or not by
>>> comparing the input received through
>>> django.template.loader.render_to_string
>>> the unit-test fail with the following traceback
>>> python manage.py test
>>> Creating test database for alias 'default'...
>>> .System check identified no issues (0 silenced).
>>> F.
>>> ==
>>> FAIL: test_index_view_returns_correct_html (lists.tests.IndexViewTest)
>>> --
>>> Traceback (most recent call last):
>>>   File "tests.py", line 24, in test_index_view_returns_correct_html
>>> self.assertEqual(expected_html, actual_html)
>>> AssertionError: '>> chars]lue="BJMT1b9fxuXOGugp00SDypeTYZxvlmc6KtBSYMDon[198 chars]l>\n' !=
>>> '>> chars]l>\n'
>>>
>>> --
>>> Ran 3 tests in 0.006s
>>>
>>> FAILED (failures=1)
>>> Destroying test database for alias 'default'...
>>>
>>> Process finished with exit code 1
>>>
>>>
>>> It was clear that the csrf token is causing the test to fail. Is there
>>> any way to test it, or should it be tested? I ask this as when I changed my
>>> Django version to 1.7, the tests were passing, even after giving the csrf
>>> token field in the form. I tried going through the changelogs but 1.7 is
>>> far behind (beginner here). Please find the code snippets, directory
>>> structure provided below.
>>>
>>>
>>> *lists/views.py*
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> *from django.http import HttpResponsefrom django.shortcuts import render# 
>>> Create your views here.def index(request):if request.method == 'POST':  
>>>   return HttpResponse(request.POST['item_text'])return 
>>> render(request, 'index.html')*
>>>
>>>
>>> *lists/test.py*
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>&

Re: Unit-Testing Django Views

2019-03-28 Thread Aldian Fazrihady
There are several things you can try:
1. Mocking csrf token functions
2. Passing the csrf token context from first HTML generation to the second
HTML generation
3. Wiping out the csrf token parts from both HTML before comparing them.

On Thu, 28 Mar 2019, 23:54 Simon Charette,  wrote:

> This is effectively failing because of a mechanism added in 1.10 to protect
> against BREACH attacks[0] by salting the CSRF token.
>
> I'm not aware of any way to disable this mechanism but testing against the
> exact HTML returned from a view seems fragile.
>
> I suggest you use assertContains[1] (with or without html=True) and
> assertTemplateUsed[2] instead.
>
> Cheers,
> Simon
>
> [0] https://docs.djangoproject.com/en/2.1/ref/csrf/#how-it-works
> [1]
> https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertContains
> [2]
> https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertTemplateUsed
>
> Le jeudi 28 mars 2019 12:16:43 UTC-4, OnlineJudge95 a écrit :
>>
>> Hi people,
>>
>> I am following the book Test-Driven Development with Python
>> <https://www.amazon.in/Test-Driven-Development-Python-Selenium-JavaScript/dp/1491958707>
>>  by
>> *Harry J.W. Perceval.* The book is using Django version 1.7 which is
>> outdated as of now so I started with version 2.1.
>>
>> I am trying to unit test my index view. One unit-test that I have written
>> is testing whether the index view returns correct HTML or not by comparing
>> the input received through
>> django.template.loader.render_to_string
>> the unit-test fail with the following traceback
>> python manage.py test
>> Creating test database for alias 'default'...
>> .System check identified no issues (0 silenced).
>> F.
>> ==
>> FAIL: test_index_view_returns_correct_html (lists.tests.IndexViewTest)
>> --
>> Traceback (most recent call last):
>>   File "tests.py", line 24, in test_index_view_returns_correct_html
>> self.assertEqual(expected_html, actual_html)
>> AssertionError: '> chars]lue="BJMT1b9fxuXOGugp00SDypeTYZxvlmc6KtBSYMDon[198 chars]l>\n' !=
>> '> chars]l>\n'
>>
>> --
>> Ran 3 tests in 0.006s
>>
>> FAILED (failures=1)
>> Destroying test database for alias 'default'...
>>
>> Process finished with exit code 1
>>
>>
>> It was clear that the csrf token is causing the test to fail. Is there
>> any way to test it, or should it be tested? I ask this as when I changed my
>> Django version to 1.7, the tests were passing, even after giving the csrf
>> token field in the form. I tried going through the changelogs but 1.7 is
>> far behind (beginner here). Please find the code snippets, directory
>> structure provided below.
>>
>>
>> *lists/views.py*
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *from django.http import HttpResponsefrom django.shortcuts import render# 
>> Create your views here.def index(request):if request.method == 'POST':   
>>  return HttpResponse(request.POST['item_text'])return 
>> render(request, 'index.html')*
>>
>>
>> *lists/test.py*
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *from django.http import HttpRequestfrom django.template.loader import
>> render_to_stringfrom django.test import TestCasefrom django.urls import
>> resolvefrom lists.views import index# Create your tests here.class
>> IndexViewTest(TestCase):def
>> test_root_url_resolves_to_home_page_view(self):   [...]def
>> test_index_view_returns_correct_html(self):request = HttpRequest()
>>   response = index(request)actual_html =
>> response.content.decode()expected_html =
>> render_to_string('index.html', request=request)
>> self.assertEqual(expected_html, actual_html)def
>> test_index_view_can_save_a_post_request(self):   [...]requirements.txt*
>>
>>
>>
>>
>>
>> *Django==2.1.7pytz==2018.9selenium==3.141.0urllib3==1.24.*
>> *settings.py*
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *[...]# Application definiti

Re: Unit-Testing Django Views

2019-03-28 Thread Simon Charette
This is effectively failing because of a mechanism added in 1.10 to protect
against BREACH attacks[0] by salting the CSRF token.

I'm not aware of any way to disable this mechanism but testing against the
exact HTML returned from a view seems fragile.

I suggest you use assertContains[1] (with or without html=True) and
assertTemplateUsed[2] instead.

Cheers,
Simon

[0] https://docs.djangoproject.com/en/2.1/ref/csrf/#how-it-works
[1] 
https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertContains
[2] 
https://docs.djangoproject.com/en/2.1/topics/testing/tools/#django.test.SimpleTestCase.assertTemplateUsed

Le jeudi 28 mars 2019 12:16:43 UTC-4, OnlineJudge95 a écrit :
>
> Hi people,
>
> I am following the book Test-Driven Development with Python 
> <https://www.amazon.in/Test-Driven-Development-Python-Selenium-JavaScript/dp/1491958707>
>  by 
> *Harry J.W. Perceval.* The book is using Django version 1.7 which is 
> outdated as of now so I started with version 2.1.
>
> I am trying to unit test my index view. One unit-test that I have written 
> is testing whether the index view returns correct HTML or not by comparing 
> the input received through
> django.template.loader.render_to_string
> the unit-test fail with the following traceback
> python manage.py test
> Creating test database for alias 'default'...
> .System check identified no issues (0 silenced).
> F.
> ==
> FAIL: test_index_view_returns_correct_html (lists.tests.IndexViewTest)
> --
> Traceback (most recent call last):
>   File "tests.py", line 24, in test_index_view_returns_correct_html
> self.assertEqual(expected_html, actual_html)
> AssertionError: ' chars]lue="BJMT1b9fxuXOGugp00SDypeTYZxvlmc6KtBSYMDon[198 chars]l>\n' != 
> ' chars]l>\n'
>
> --
> Ran 3 tests in 0.006s
>
> FAILED (failures=1)
> Destroying test database for alias 'default'...
>
> Process finished with exit code 1
>
>
> It was clear that the csrf token is causing the test to fail. Is there any 
> way to test it, or should it be tested? I ask this as when I changed my 
> Django version to 1.7, the tests were passing, even after giving the csrf 
> token field in the form. I tried going through the changelogs but 1.7 is 
> far behind (beginner here). Please find the code snippets, directory 
> structure provided below.
>
>
> *lists/views.py*
>
>
>
>
>
>
>
>
>
>
> *from django.http import HttpResponsefrom django.shortcuts import render# 
> Create your views here.def index(request):if request.method == 'POST':
> return HttpResponse(request.POST['item_text'])return render(request, 
> 'index.html')*
>
>
> *lists/test.py*
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *from django.http import HttpRequestfrom django.template.loader import 
> render_to_stringfrom django.test import TestCasefrom django.urls import 
> resolvefrom lists.views import index# Create your tests here.class 
> IndexViewTest(TestCase):def 
> test_root_url_resolves_to_home_page_view(self):   [...]def 
> test_index_view_returns_correct_html(self):request = HttpRequest()  
>   response = index(request)actual_html = 
> response.content.decode()expected_html = 
> render_to_string('index.html', request=request)
> self.assertEqual(expected_html, actual_html)def 
> test_index_view_can_save_a_post_request(self):   [...]requirements.txt*
>
>
>
>
>
> *Django==2.1.7pytz==2018.9selenium==3.141.0urllib3==1.24.*
> *settings.py*
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *[...]# Application definitionINSTALLED_APPS = [ 'django.contrib.admin', 
> 'django.contrib.auth', 'django.contrib.contenttypes', 
> 'django.contrib.sessions', 'django.contrib.messages', 
> 'django.contrib.staticfiles', 'lists',][...]*
> *Directory Structure*
>
> [image: Screen Shot 2019-03-28 at 9.36.56 PM.png]
>
>

-- 
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+unsubscr...@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/7f0f12be-fc3e-43c3-ba07-e48158def051%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Unit-Testing Django Views

2019-03-28 Thread OnlineJudge95
Hi people,

I am following the book Test-Driven Development with Python 
<https://www.amazon.in/Test-Driven-Development-Python-Selenium-JavaScript/dp/1491958707>
 by 
*Harry J.W. Perceval.* The book is using Django version 1.7 which is 
outdated as of now so I started with version 2.1.

I am trying to unit test my index view. One unit-test that I have written 
is testing whether the index view returns correct HTML or not by comparing 
the input received through
django.template.loader.render_to_string
the unit-test fail with the following traceback
python manage.py test
Creating test database for alias 'default'...
.System check identified no issues (0 silenced).
F.
==
FAIL: test_index_view_returns_correct_html (lists.tests.IndexViewTest)
--
Traceback (most recent call last):
  File "tests.py", line 24, in test_index_view_returns_correct_html
self.assertEqual(expected_html, actual_html)
AssertionError: '\n' != 
'\n'

--
Ran 3 tests in 0.006s

FAILED (failures=1)
Destroying test database for alias 'default'...

Process finished with exit code 1


It was clear that the csrf token is causing the test to fail. Is there any 
way to test it, or should it be tested? I ask this as when I changed my 
Django version to 1.7, the tests were passing, even after giving the csrf 
token field in the form. I tried going through the changelogs but 1.7 is 
far behind (beginner here). Please find the code snippets, directory 
structure provided below.


*lists/views.py*










*from django.http import HttpResponsefrom django.shortcuts import render# 
Create your views here.def index(request):if request.method == 'POST':  
  return HttpResponse(request.POST['item_text'])return render(request, 
'index.html')*


*lists/test.py*


























*from django.http import HttpRequestfrom django.template.loader import 
render_to_stringfrom django.test import TestCasefrom django.urls import 
resolvefrom lists.views import index# Create your tests here.class 
IndexViewTest(TestCase):def 
test_root_url_resolves_to_home_page_view(self):   [...]def 
test_index_view_returns_correct_html(self):request = HttpRequest()  
  response = index(request)actual_html = 
response.content.decode()expected_html = 
render_to_string('index.html', request=request)
self.assertEqual(expected_html, actual_html)def 
test_index_view_can_save_a_post_request(self):   [...]requirements.txt*





*Django==2.1.7pytz==2018.9selenium==3.141.0urllib3==1.24.*
*settings.py*















*[...]# Application definitionINSTALLED_APPS = [ 'django.contrib.admin', 
'django.contrib.auth', 'django.contrib.contenttypes', 
'django.contrib.sessions', 'django.contrib.messages', 
'django.contrib.staticfiles', 'lists',][...]*
*Directory Structure*

[image: Screen Shot 2019-03-28 at 9.36.56 PM.png]

-- 
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+unsubscr...@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/ed387060-93e5-4d0c-a4a6-a5204e6c097f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Preparing for 2.2LTS - testing for Deprecation Warnings

2019-01-17 Thread Dan Davis
I will then try like this in my manage.py:

 if len(sys.argv)>1 and sys.argv[1] = 'test':
  warnings.filterwarnings(...)

Thanks,

-Dan

On Thu, Jan 17, 2019 at 1:08 PM Simon Charette  wrote:

> You can use the category kwarg of filterwarnings[0] to pass the Django
> deprecation
> warning classes.
>
> They can be found in the django.utils.deprecation module. (e.g.
> RemovedInDjango30Warning).
>
> Cheers,
> Simon
>
> [0]
> https://docs.python.org/3/library/warnings.html?highlight=filterwarnings#warnings.filterwarnings
>
> --
> 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/Urrwf66qv6A/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@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/520cea1a-7df7-4060-a8b0-3d361473e7a5%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+unsubscr...@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/CAFzonYaiD7Q0Y%3DppAqw6K22VsFPve%2BuL0Sb%3DOKaYHfR7Vnw58A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Preparing for 2.2LTS - testing for Deprecation Warnings

2019-01-17 Thread Simon Charette
You can use the category kwarg of filterwarnings[0] to pass the Django 
deprecation
warning classes.

They can be found in the django.utils.deprecation module. (e.g. 
RemovedInDjango30Warning).

Cheers,
Simon

[0] 
https://docs.python.org/3/library/warnings.html?highlight=filterwarnings#warnings.filterwarnings

-- 
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+unsubscr...@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/520cea1a-7df7-4060-a8b0-3d361473e7a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Preparing for 2.2LTS - testing for Deprecation Warnings

2019-01-17 Thread Dan Davis
PYTHONWARNINGS=error is too much.

How can I call warnings.filterwarnings() to make all *Django* 
DeprecationWarnings into errors?

-- 
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+unsubscr...@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/8b01f54a-ebf1-4082-b205-b83491d9bab7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with testing on Travis CI

2019-01-16 Thread אורי
Thank you Michal, I was not aware of this issue. I fixed it and committed
again -
https://github.com/speedy-net/speedy-net/commit/6570e00edb9d58c8d855f8b7ea6a8129c774eb33.
Thanks for your help!

Thanks,
אורי (Uri)
u...@speedy.net


On Wed, Jan 16, 2019 at 11:39 AM Michal Petrucha <
michal.petru...@konk.org> wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA512
>
> On Wed, Jan 16, 2019 at 09:11:47AM +0200, אורי wrote:
> > Hi,
> >
> > I recently have problems with testing my project on Travis CI. Tests
> > started to fail 2 days ago. The error message is
> > `psycopg2.OperationalError: FATAL:  database "speedy" does not exist`
> and I
> > don't know why. It seems to me that the first test which fail for this
> > reason is https://travis-ci.org/speedy-net/speedy-net/builds/479248003
> and
> > the commit is
> >
> https://github.com/speedy-net/speedy-net/commit/04c4c891f64c4eee3accc393e59b5d18f0c8bbcc
> ,
> > but I don't know what in this commit causes the tests to fail. When I run
> > the tests locally they run without problems. Do you know why our tests
> fail
> > on Travis CI?
>
> Hi Uri,
>
> The problem is the following line:
>
> https://github.com/speedy-net/speedy-net/commit/04c4c891f64c4eee3accc393e59b5d18f0c8bbcc#diff-c1494957b796412b658b8c2c97136711R6
> That line tries to execute a database query during import, which will
> not work – you don't want to make import-time queries, because those
> will be routed to the production database even when you're running
> tests, and they will also make it impossible for you to run migrations
> in a fresh, empty database.
>
> Good luck,
>
> Michal
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1
>
> iQIcBAEBCgAGBQJcPvvRAAoJEHA7T/IPM/kl4gsP/j2Pyl8YQsUi94saQFnIaEIH
> sxQ28wm4a5vlfAyKxDDNZqcBBwVq0YPkpflEe5DnmFjQdcsanjZgxt+ejwwONmFF
> +kP7gjD1mPmGG4V2XT5MllzI0VR5clZiP7leXgnQq+Xgtb0+xdfQHjZMm8JszhVe
> oWbCgRlBNOXDPhnSS5mu5rh//zbBGaOQHjN6vcmmT+M7OQcjDD4nmsEnz3fY3b5J
> mh3Y/X8h0dzCao0cAul7m8Pynu/xDl5THQS9dI4YIEOrzdQBkjNZMonNr0rK7e5o
> 49MbfHOGRmDNdF53w2AfKe+9FN/I+C9WXR6XQNE2858aveGM0o+hw+P+1RhNUPBF
> /oov5rDu0vmyLDd2ip3lHZ0ki12mkMKYMZQ6Yfit4X1nLaob/6oQ4KkMCzawrIWS
> CekjFC2HQY6SJJRpS0VGjft5qlRvEgO9isn+THoNDIEZDJj1XT07RJldA+6/g1Jy
> POeneUyxa7j1F3gcW86lazCfavLO7LhPnAcWKjntc9j5Xq5/l0TyJcORV6yJFMSu
> Wgh3YrqjIZcOMkX+YiJ0pr5iqkZ3M/hieLALuaM13iYbx1NtL+k34rx76ROz8sw4
> BpAO/oUMJnDS+2yT/G2FmTdhJisznTjsqgwfyDSAdlMSpADjxNj62ykojgCTjhpB
> J6DfyIn1PH3LaTeWK4bi
> =zAwN
> -END PGP SIGNATURE-
>
> --
> 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+unsubscr...@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/20190116093929.GZ8269%40konk.org
> .
> 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+unsubscr...@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/CABD5YeGsY6Fk0DooCVYXbbg9knL4wn7Y2Y%3D2y_Gitm5-sFrbVg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with testing on Travis CI

2019-01-16 Thread Michal Petrucha
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

On Wed, Jan 16, 2019 at 09:11:47AM +0200, אורי wrote:
> Hi,
> 
> I recently have problems with testing my project on Travis CI. Tests
> started to fail 2 days ago. The error message is
> `psycopg2.OperationalError: FATAL:  database "speedy" does not exist` and I
> don't know why. It seems to me that the first test which fail for this
> reason is https://travis-ci.org/speedy-net/speedy-net/builds/479248003 and
> the commit is
> https://github.com/speedy-net/speedy-net/commit/04c4c891f64c4eee3accc393e59b5d18f0c8bbcc,
> but I don't know what in this commit causes the tests to fail. When I run
> the tests locally they run without problems. Do you know why our tests fail
> on Travis CI?

Hi Uri,

The problem is the following line:
https://github.com/speedy-net/speedy-net/commit/04c4c891f64c4eee3accc393e59b5d18f0c8bbcc#diff-c1494957b796412b658b8c2c97136711R6
That line tries to execute a database query during import, which will
not work – you don't want to make import-time queries, because those
will be routed to the production database even when you're running
tests, and they will also make it impossible for you to run migrations
in a fresh, empty database.

Good luck,

Michal
-BEGIN PGP SIGNATURE-
Version: GnuPG v1

iQIcBAEBCgAGBQJcPvvRAAoJEHA7T/IPM/kl4gsP/j2Pyl8YQsUi94saQFnIaEIH
sxQ28wm4a5vlfAyKxDDNZqcBBwVq0YPkpflEe5DnmFjQdcsanjZgxt+ejwwONmFF
+kP7gjD1mPmGG4V2XT5MllzI0VR5clZiP7leXgnQq+Xgtb0+xdfQHjZMm8JszhVe
oWbCgRlBNOXDPhnSS5mu5rh//zbBGaOQHjN6vcmmT+M7OQcjDD4nmsEnz3fY3b5J
mh3Y/X8h0dzCao0cAul7m8Pynu/xDl5THQS9dI4YIEOrzdQBkjNZMonNr0rK7e5o
49MbfHOGRmDNdF53w2AfKe+9FN/I+C9WXR6XQNE2858aveGM0o+hw+P+1RhNUPBF
/oov5rDu0vmyLDd2ip3lHZ0ki12mkMKYMZQ6Yfit4X1nLaob/6oQ4KkMCzawrIWS
CekjFC2HQY6SJJRpS0VGjft5qlRvEgO9isn+THoNDIEZDJj1XT07RJldA+6/g1Jy
POeneUyxa7j1F3gcW86lazCfavLO7LhPnAcWKjntc9j5Xq5/l0TyJcORV6yJFMSu
Wgh3YrqjIZcOMkX+YiJ0pr5iqkZ3M/hieLALuaM13iYbx1NtL+k34rx76ROz8sw4
BpAO/oUMJnDS+2yT/G2FmTdhJisznTjsqgwfyDSAdlMSpADjxNj62ykojgCTjhpB
J6DfyIn1PH3LaTeWK4bi
=zAwN
-END PGP SIGNATURE-

-- 
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+unsubscr...@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/20190116093929.GZ8269%40konk.org.
For more options, visit https://groups.google.com/d/optout.


Problem with testing on Travis CI

2019-01-15 Thread אורי
Hi,

I recently have problems with testing my project on Travis CI. Tests
started to fail 2 days ago. The error message is
`psycopg2.OperationalError: FATAL:  database "speedy" does not exist` and I
don't know why. It seems to me that the first test which fail for this
reason is https://travis-ci.org/speedy-net/speedy-net/builds/479248003 and
the commit is
https://github.com/speedy-net/speedy-net/commit/04c4c891f64c4eee3accc393e59b5d18f0c8bbcc,
but I don't know what in this commit causes the tests to fail. When I run
the tests locally they run without problems. Do you know why our tests fail
on Travis CI?

Thanks,
אורי (Uri)
u...@speedy.net

-- 
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+unsubscr...@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/CABD5YeEKiU-3uefV0RyvG%2Bod15FJaB%3DFgmOdii7c_ZsqihaR_Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django unit testing and pk's changing

2018-10-24 Thread David
The issue was my using incorrect def get_absolute_url's in my model  My 
error.

On Wednesday, 24 October 2018 12:24:07 UTC+1, David wrote:
>
> Hi
>
> When I run tests on my app they run through fine.
>
> When I run tests just using "manage.py test" the app mentioned above 
> contains failures.
>
> Example code:
>
> def test_lumpsum_get_absolute_url(self):
> lumpsum = LumpSum.objects.get()
> self.assertEquals(lumpsum.get_absolute_url(),
>   reverse('estates:lumpsum', kwargs={
>   'case_pk': self.case.pk,
>   'client_pk': self.client.pk,
>   })
>   )
>
>
> Traceback (most recent call last):
>   File "path\test_models.py", line 541, in test_lumpsum_get_absolute_url
> 'client_pk': lumpsum.client.pk,
> AssertionError: '/estates/53/lumpsum/98/' != '/estates/113/lumpsum/98/'
> - /estates/53/lumpsum/98/
> ?  ^
> + /estates/113/lumpsum/98/
> ?  
>
> The case.pk (53 and 113 above) changes, yet the client.pk (98) does not.
>
> I understand that setUp is run for each test, so expect the pk to rise, 
> but I cannot fathom why only one of the PKs is changing.
>
> In setUp:
>
> self.case = Case.objects.create(
> name='example case',
> adviser=self.adviser,
> meeting_date='2018-01-01',
> urgency='N',
> assignment_trust='N',
> expression_wishes='N',
> lifetime_planning='N',
> home_savings='Y',
> marriage_death='N',
> inheritance_tax='Y',
> inheritance_creditors='N',
> inheritance_divorce='Y',
> further_iht='N',
> comment='just another comment',
> )
>
> self.client = Client.objects.create(
> case=self.case,
> prefix='Mr',
> first_name='first name',
> last_name='last name',
> date_of_birth='1900-01-01',
> gender='M',
> residence='EN',
> address_1='10 C',
> city='city',
> postcode='SOL',
> telephone='0211 11',
> marital_status='SI',
> have_will='N',
> existing_poa='N',
> dependant='N',
> share_house='N',
> )
>

-- 
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+unsubscr...@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/f72902ab-9dd3-4cfc-8b05-f9dc090d0a8b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django unit testing and pk's changing

2018-10-24 Thread David
Hi

When I run tests on my app they run through fine.

When I run tests just using "manage.py test" the app mentioned above 
contains failures.

Example code:

def test_lumpsum_get_absolute_url(self):
lumpsum = LumpSum.objects.get()
self.assertEquals(lumpsum.get_absolute_url(),
  reverse('estates:lumpsum', kwargs={
  'case_pk': self.case.pk,
  'client_pk': self.client.pk,
  })
  )


Traceback (most recent call last):
  File "path\test_models.py", line 541, in test_lumpsum_get_absolute_url
'client_pk': lumpsum.client.pk,
AssertionError: '/estates/53/lumpsum/98/' != '/estates/113/lumpsum/98/'
- /estates/53/lumpsum/98/
?  ^
+ /estates/113/lumpsum/98/
?  

The case.pk (53 and 113 above) changes, yet the client.pk (98) does not.

I understand that setUp is run for each test, so expect the pk to rise, but 
I cannot fathom why only one of the PKs is changing.

In setUp:

self.case = Case.objects.create(
name='example case',
adviser=self.adviser,
meeting_date='2018-01-01',
urgency='N',
assignment_trust='N',
expression_wishes='N',
lifetime_planning='N',
home_savings='Y',
marriage_death='N',
inheritance_tax='Y',
inheritance_creditors='N',
inheritance_divorce='Y',
further_iht='N',
comment='just another comment',
)

self.client = Client.objects.create(
case=self.case,
prefix='Mr',
first_name='first name',
last_name='last name',
date_of_birth='1900-01-01',
gender='M',
residence='EN',
address_1='10 C',
city='city',
postcode='SOL',
telephone='0211 11',
marital_status='SI',
have_will='N',
existing_poa='N',
dependant='N',
share_house='N',
)

-- 
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+unsubscr...@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/05ea3e16-0cba-446c-8166-00454ded503e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I patch django.core.mail.send_mail for testing?

2018-08-23 Thread scloutier
I solved the problem by wrapping the imports of the test-file inside a 
context manager, as follow:

with patch('django.core.mail.send_mail') as mocked_send_mail:
from ModuleToTest.File import functionToTest


That forced the patch to occur before the tested function was actualy 
imported.

-- 
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+unsubscr...@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/f4212245-30cb-47e5-9505-5b66cff20064%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Setting up a system for testing by users (tables are tables?)

2018-08-14 Thread guettli


Am Montag, 13. August 2018 18:12:03 UTC+2 schrieb Mikhailo Keda:
>
> 1. take a dump of production db
> 2. remove/anonymize all sensitive or unneeded data (you can use django 
> admin or sql or python script)
> 3. reduce amount of data if needed
> 4. take a git branch with fixes 
> 5. make sure there are no sensitive data in your code
>

Yes, these steps look good.

I don't like thinking. Up to now I need to think if I need to decide if 
data is sensitive or unneeded.

It would be nice if this could be defined somehow. I think per row is not 
useful, but per table looks feasible.

-- 
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+unsubscr...@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/70054b6b-281d-4690-a0f7-2fbd0993c6ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Setting up a system for testing by users (tables are tables?)

2018-08-13 Thread Mikhailo Keda
1. take a dump of production db
2. remove/anonymize all sensitive or unneeded data (you can use django 
admin or sql or python script)
3. reduce amount of data if needed
4. take a git branch with fixes 
5. make sure there are no sensitive data in your code

-- 
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+unsubscr...@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/b48a127f-ac71-47a6-a9c3-8cad9266b1f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Setting up a system for testing by users (tables are tables?)

2018-08-11 Thread Derek
*The users who should do the testing say "The new system should be like the 
production system."*
You need to let them know ASAP that that is very unlikely to be the case, 
unless you are using exactly the same tools.  You can probably provide 
similar functionality.

Otherwise you are too vague to give better feedback - "copying a system" 
has too many meanings.  If its just the database you need, and you plan to 
write a new front-end from scratch using Django, then that is "do-able" 
(assuming you can extract the data from SAP - that is a problem you will 
need to ask the SAP experts about).  Once you have the database available, 
you can follow this guide:

https://docs.djangoproject.com/en/2.1/howto/legacy-databases/


On Wednesday, 18 July 2018 11:45:00 UTC+2, guettli wrote:
>
> I have a task which looks simple at the first sight:
>
>  Setting up a system for testing by users. 
>
> In my case it is a custom issue tracking system.
>
> The users who should do the testing say "The new system should be like the 
> production system."
>
> If this would be true, then dump+restore of the database should work.
>
> No Nr2: the production system contains a lot of issues, and these should 
> not be in the new system.
>
> No Nr2: The production system contains configuration (in the database) of 
> remote storage systems. These
> database rows must not get copied, otherwise the testing system would 
> transfer testing data
> to the production storage system.
>
> Configuration like the list of ticket types should get copied.
>
> Tables are tables, or is there a difference between tables?
>
> Up to now I only found one hint to this task: In SAP this is called 
> "client copy" and there seem
> to be different "delivery classes" of a table:
>
>
> https://help.sap.com/doc/saphelp_crm70/7.0.0.18/en-US/43/45860774b711d2959700a0c929b3c3/content.htm?no_cache=true
>
> Are there tools/framework which support copying a system? I am curious, if 
> you know a framework outside django, please tell me.
>
> Up to now I could not find a tool or hint about solving this in a reusable 
> way in django. If I was blind, please let me know.
>
> Any kind of feedback is welcome.
>
> Regards,
>   Thomas Gütler
>

-- 
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+unsubscr...@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/8508f0bd-e5f6-4401-9215-682bb39ee5a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Setting up a system for testing by users (tables are tables?)

2018-08-10 Thread guettli
I see: no reply. Why?

Am Mittwoch, 18. Juli 2018 11:45:00 UTC+2 schrieb guettli:
>
> I have a task which looks simple at the first sight:
>
>  Setting up a system for testing by users. 
>
> In my case it is a custom issue tracking system.
>
> The users who should do the testing say "The new system should be like the 
> production system."
>
> If this would be true, then dump+restore of the database should work.
>
> No Nr2: the production system contains a lot of issues, and these should 
> not be in the new system.
>
> No Nr2: The production system contains configuration (in the database) of 
> remote storage systems. These
> database rows must not get copied, otherwise the testing system would 
> transfer testing data
> to the production storage system.
>
> Configuration like the list of ticket types should get copied.
>
> Tables are tables, or is there a difference between tables?
>
> Up to now I only found one hint to this task: In SAP this is called 
> "client copy" and there seem
> to be different "delivery classes" of a table:
>
>
> https://help.sap.com/doc/saphelp_crm70/7.0.0.18/en-US/43/45860774b711d2959700a0c929b3c3/content.htm?no_cache=true
>
> Are there tools/framework which support copying a system? I am curious, if 
> you know a framework outside django, please tell me.
>
> Up to now I could not find a tool or hint about solving this in a reusable 
> way in django. If I was blind, please let me know.
>
> Any kind of feedback is welcome.
>
> Regards,
>   Thomas Gütler
>

-- 
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+unsubscr...@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/0949314c-189f-4e90-b4f0-802ffe7de7fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: response.status 404 testing problem

2018-08-06 Thread Mike Dewhirst
Had a thought overnight ... maybe the 301 (permanently redirected) is 
because the staging server is using https and the server redirects from 
http to https.


I'll start looking there.

If anyone has any advice on best practice for this I'd love to hear it.

Thanks

Mike

On 6/08/2018 2:08 PM, Mike Dewhirst wrote:

Forgot to mention ...

dev = Django 1.11.15, Python 3.6 and 2.7 on Windows 10
staging = Django 1.11.15, Python 2.7 on Ubuntu 16.04 (no GUI) Apache 2.4

Sorry

Mike

On 6/08/2018 1:44 PM, Mike Dewhirst wrote:
I have a test which succeeds in development but fails with Apache in 
staging ...


Here is the test ...

    def test_course_view_not_found_status_code(self):
        # no course exists with pk of 99
    response = self.client.get(reverse('course:course_view', 
kwargs={'pk': 99}))

    self.assertEquals(response.status_code, 404)

The status code from the staging server with Apache is 301 <-- Huh?

The test class tearDown() deletes all courses between each test.

Here is the view ...

def course_view(request, pk=None):
    course = get_object_or_404(Course, pk=pk)
    # login is needed if there are questions/answers
    if course.login_needed or request.user.is_authenticated:
    return course_login_required(request, course=course)
    else:
    return course_login_not_required(request, course=course)

What am I doing wrong?

Thanks

Mike






--

Climate Pty Ltd
PO Box 308
Mount Eliza
Vic 3930
Australia +61

T: 03 9034 3977
M: 0411 704 143


--
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+unsubscr...@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/6f5096c6-6273-9358-de9f-0990f031c97a%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: response.status 404 testing problem

2018-08-05 Thread Mike Dewhirst

Forgot to mention ...

dev = Django 1.11.15, Python 3.6 and 2.7 on Windows 10
staging = Django 1.11.15, Python 2.7 on Ubuntu 16.04 (no GUI) Apache 2.4

Sorry

Mike

On 6/08/2018 1:44 PM, Mike Dewhirst wrote:
I have a test which succeeds in development but fails with Apache in 
staging ...


Here is the test ...

    def test_course_view_not_found_status_code(self):
        # no course exists with pk of 99
    response = self.client.get(reverse('course:course_view', 
kwargs={'pk': 99}))

    self.assertEquals(response.status_code, 404)

The status code from the staging server with Apache is 301  <-- Huh?

The test class tearDown() deletes all courses between each test.

Here is the view ...

def course_view(request, pk=None):
    course = get_object_or_404(Course, pk=pk)
    # login is needed if there are questions/answers
    if course.login_needed or request.user.is_authenticated:
    return course_login_required(request, course=course)
    else:
    return course_login_not_required(request, course=course)

What am I doing wrong?

Thanks

Mike



--
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+unsubscr...@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/dd876785-ecba-2a99-cf1f-676dabdeda08%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


response.status 404 testing problem

2018-08-05 Thread Mike Dewhirst
I have a test which succeeds in development but fails with Apache in 
staging ...


Here is the test ...

    def test_course_view_not_found_status_code(self):
        # no course exists with pk of 99
    response = self.client.get(reverse('course:course_view', 
kwargs={'pk': 99}))

    self.assertEquals(response.status_code, 404)

The status code from the staging server with Apache is 301  <-- Huh?

The test class tearDown() deletes all courses between each test.

Here is the view ...

def course_view(request, pk=None):
    course = get_object_or_404(Course, pk=pk)
    # login is needed if there are questions/answers
    if course.login_needed or request.user.is_authenticated:
    return course_login_required(request, course=course)
    else:
    return course_login_not_required(request, course=course)

What am I doing wrong?

Thanks

Mike

--
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+unsubscr...@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/dff00ca5-ef30-85ed-dc6a-96d06db988d9%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Setting up a system for testing by users (tables are tables?)

2018-07-18 Thread guettli
I have a task which looks simple at the first sight:

 Setting up a system for testing by users. 

In my case it is a custom issue tracking system.

The users who should do the testing say "The new system should be like the 
production system."

If this would be true, then dump+restore of the database should work.

No Nr2: the production system contains a lot of issues, and these should 
not be in the new system.

No Nr2: The production system contains configuration (in the database) of 
remote storage systems. These
database rows must not get copied, otherwise the testing system would 
transfer testing data
to the production storage system.

Configuration like the list of ticket types should get copied.

Tables are tables, or is there a difference between tables?

Up to now I only found one hint to this task: In SAP this is called "client 
copy" and there seem
to be different "delivery classes" of a table:

https://help.sap.com/doc/saphelp_crm70/7.0.0.18/en-US/43/45860774b711d2959700a0c929b3c3/content.htm?no_cache=true

Are there tools/framework which support copying a system? I am curious, if 
you know a framework outside django, please tell me.

Up to now I could not find a tool or hint about solving this in a reusable 
way in django. If I was blind, please let me know.

Any kind of feedback is welcome.

Regards,
  Thomas Gütler

-- 
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+unsubscr...@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/4b410060-3acc-4ddc-87c3-aa9c2af750c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


queryset appears empty in debugger during testing, but not in console

2018-06-18 Thread mccc
Hello,

I'm testing REST APIs with rest_framework.test.APITestCase, using their 
client for making requests and model_mommy for creating objects in the 
setUp() method.
The general working is quite simple: the view is supposed to fetch a User 
and an object, and assign permissions for the former to the latter by means 
of django-guardian's assign_perm; the test creates a user and a group in 
the setUp method, then the actual test performs a POST passing their pk's 
as payload.
The issue I'm seeing, is that when the 
User.objects.filter(pk__in=people_ids) instruction is executed, the value I 
see in the debugger is that of an empty queryset, while if I type the exact 
same line in a console connected to the same session as the debugger I see 
the actual value being found.
Then the view gets to the assign_perm instruction, and it crashes with 
an IndexError: list index out of range error on the first evaluation of the 
queryset itself, which happens on the for loop at line 247 in the file 
core.py of the django-guardian library.

Is there something obvious that I should be looking at, because I really 
cannot wrap my head around this.

Thanks,
Michele

-- 
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+unsubscr...@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/bf0050d0-525a-4844-834c-6c3eff2c04b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Definitive (or any) guide to testing Django admin actions with intermediate pages?

2018-05-28 Thread Derek
Looking for some help with a persistent problem.

While there are many examples scattered across the internet about how to
incorporate intermediate pages (typically with a form involved) into a
custom Django admin action, I have not been able to find a complete and
definitive guide to how to create unit tests for such functions.

If anyone has, actually, created such a unit test, I'd appreciate your
insight. I am not looking for "best practice" but something pragmatic that
"Just Works".

I imagine the unit test looks something like this:

def test_custom_admin_action():
# set up scaffolding - client? request? login a user?
# set up the queryset data
# set up the form data
# call the action, passing in (?) the queryset and the form data
# validate the response*

* in most cases, for the actions I write**, the action returns back to the
original Django list page from where it was called, typically with a
message indicating the success (or otherwise) of the action.  So validation
would ideally need to check both the system changes (e.g. records altered
or new records created) and the response to the user, which was made via
the Django messages framework.
** for purpose of this question, its safe to assume that all logic for the
action is included in it as a single whole.

Any help with this is appreciated - its the one part of testing that just
eludes me.

Derek

-- 
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+unsubscr...@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/CAF1Wu3MiLaU8TDW7dStQ4dDCZTW69EiXxRho_1gmJLAmcE0X0w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unit testing models.py

2018-05-14 Thread Melvyn Sopacua
Hi Mark,

On zondag 13 mei 2018 18:11:07 CEST Mark Phillips wrote:
> What should be unit tested in models.py? I assume the storing of data and
> retrieving of data from the database does not need to be tested, as I
> further assume django has a full set of tests for those operations.

You should test your business requirements. Even for those operations. Best 
illustrated:

# models.py
class Customer(models.Model):
email = models.EmailField()
name = models.CharField(max_length=100)

# tests.py

class CustomerTestCase(TestCase):
def test_create(self):
data = { 'email': 'i...@example.com', name='John Doe' }
  first = Customer.objects.create(**data)
with self.assertRaisesMessage(IntegrityError, 'duplicate key 
value'):
second = Customer.objects.create(**data)

This test will fail cause there's no unique constrain on email, which is 
likely to be a business requirement. You should test it. Especially because if 
someone refactor years down the line and accidentally removes the requirement, 
you have a problem.

> * Labels for all fields
> something like
> def test_first_name_label(self):
> author=Author.objects.get(id=1)
> field_label = author._meta.get_field('first_name').verbose_name
> self.assertEquals(field_label,'first name')

I would say this is exactly the thing you wouldn't test: anything dealing with 
_meta. Test these further downstream, by verifying form labels and their 
translated version if it applies. And I'd say the exact wording of a form 
label may not be at all important, so you could skip this.

-- 
Melvyn Sopacua

-- 
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+unsubscr...@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/2172791.13n9OJESef%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Unit testing models.py

2018-05-14 Thread 'Anthony Flury' via Django users

I would agree with that - test any custom functionality -

 * Custom methods (including __str__ and __repr__)
 * custom managers
 * Triggers (that maybe save custom fields on update)
 * validations - testing to ensure that the right validation is
   performed on that field - i.e. you linked the right field with the
   right validation.

I would do a cursory test that you can save and retrieve an object - 
just to make sure that you have executed your migrations correctly



On 13/05/18 19:08, Jani Tiainen wrote:

Hi,

In general you don't need to test your models if you don't use 
anything special there. If you do have properties or methods on models 
that do something that is good to test that they return correct values 
or do correct things.




On Sun, May 13, 2018 at 7:11 PM, Mark Phillips 
<m...@phillipsmarketing.biz <mailto:m...@phillipsmarketing.biz>> wrote:


What should be unit tested in models.py? I assume the storing of
data and retrieving of data from the database does not need to be
tested, as I further assume django has a full set of tests for
those operations.

    I can see testing these parts of models.py

* All custom methods

* Labels for all fields
something like
def test_first_name_label(self):
        author=Author.objects.get(id=1)
        field_label =
author._meta.get_field('first_name').verbose_name
        self.assertEquals(field_label,'first name')

* Field attributes (eg length of CharField)? Is this really
necessary, as I would again assume django covers this in their
unit tests?

Anything else that I am missing?

Thanks!

Mark
-- 
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+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users
<https://groups.google.com/group/django-users>.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/CAEqej2P0_sZt2j06nf0OnOL%2BE%3DuVa1Cs0BOFmTx8vjQm6-io2Q%40mail.gmail.com

<https://groups.google.com/d/msgid/django-users/CAEqej2P0_sZt2j06nf0OnOL%2BE%3DuVa1Cs0BOFmTx8vjQm6-io2Q%40mail.gmail.com?utm_medium=email_source=footer>.
For more options, visit https://groups.google.com/d/optout
<https://groups.google.com/d/optout>.




--
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...
--
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+unsubscr...@googlegroups.com 
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com 
<mailto: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/CAHn91oeJYPGbLaJAZbJqd3jxbDcY6m3d8e2fSE06_E_ZwXXosQ%40mail.gmail.com 
<https://groups.google.com/d/msgid/django-users/CAHn91oeJYPGbLaJAZbJqd3jxbDcY6m3d8e2fSE06_E_ZwXXosQ%40mail.gmail.com?utm_medium=email_source=footer>.

For more options, visit https://groups.google.com/d/optout.



--
--
Anthony Flury
email : *anthony.fl...@btinternet.com*
Twitter : *@TonyFlury <https://twitter.com/TonyFlury/>*

--
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+unsubscr...@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/9822baae-9064-2a48-ede3-c4f2c2b4d031%40btinternet.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unit testing models.py

2018-05-13 Thread Jani Tiainen
Hi,

In general you don't need to test your models if you don't use anything
special there. If you do have properties or methods on models that do
something that is good to test that they return correct values or do
correct things.



On Sun, May 13, 2018 at 7:11 PM, Mark Phillips <m...@phillipsmarketing.biz>
wrote:

> What should be unit tested in models.py? I assume the storing of data and
> retrieving of data from the database does not need to be tested, as I
> further assume django has a full set of tests for those operations.
>
> I can see testing these parts of models.py
>
> * All custom methods
>
> * Labels for all fields
> something like
> def test_first_name_label(self):
> author=Author.objects.get(id=1)
> field_label = author._meta.get_field('first_name').verbose_name
> self.assertEquals(field_label,'first name')
>
> * Field attributes (eg length of CharField)? Is this really necessary, as
> I would again assume django covers this in their unit tests?
>
> Anything else that I am missing?
>
> Thanks!
>
> Mark
>
> --
> 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+unsubscr...@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/CAEqej2P0_sZt2j06nf0OnOL%2BE%
> 3DuVa1Cs0BOFmTx8vjQm6-io2Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAEqej2P0_sZt2j06nf0OnOL%2BE%3DuVa1Cs0BOFmTx8vjQm6-io2Q%40mail.gmail.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

-- 
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+unsubscr...@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/CAHn91oeJYPGbLaJAZbJqd3jxbDcY6m3d8e2fSE06_E_ZwXXosQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


  1   2   3   4   5   6   7   8   9   10   >