Re: Trying to deploy Django 2.0.2 (DigitalOcean)

2018-02-07 Thread drone4four
Yes I know, *sacrac*. My venv was configured with Python 3.4 and pip3 
pulled Django 2.0.1 beautifully from the start.

I resolved my issue. The problem was with my Apache mod_wsgi version was 
with python 2.  I found and installed libapache2-mod-wsgi-py3. Now my site 
runs perfectly.

On Wednesday, February 7, 2018 at 10:31:02 PM UTC-5, sacrac wrote:
>
> i think you install with python 3 right, django 2.0.x run only version 
> python3!!
>
> On Wed, Feb 7, 2018 at 9:13 PM, drone4four  > wrote:
>
>> I am struggling deploying Django 2.0.2 on my DigitalOcean Droplet (Ubuntu 
>> 14.04) with Apache mod_wsgi.
>>
>> I’ve followed this guide 
>> 
>>  
>> closely. That guide focuses on setting up Django for delivery through 
>> port 80 (http).  I’m trying to establish a port 443 connection (https) and 
>> ssl so I am using this guide 
>> 
>> .
>>
>> When I navigate to my site, www.daniel496.agency , it basically times 
>> out after a minute or two and resolves to this error message:
>>
>> Internal Server Error
>>> The server encountered an internal error or misconfiguration and was 
>>> unable to complete your request.
>>> Please contact the server administrator at coffee.dri...@gmail.com 
>>>  to inform them of the time this error occurred, and the 
>>> actions you performed just before this error.
>>> More information about this error may be available in the server error 
>>> log.
>>> --
>>> Apache/2.4.7 (Ubuntu) Server at www.daniel496.agency Port 443
>>
>>
>> The strangest red flag I am aware of at this point is the contents of 
>> /var/log/apache2/errors.log . Here are the first ten lines of this log 
>> file:
>>
>>
>> 1 [Mon Feb 05 06:25:13.210967 2018] [ssl:warn] [pid 27373] AH01909: 
>>> RSA certificate configured for 127.0.0.1:443 does NOT include an ID 
>>> which matches the server name
>>> 2 [Mon Feb 05 06:25:13.213123 2018] [ssl:warn] [pid 27373] AH02292: 
>>> Init: Name-based SSL virtual hosts only work for clients with TLS server 
>>> name indication support (RFC 4366)
>>> 3 [Mon Feb 05 06:25:13.214637 2018] [mpm_prefork:notice] [pid 27373] 
>>> AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.22 OpenSSL/1.0.1f 
>>> mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
>>> 4 [Mon Feb 05 06:25:13.214675 2018] [core:notice] [pid 27373] 
>>> AH00094: Command line: '/usr/sbin/apache2'
>>> 5 ImportError: No module named site
>>> 6 ImportError: No module named site
>>> 7 ImportError: No module named site
>>> 8 ImportError: No module named site
>>> 9 ImportError: No module named site
>>>   10 ImportError: No module named site
>>
>>
>> Lines 5-10 repeat 355,822 times
>>
>> Here is my vhost config file, 
>> /etc/apache2/sites-available/daniel496.agency-le-ssl.conf:
>>
>>
>>   ServerAdmin 
>>> coffee.dri...@gmail.com  ServerName daniel496.agency 
>>> ServerAlias www.daniel496.agency DocumentRoot 
>>> /var/www/html/daniel496.agency/public_html ErrorLog 
>>> ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined 
>>> # Django project Alias /static /home/tranq/cel2fah/static >> /home/tranq/cel2fah/static> Require all granted  >> /home/tranq/cel2fah/cel2fah>  Require all granted  
>>>  WSGIDaemonProcess cel2fah2 python-path=/home/tranq/cel2fah 
>>> python-home=/home/tranq/cel2fah/venv WSGIProcessGroup cel2fah2 
>>> WSGIScriptAlias / /home/tranq/cel2fah/cel2fah/wsgi.py Include 
>>> /etc/letsencrypt/options-ssl-apache.conf SSLCertificateFile 
>>> /etc/letsencrypt/live/daniel496.agency/cert.pem SSLCertificateKeyFile 
>>> /etc/letsencrypt/live/daniel496.agency/privkey.pem SSLCertificateChainFile 
>>> /etc/letsencrypt/live/daniel496.agency/chain.pem   
>>
>>
>>
>> Is there any other information I can provide?
>>
>> Thanks for your attention.
>>
>> -- 
>> 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...@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/d10625a1-f380-4ab2-8ec0-efa25aaea5b6%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> att.
> Carlos Rocha
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails 

