Comments (21)
Ok, thanks. I will try and have a look, and perhaps expand the tutorial example to show interactions with the DB.
from channels.
Are you sure your environment variables are being set correctly? (I'd expect the test DB name to be test_testasgi
from the sample .env file + settings.py you have in your repo.)
from channels.
Pardon me, coming from pytest
I was unaware unittest
already required a database and then simply cloned the already-existing one, prefixing it with test_
. While the database error is gone, data created within a test function still cannot be used from the browser.
E.g. using the following code does not allow the user to log into the admin using the browser:
user_staff = User.objects.create(
username='test',
email='[email protected]',
password=make_password('hunter42'),
is_staff=True,
is_superuser=True
)
self.client.login(
username=user_staff.username,
password='hunter42'
)
# returns True
self.driver.get(self.live_server_url + "/admin/")
self.driver.find_element('name', 'username').send_keys(user_staff.username)
self.driver.find_element('name', 'password').send_keys('hunter42')
self.driver.find_element(By.CSS_SELECTOR, "input[type='submit']").click()
# error in admin - login does not work
from channels.
Ok, but in general that works, so you need to put a breakpoint there and see why the login isn't working. (This isn't really a channels issue.)
from channels.
It's not a channels
issue per-se, but what I assume is an asgiref issue / ChannelsLiveServerTestCase
issue, since the intended use to test the frontend does not work as outlined in the docs.
It's like the database is out of sync between the sync test routing and the async server worker thread. I threw in a pdb
in the test function, but everything there is working fine there. Not sure how I would debug the server function serving the frontend.
from channels.
It works if you follow the steps in the tutorial. I'm not sure what else I can say given the info provided. Sorry.
from channels.
I just followed the steps in the tutorial and setting up a test database that is available via the frontend does not work as expected.
Users that are created as part of the regular Python functions are not available to the frontend (see chat.tests.DatabaseTests
). The only reason the tutorial "works" is because it does not use any part of the ORM but unauthenticated views testing the mere websockets functionality.
One could argue that this is a sufficient for unit tests and the rest if out of scope for this library. However I would argue if you provide a dedicated test server for the use case, it should work with the ORM, because it's unlikely that it's used only with unauthenticated interactions.
from channels.
OK, your test project has way too much going on to identify any issue. Can you trim it down to a minimal please, with a clear error case, rather than a sleep
. (The initial ticket here was "Database not created", so if you can clarify that too, that would be great.
I'd move the user creation into setup, and then inspect the DB to make sure that's actually committed. Then compare Django's Admin Selenium test cases, which do this at length.
from channels.
OK, your test project has way too much going on to identify any issue
Not sure what exactly you are referring to. I simply implemented the tutorial boilerplate in chat
and config
-related settings as requested.
I slimmed down chat.tests
โ including a SyncDatabaseTests
and AsyncDatabaseTests
, both testing for the same result, only using the different servers. The former one works.
then inspect the DB to make sure that's actually committed. Then compare Django's Admin Selenium test cases, which do this at length
From what I can see in e.g. the Django admin_changelist test, the user is simply created, then used to log in thereafter. Nevertheless I added a simple check to test_user_model_creation
that asserts the user is present before opening the browser.
from channels.
Heya! Have you had a chance to look into it?
from channels.
Hi @alfonsrv โ no, not as yet. It's on my list for later in the autumn, but short of someone (you maybe?) digging deeper (and highlighting either the error in the project or the bug in the test case) it'll have to wait until I can get to it.
from channels.
from channels.
@ashtonrobinson I tried using your PR but it leads to a ProgrammingError at /chat/test/
yellow error page, as if migrations didn't run for the frontend / test database.
But it seems like you're onto something โ because using the async test case (chat.tests.AsyncDatabaseTests
) I created, it appears to use the default
database instead of the test database.
And users that are created as part of python manage.py createsuperuser
are listed in the AsyncDatabaseTests
frontend, while they are not when using the regular unit test SyncDatabaseTests
.
from channels.
From the PR...
a multiprocessing.Process object which takes care of creating a new process. This uses the SpawnProcess of multiprocessing class on Windows and macOS. Linux uses the Fork method...
Ah, spawn vs fork
This will be related to the discover runner updates in Django 4.1. https://docs.djangoproject.com/en/5.0/releases/4.1/#tests
See https://code.djangoproject.com/ticket/31169 โ We'll likely need to use some of the added test setup steps.
Progress. ๐
from channels.
Just to add in the meantime, if the spawn startup is the issue running the tests with --parallel=1
should function as a workaround.
from channels.
That doesn't work either.
How can something as fundamental as tests (albeit in the context of database interactions) be kept broken for what is essentially a core Django library for this long?
from channels.
@alfonsrv by it not being exercised. Django is built on volunteer effort, so short of someone picking it up and investigating it can take a while.
Since you're using this, perhaps you could be the person to work out the cause and resolve it.
from channels.
I tried looking into it, but I'm afraid it's a bit too advanced for my understanding.
Willing to sponsor and offer a bounty though.
from channels.
@alfonsrv the first step would be a failing test case demonstrating the issue. If folks can instantly get to the problem it's much easier to work on.
from channels.
That exists: https://github.com/alfonsrv/django-asgitest โ the test cases inherit the same base class, to run the same code both Sync
and Async
.
Mentioned the repo here previously. It has some boilerplate code due to following the channels tutorial โ as I was asked to previously โ but the test cases are very basic.
from channels.
I really meant as a unit test against the channels test suite, but yes.
The bottom line is that until somebody can find the time to dig into it, this will sit there. It's on my list, but I have quite a few ๐คน other things which are more pressing to me, so it's not something I'm going to get to quickly.
from channels.
Related Issues (20)
- "group_add" is not a known member of "None" HOT 1
- ProtocolTypeRouter.__call__() missing 1 required positional argument: 'send' HOT 1
- Feature request: WebTransport support in Django Channels HOT 1
- Question about versions HOT 1
- initkwargs wasn't set in result consumer HOT 7
- `TEST_CONFIG` key has code using it but seems to be broken and no longer documented HOT 2
- AttributeError: 'NoneType' object has no attribute 'group_add' HOT 1
- OriginValidator could raise exception/log message for denied connections HOT 1
- Unable to collect code coverage when using `ChannelsLiveServerTestCase` HOT 14
- error in channel layer explanations HOT 2
- adding a check if group_name exists method for channel_layer HOT 1
- Small messages are getting concatenated HOT 1
- How can I change the schema in the database? HOT 1
- How to test send_json() contents when passing close=True HOT 2
- Handler declaration by decorator/annotation (in order to prevent potential method leaks) HOT 1
- django-q2 and django-channels together HOT 1
- Channel Layer's group_send() Not Working When Called From Django View HOT 3
- Add CORs middleware HOT 1
- Breakage in routing.py on django/main pre-5.1.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from channels.