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/

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
>>>>>&

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
&g

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,