Re: Trying to deploy Django 2.0.2 (DigitalOcean)

2018-02-07 Thread carlos
i think you install with python 3 right, django 2.0.x run only version
python3!!

On Wed, Feb 7, 2018 at 9:13 PM, drone4four  wrote:

> I am struggling deploying Django 2.0.2 on my DigitalOcean Droplet (Ubuntu
> 14.04) with Apache mod_wsgi.
>
> I’ve followed this guide
> 
> closely. That guide focuses on setting up Django for delivery through
> port 80 (http).  I’m trying to establish a port 443 connection (https) and
> ssl so I am using this guide
> 
> .
>
> When I navigate to my site, www.daniel496.agency , it basically times out
> after a minute or two and resolves to this error message:
>
> Internal Server Error
>> The server encountered an internal error or misconfiguration and was
>> unable to complete your request.
>> Please contact the server administrator at coffee.drinker.daniel@gmail.
>> com to inform them of the time this error occurred, and the actions you
>> performed just before this error.
>> More information about this error may be available in the server error
>> log.
>> --
>> Apache/2.4.7 (Ubuntu) Server at www.daniel496.agency Port 443
>
>
> The strangest red flag I am aware of at this point is the contents of
> /var/log/apache2/errors.log . Here are the first ten lines of this log
> file:
>
>
> 1 [Mon Feb 05 06:25:13.210967 2018] [ssl:warn] [pid 27373] AH01909:
>> RSA certificate configured for 127.0.0.1:443 does NOT include an ID
>> which matches the server name
>> 2 [Mon Feb 05 06:25:13.213123 2018] [ssl:warn] [pid 27373] AH02292:
>> Init: Name-based SSL virtual hosts only work for clients with TLS server
>> name indication support (RFC 4366)
>> 3 [Mon Feb 05 06:25:13.214637 2018] [mpm_prefork:notice] [pid 27373]
>> AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.22 OpenSSL/1.0.1f
>> mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
>> 4 [Mon Feb 05 06:25:13.214675 2018] [core:notice] [pid 27373]
>> AH00094: Command line: '/usr/sbin/apache2'
>> 5 ImportError: No module named site
>> 6 ImportError: No module named site
>> 7 ImportError: No module named site
>> 8 ImportError: No module named site
>> 9 ImportError: No module named site
>>   10 ImportError: No module named site
>
>
> Lines 5-10 repeat 355,822 times
>
> Here is my vhost config file, /etc/apache2/sites-available/
> daniel496.agency-le-ssl.conf:
>
>
>   ServerAdmin
>> coffee.drinker.dan...@gmail.com ServerName daniel496.agency ServerAlias
>> www.daniel496.agency DocumentRoot /var/www/html/daniel496.agency/public_html
>> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log
>> combined # Django project Alias /static /home/tranq/cel2fah/static
>>  Require all granted 
>>   Require all granted
>>   WSGIDaemonProcess cel2fah2 
>> python-path=/home/tranq/cel2fah
>> python-home=/home/tranq/cel2fah/venv WSGIProcessGroup cel2fah2
>> WSGIScriptAlias / /home/tranq/cel2fah/cel2fah/wsgi.py Include
>> /etc/letsencrypt/options-ssl-apache.conf SSLCertificateFile
>> /etc/letsencrypt/live/daniel496.agency/cert.pem SSLCertificateKeyFile
>> /etc/letsencrypt/live/daniel496.agency/privkey.pem
>> SSLCertificateChainFile /etc/letsencrypt/live/daniel496.agency/chain.pem
>>  
>
>
>
> Is there any other information I can provide?
>
> Thanks for your attention.
>
> --
> 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/d10625a1-f380-4ab2-8ec0-efa25aaea5b6%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
att.
Carlos Rocha

-- 
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/CAM-7rO1W9GjAtRWdWUvSK630nh6jfw3rvM5EajZ0ziVht4bz%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Trying to deploy Django 2.0.2 (DigitalOcean)

2018-02-07 Thread drone4four


I am struggling deploying Django 2.0.2 on my DigitalOcean Droplet (Ubuntu 
14.04) with Apache mod_wsgi.

I’ve followed this guide 

 
closely. That guide focuses on setting up Django for delivery through port 
80 (http).  I’m trying to establish a port 443 connection (https) and ssl 
so I am using this guide 

.

When I navigate to my site, www.daniel496.agency , it basically times out 
after a minute or two and resolves to this error message:

Internal Server Error
> The server encountered an internal error or misconfiguration and was 
> unable to complete your request.
> Please contact the server administrator at coffee.drinker.dan...@gmail.com 
> to inform them of the time this error occurred, and the actions you 
> performed just before this error.
> More information about this error may be available in the server error log.
> --
> Apache/2.4.7 (Ubuntu) Server at www.daniel496.agency Port 443


The strangest red flag I am aware of at this point is the contents of 
/var/log/apache2/errors.log . Here are the first ten lines of this log file:


1 [Mon Feb 05 06:25:13.210967 2018] [ssl:warn] [pid 27373] AH01909: RSA 
> certificate configured for 127.0.0.1:443 does NOT include an ID which 
> matches the server name
> 2 [Mon Feb 05 06:25:13.213123 2018] [ssl:warn] [pid 27373] AH02292: 
> Init: Name-based SSL virtual hosts only work for clients with TLS server 
> name indication support (RFC 4366)
> 3 [Mon Feb 05 06:25:13.214637 2018] [mpm_prefork:notice] [pid 27373] 
> AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.22 OpenSSL/1.0.1f 
> mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
> 4 [Mon Feb 05 06:25:13.214675 2018] [core:notice] [pid 27373] AH00094: 
> Command line: '/usr/sbin/apache2'
> 5 ImportError: No module named site
> 6 ImportError: No module named site
> 7 ImportError: No module named site
> 8 ImportError: No module named site
> 9 ImportError: No module named site
>   10 ImportError: No module named site


Lines 5-10 repeat 355,822 times

Here is my vhost config file, 
/etc/apache2/sites-available/daniel496.agency-le-ssl.conf:


  ServerAdmin 
> coffee.drinker.dan...@gmail.com ServerName daniel496.agency ServerAlias 
> www.daniel496.agency DocumentRoot 
> /var/www/html/daniel496.agency/public_html ErrorLog 
> ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined 
> # Django project Alias /static /home/tranq/cel2fah/static  /home/tranq/cel2fah/static> Require all granted   /home/tranq/cel2fah/cel2fah>  Require all granted  
>  WSGIDaemonProcess cel2fah2 python-path=/home/tranq/cel2fah 
> python-home=/home/tranq/cel2fah/venv WSGIProcessGroup cel2fah2 
> WSGIScriptAlias / /home/tranq/cel2fah/cel2fah/wsgi.py Include 
> /etc/letsencrypt/options-ssl-apache.conf SSLCertificateFile 
> /etc/letsencrypt/live/daniel496.agency/cert.pem SSLCertificateKeyFile 
> /etc/letsencrypt/live/daniel496.agency/privkey.pem SSLCertificateChainFile 
> /etc/letsencrypt/live/daniel496.agency/chain.pem   



Is there any other information I can provide?

Thanks for your attention.

-- 
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/d10625a1-f380-4ab2-8ec0-efa25aaea5b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to test get_success_url in CreateView in Django

2018-02-07 Thread Tony


I am trying to write a test for the get_success_url method in a CreateView, 
to make sure it redirects to the newly created page. But the response 
status code is 200 instead of 302 as I expected.

views.py

class BlogCreate(CreateView):
model = Blog
fields = [‘author’, 'title', ’post’]
def get_success_url(self):
return reverse_lazy('blog:blog-detail', kwargs={'slug': 
self.object.slug})
class BlogList(ListView):
model = Blog
ordering = ["-created"]

class BlogDetail(DetailView):
model = Blog

config/urls.py

from django.conf.urls import include, url

urlpatterns = [
url(r'^blog/', include('blog.url', namespace='blog')),

blog/urls.py

from django.conf.urls import urlfrom .views import BlogCreate, BlogList, 
BlogDetail, BlogEdit, BlogDelete


urlpatterns = [
url(r'^(?P[-\w]+)/$', BlogDetail.as_view(), name='blog-detail'),
url(r'^(?P[-\w]+)/edit$', BlogEdit.as_view(), name='blog-edit'),
url(r'^(?P[-\w]+)/delete$', BlogDelete.as_view(), name='blog-delete'),
url(r'^new$', BlogCreate.as_view(), name='blog-create'),
url(r'^$', BlogList.as_view(), name='blog-list'),]

tests.py

class BlogCreateTest(TestCase):
def setUp(self):
self.user = User.objects.create_user(username='john', password='123')

def test_create_success_url(self):
post = {‘author’: self.user,
'title': ‘new blog’,
‘article’: ‘text’,
}

url = reverse_lazy('blog:blog-create')

success_url = reverse_lazy('blog:blog-detail', 
kwargs={'slug':'new-blog'})
response = self.client.post(url, post)

self.assertEqual(response.status_code, 302)
self.assertRedirects(response, success_url)

-- 
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/9521294e-a64e-4015-a3b7-9bf1d34c3cd0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing Channels 2.0 consumers - problem with routing

2018-02-07 Thread Andrew Godwin
I'm not going to address the mocking, as there's subtle details there (e.g.
you mocked group_name as a non-property, I think), but look at the main
issue.

Can you make your code print out what _is_ in `self.scope`? url_route
should definitely be in there, but I am curious what it looks like if it is
not.

Andrew

On Wed, Feb 7, 2018 at 12:16 PM, Azamat Galimzhanov 
wrote:

> Hello,
>
> I'm setting up an auctions application using channels and websockets. When
> I'm running the server the code works just fine, troubles arise when I'm
> trying to test my app.
>
> asgiref==2.1.3
> daphne==2.0.2
> Django==2.0.2
> channels==2.0.1
> channels-redis==2.0.2
> pytest==3.4.0
> pytest-asyncio==0.8.0
>
> a bunch of other stuff, but I think that's it for relevant libraries.
>
> Here is my consumer:
>
> class AuctionConsumer(WebsocketConsumer):
> @property
> @lru_cache(maxsize=None)
> def group_name(self):
> auction_id = self.scope['url_route']['kwargs']['auction_id']
> return 'auction_{}'.format(auction_id)
>
> def connect(self):
> AsyncToSync(self.channel_layer.group_add)(self.group_name, 
> self.channel_name)
> self.accept()
>
>
> Here is my routing:
>
> application = ProtocolTypeRouter({
> 'websocket': URLRouter([
> path("auctions//", AuctionConsumer),
> ]),
> })
>
>
> And here is my test:
>
>
> @pytest.mark.asyncio
> async def test_auction_consumer(mocker):
> communicator = WebsocketCommunicator(AuctionConsumer, 'auctions/1/')
> connected, subprotocol = await communicator.connect()
> assert connected
> # Test sending text
> await communicator.send_to(text_data='1')
> response = await communicator.receive_from()
> assert response == '1'
> # Close
> await communicator.disconnect()
>
>
>
> I'm running into the following problem;
>
> @property
> @lru_cache(maxsize=None)
> def group_name(self):
> >   auction_id = self.scope['url_route']['kwargs']['auction_id']
> E   KeyError: 'url_route'
>
> I tried mocking at the top of my test:
>
> group_name = mocker.patch('auctions.consumers.AuctionConsumer.group_name')
> group_name.return_value = 'auction'
>
>
> But then I run into:
>
> def valid_group_name(self, name):
> if self.match_type_and_length(name):
> if bool(self.group_name_regex.match(name)):
> return True
> raise TypeError(
> "Group name must be a valid unicode string containing only
> ASCII " +
> >   "alphanumerics, hyphens, or periods."
> )
> E   TypeError: Group name must be a valid unicode string containing
> only ASCII alphanumerics, hyphens, or periods.
>
>
> I also tried:
>
> scope = mocker.patch('auctions.consumers.AuctionConsumer.scope')
> scope.return_value = {'url_route': {}}
>
>
> But that got me:
>
> if not self.create and original is DEFAULT:
> raise AttributeError(
> >   "%s does not have the attribute %r" % (target, name)
> )
> E   AttributeError: 
> does not have the attribute 'scope'
>
>
> At this point I'm out of ideas. Anything I should try?
>
> Thanks in advance.
>
> --
> 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/528e93c5-dfb1-4cc1-a599-b99404c59533%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/CAFwN1uoZ875%3DO%3DPdurHw%3DtrHR960Pm1KnEjue0EKCzx%2BAnWdMw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Testing Channels 2.0 consumers - problem with routing

2018-02-07 Thread Azamat Galimzhanov
Hello,

I'm setting up an auctions application using channels and websockets. When 
I'm running the server the code works just fine, troubles arise when I'm 
trying to test my app.

asgiref==2.1.3
daphne==2.0.2
Django==2.0.2
channels==2.0.1
channels-redis==2.0.2
pytest==3.4.0
pytest-asyncio==0.8.0

a bunch of other stuff, but I think that's it for relevant libraries.

Here is my consumer:

class AuctionConsumer(WebsocketConsumer):
@property
@lru_cache(maxsize=None)
def group_name(self):
auction_id = self.scope['url_route']['kwargs']['auction_id']
return 'auction_{}'.format(auction_id)

def connect(self):
AsyncToSync(self.channel_layer.group_add)(self.group_name, 
self.channel_name)
self.accept()


Here is my routing:

application = ProtocolTypeRouter({
'websocket': URLRouter([
path("auctions//", AuctionConsumer),
]),
})


And here is my test:


@pytest.mark.asyncio
async def test_auction_consumer(mocker):
communicator = WebsocketCommunicator(AuctionConsumer, 'auctions/1/')
connected, subprotocol = await communicator.connect()
assert connected
# Test sending text
await communicator.send_to(text_data='1')
response = await communicator.receive_from()
assert response == '1'
# Close
await communicator.disconnect()



I'm running into the following problem;

@property
@lru_cache(maxsize=None)
def group_name(self):
>   auction_id = self.scope['url_route']['kwargs']['auction_id']
E   KeyError: 'url_route'

I tried mocking at the top of my test:

group_name = mocker.patch('auctions.consumers.AuctionConsumer.group_name')
group_name.return_value = 'auction'


But then I run into:

def valid_group_name(self, name):
if self.match_type_and_length(name):
if bool(self.group_name_regex.match(name)):
return True
raise TypeError(
"Group name must be a valid unicode string containing only 
ASCII " +
>   "alphanumerics, hyphens, or periods."
)
E   TypeError: Group name must be a valid unicode string containing 
only ASCII alphanumerics, hyphens, or periods.


I also tried:

scope = mocker.patch('auctions.consumers.AuctionConsumer.scope')
scope.return_value = {'url_route': {}}


But that got me:

if not self.create and original is DEFAULT:
raise AttributeError(
>   "%s does not have the attribute %r" % (target, name)
)
E   AttributeError:  
does not have the attribute 'scope'


At this point I'm out of ideas. Anything I should try?

Thanks in advance.

-- 
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/528e93c5-dfb1-4cc1-a599-b99404c59533%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels 2.0 WebSocket demultiplexing

2018-02-07 Thread Daniel Gilge
Oh, thanks. Sorry, I didn’t realise that this issue is related to Channels 2.

> Am 07.02.2018 um 19:09 schrieb Andrew Godwin :
> 
> Hi,
> 
> It's not yet been re-implemented - here's the issue to track it: 
> https://github.com/django/channels/issues/825 
> 
> 
> Andrew
> 
> On Wed, Feb 7, 2018 at 1:53 AM, Daniel Gilge  > wrote:
> Hi,
> 
> how do you demultiplex in Channels 2.0 using WebSockets?
> 
> I want to use a single WebSocket connection and be able to address different 
> models according to the path.
> 
> Daniel
> 
> -- 
> 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/e7129dc6-bf95-4043-8274-7750171663d6%40googlegroups.com
>  
> .
> For more options, visit https://groups.google.com/d/optout 
> .
> 
> 
> -- 
> 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/957DNwlgN7A/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/CAFwN1uozsmT%2BLmzdM3yNzWKSsdv%2BMX7qogEnBg8rcbu9qFU7tw%40mail.gmail.com
>  
> .
> For more options, visit https://groups.google.com/d/optout 
> .

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+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/24B38180-54DF-4DC3-A6CF-29AAB58CF1FA%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels 2.0 WebSocket demultiplexing

2018-02-07 Thread Andrew Godwin
Hi,

It's not yet been re-implemented - here's the issue to track it:
https://github.com/django/channels/issues/825

Andrew

On Wed, Feb 7, 2018 at 1:53 AM, Daniel Gilge  wrote:

> Hi,
>
> how do you demultiplex in Channels 2.0 using WebSockets?
>
> I want to use a single WebSocket connection and be able to address
> different models according to the path.
>
> Daniel
>
> --
> 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/e7129dc6-bf95-4043-8274-7750171663d6%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/CAFwN1uozsmT%2BLmzdM3yNzWKSsdv%2BMX7qogEnBg8rcbu9qFU7tw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing Channels database data missing in Consumer

2018-02-07 Thread Andrew Godwin
Interesting. I did note that you called ORM methods in an async context,
which is not how you are supposed to do it, but I also believe that should
work. Maybe try splitting the ORM methods into a separate function and
awaiting it using SyncToAsync?

As for the staticfiles in live test case problem, I have opened a ticket
for that: https://github.com/django/channels/issues/880

Andrew

On Wed, Feb 7, 2018 at 9:51 AM, Daniel Gilge  wrote:

> Hi Andrew,
>
> thanks for your reply.
>
> This test is passing (using the same packages):
>
> def test_fixture(db_with_segment, admin_client):
> assert models.MyModel.objects.count() == 1
> response = admin_client.get('/api/my_model/list/')
> assert len(response.json()['results']) == 1
>
> I tried to write a simpler async test with asyncio.wait but I didn't
> complete it so far.
>
> I thought to just write ChannelsLiveServerTestCase tests but I couldn't
> manage to serve static files there. (Both, setting static_handler =
> StaticFilesHandler – what StaticLiveServerTestCase does – and running
> collectstatic didn't work.)
>
> Finally I ran my development server and did some tests in the browser
> console. There it works. I'll continue coding using this technique to
> "test" my code and try to find a solution for the other (real) tests as I
> have time.
>
> Am Mittwoch, 7. Februar 2018 04:31:14 UTC+1 schrieb Andrew Godwin:
>>
>> I'm not quite sure either. Does the test setup work if you are not in
>> async mode?
>>
>> Andrew
>>
>> On Tue, Feb 6, 2018 at 9:45 AM, Daniel Gilge  wrote:
>>
>>> Hi,
>>>
>>> this question is related to Channels 2.0, Django 2.0, pytest 3.4,
>>> pytest-django 3.1 and pytest-asyncio 0.8.
>>>
>>> I created a pytest:
>>>
>>> @pytest.fixture
>>> def db_with_obj(db):
>>> factories.MyModelFactory()
>>>
>>> @pytest.mark.asyncio
>>> async def test_something(db_with_obj):
>>> print(models.MyModelFactory.objects.all())
>>> obj = models.MyModelFactory.objects.first()
>>> communicator = WebsocketCommunicator(MyConsumer, 'ws/')
>>> connected, subprotocol = await communicator.connect()
>>> assert connected
>>> await communicator.send_to(text_data=json.dumps({
>>> 'id': obj.pk,
>>> 'content': 'my content',
>>> }))
>>> response = await communicator.receive_from()
>>> assert response == 'my content'
>>> await communicator.disconnect()
>>>
>>> print gives me ]>
>>>
>>> Here my Consumer code:
>>>
>>> class MyConsumer(WebsocketConsumer):
>>> def receive(self, text_data=None, bytes_data=None):
>>> print(models.MyModel.objects.all())
>>> # ...
>>>
>>> print gives me 
>>>
>>> I don't know what I'm doing wrong. I didn't use both, pytest and Python
>>> async code, before. Therefore I don't know where to look for the solution,
>>> though I think it's easy to solve. Any hint appreciated.
>>>
>>> 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...@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/ms
>>> gid/django-users/7e5f63f4-789c-413e-a8d2-fcf8ea62a2cb%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/464c465b-8b24-4061-977d-a44b4868fc84%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/CAFwN1ur8xAgTd21ntmV6dyYD6eTTLW3HWghTHLVT_OJHr0UJNA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing Channels database data missing in Consumer

2018-02-07 Thread Daniel Gilge
Hi Andrew,

thanks for your reply.

This test is passing (using the same packages):

def test_fixture(db_with_segment, admin_client):
assert models.MyModel.objects.count() == 1
response = admin_client.get('/api/my_model/list/')
assert len(response.json()['results']) == 1

I tried to write a simpler async test with asyncio.wait but I didn't 
complete it so far.

I thought to just write ChannelsLiveServerTestCase tests but I couldn't 
manage to serve static files there. (Both, setting static_handler = 
StaticFilesHandler – what StaticLiveServerTestCase does – and running 
collectstatic didn't work.)

Finally I ran my development server and did some tests in the browser 
console. There it works. I'll continue coding using this technique to 
"test" my code and try to find a solution for the other (real) tests as I 
have time.

Am Mittwoch, 7. Februar 2018 04:31:14 UTC+1 schrieb Andrew Godwin:
>
> I'm not quite sure either. Does the test setup work if you are not in 
> async mode?
>
> Andrew
>
> On Tue, Feb 6, 2018 at 9:45 AM, Daniel Gilge  > wrote:
>
>> Hi,
>>
>> this question is related to Channels 2.0, Django 2.0, pytest 3.4, 
>> pytest-django 3.1 and pytest-asyncio 0.8.
>>
>> I created a pytest:
>>
>> @pytest.fixture
>> def db_with_obj(db):
>> factories.MyModelFactory()
>>
>> @pytest.mark.asyncio
>> async def test_something(db_with_obj):
>> print(models.MyModelFactory.objects.all())
>> obj = models.MyModelFactory.objects.first()
>> communicator = WebsocketCommunicator(MyConsumer, 'ws/')
>> connected, subprotocol = await communicator.connect()
>> assert connected
>> await communicator.send_to(text_data=json.dumps({
>> 'id': obj.pk,
>> 'content': 'my content',
>> }))
>> response = await communicator.receive_from()
>> assert response == 'my content'
>> await communicator.disconnect()
>>
>> print gives me ]>
>>
>> Here my Consumer code:
>>
>> class MyConsumer(WebsocketConsumer):
>> def receive(self, text_data=None, bytes_data=None):
>> print(models.MyModel.objects.all())
>> # ...
>>
>> print gives me 
>>
>> I don't know what I'm doing wrong. I didn't use both, pytest and Python 
>> async code, before. Therefore I don't know where to look for the solution, 
>> though I think it's easy to solve. Any hint appreciated.
>>
>> 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...@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/7e5f63f4-789c-413e-a8d2-fcf8ea62a2cb%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/464c465b-8b24-4061-977d-a44b4868fc84%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Syntax error with TruncDay

2018-02-07 Thread Andrea
I have the following model in Django 1.11.10:

class Test(models.Model):
  ...
  date_start = models.DateTimeField()
  ...

The following works fine:

Test.objects.annotate(day_start=TruncDate(ExpressionWrapper(F('date_start')
- timedelta(hours=5), output_field=models.DateField()))

If I replace TruncDate with TruncDay or TruncMonth:

Test.objects.annotate(day_start=TruncDay(ExpressionWrapper(F('date_start')
- timedelta(hours=5), output_field=models.DateField()))

I get the following error:

ProgrammingError: syntax error at or near "%"
LINE 1: ...TE_TRUNC('day', ("test_test"."date_start" - %s)) AS "d...

Is anyone able to reproduce the problem? The goal is to shift the
`date_start` field in time before applying the `Trunc*` operation. Is that
possible?

Thanks!
Andrea

Andrea Angelini

*Zap 15*
Tailored web solutions
www.zap15.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 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/CAAPQ7Y0mAPQU5NATzzR%2BeX8jy-VBKBSjvBRdmcvYLMSYw%2BBnpg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Channels 2.0 WebSocket demultiplexing

2018-02-07 Thread Daniel Gilge
Hi,

how do you demultiplex in Channels 2.0 using WebSockets?

I want to use a single WebSocket connection and be able to address 
different models according to the path.

Daniel

-- 
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/e7129dc6-bf95-4043-8274-7750171663d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.