Testing of Celery Tasks in Django
Hoping for just some general information here. I have a Celery Task that performs a few functions and then updates a model with new information from the functions.
I want to be able to test
\> that the task completes successfully
\> that the model updates successfully
And I want to be able to debug any errors inside the task. I have read alot of loose instructions but am not entirely sure which way to start.
I have used
@override\_settings\(
DEBUG=True,
CELERY\_TASK\_ALWAYS\_EAGER=True,
CELERY\_TASK\_EAGER\_PROPOGATES=True,
\)
to set appropriate settings for the test I want to run.
The test completes without failure, however, I KNOW that the task should be throwing exceptions and it does not.
How best to go about getting the exception info I need from the task in the django testing environment?
/r/django
https://redd.it/8aljqr
Hoping for just some general information here. I have a Celery Task that performs a few functions and then updates a model with new information from the functions.
I want to be able to test
\> that the task completes successfully
\> that the model updates successfully
And I want to be able to debug any errors inside the task. I have read alot of loose instructions but am not entirely sure which way to start.
I have used
@override\_settings\(
DEBUG=True,
CELERY\_TASK\_ALWAYS\_EAGER=True,
CELERY\_TASK\_EAGER\_PROPOGATES=True,
\)
to set appropriate settings for the test I want to run.
The test completes without failure, however, I KNOW that the task should be throwing exceptions and it does not.
How best to go about getting the exception info I need from the task in the django testing environment?
/r/django
https://redd.it/8aljqr
reddit
Testing of Celery Tasks in Django • r/django
Hoping for just some general information here. I have a Celery Task that performs a few functions and then updates a model with new information...
How to tackle Heroku 30 secs request timeout limit
I have a Django application pushed on Heroku which sometimes takes more than 30 secs time to process the data, hence I get the request timeout error. Is there any way to increase the timeout value to say around 2-5 min Or should I look for other web hosting alternatives.
/r/django
https://redd.it/8aij8x
I have a Django application pushed on Heroku which sometimes takes more than 30 secs time to process the data, hence I get the request timeout error. Is there any way to increase the timeout value to say around 2-5 min Or should I look for other web hosting alternatives.
/r/django
https://redd.it/8aij8x
reddit
How to tackle Heroku 30 secs request timeout limit • r/django
I have a Django application pushed on Heroku which sometimes takes more than 30 secs time to process the data, hence I get the request timeout...
[N] PyTorch as of April is installable via `pip install torch`
http://pytorch.org/ updated on April 3rd to allow `pip install torch`
/r/MachineLearning
https://redd.it/8aj2bj
http://pytorch.org/ updated on April 3rd to allow `pip install torch`
/r/MachineLearning
https://redd.it/8aj2bj
reddit
[N] PyTorch as of April is installable via... • r/MachineLearning
http://pytorch.org/ updated on April 3rd to allow `pip install torch`
Downloading files from MongoDB to the user
My project has MongoDB storing a users "file structure". Since the structure is a dict of dicts, eventually bottoming out at a string representation of the individual files, I'm trying to find a way to get django to zip all files in the structure and download them to the user when the user clicks a button. I'm not entirely sure how to go about this if anyone can post any resources or have advice on doing something simliar?
/r/django
https://redd.it/8an3zx
My project has MongoDB storing a users "file structure". Since the structure is a dict of dicts, eventually bottoming out at a string representation of the individual files, I'm trying to find a way to get django to zip all files in the structure and download them to the user when the user clicks a button. I'm not entirely sure how to go about this if anyone can post any resources or have advice on doing something simliar?
/r/django
https://redd.it/8an3zx
reddit
Downloading files from MongoDB to the user • r/django
My project has MongoDB storing a users "file structure". Since the structure is a dict of dicts, eventually bottoming out at a string...
Best way to test Django app running on docker
I'm adding tests to a large Django application in order to facilitate upgrades to python 3 and more recent versions of Django. The app relies on postgres, elasticsearch, and redis. Docker-compose works well with for this, allowing me to start a clean install of the app with versions matched exactly to what is in production.
I feel like integration tests are important because the search function, redis features, etc are intertwined. The problem I'm running into with the integration tests is using selenium. I tried running a headless version of chrome within docker (selenium/standalone-chrome-debug) but the tests are very slow, and sometimes hang. It really does not seem feasible to use selenium within docker. How are others dealing with this problem? From what I can tell I have these options:
1. Stop using selenium and move exclusively to something like Django TestCase
2. Refactor the tests so that I start the services and expose the ports with docker, but then run the main Django tests through a regular virtualenv. I'm not a big fan of this because I would have to change environment variables that point to the services just to run tests.
3. Somehow use my local version of chrome on my MacBook to run selenium tests, even though everything is running on docker. Not sure if this is possible?
Am I missing something? I would love to hear how others are solving this issue. I love docker so far but this hurdle is becoming frustrating.
/r/django
https://redd.it/8aneug
I'm adding tests to a large Django application in order to facilitate upgrades to python 3 and more recent versions of Django. The app relies on postgres, elasticsearch, and redis. Docker-compose works well with for this, allowing me to start a clean install of the app with versions matched exactly to what is in production.
I feel like integration tests are important because the search function, redis features, etc are intertwined. The problem I'm running into with the integration tests is using selenium. I tried running a headless version of chrome within docker (selenium/standalone-chrome-debug) but the tests are very slow, and sometimes hang. It really does not seem feasible to use selenium within docker. How are others dealing with this problem? From what I can tell I have these options:
1. Stop using selenium and move exclusively to something like Django TestCase
2. Refactor the tests so that I start the services and expose the ports with docker, but then run the main Django tests through a regular virtualenv. I'm not a big fan of this because I would have to change environment variables that point to the services just to run tests.
3. Somehow use my local version of chrome on my MacBook to run selenium tests, even though everything is running on docker. Not sure if this is possible?
Am I missing something? I would love to hear how others are solving this issue. I love docker so far but this hurdle is becoming frustrating.
/r/django
https://redd.it/8aneug
Reddit
reddit: the front page of the internet
r/django:
[AF] Authenticating internal APIs
I built a website using flask_login for handling 'logged in' permissions. This extension works great for protecting my views using `@login_required`, but it does nothing to protect my APIs (as far as I'm aware). How do I protect my internal API's? Do I integrate token-based JWT authentication?
EDIT: I had my decorators in the wrong order, sorry. `@login_required` wasn't working for me so I figured that it doesn't work with APIs for some reason. I actually discovered my problem: I placed my `l@login_required` decorator before my route handler, not after. Noob mistake.
/r/flask
https://redd.it/8akawc
I built a website using flask_login for handling 'logged in' permissions. This extension works great for protecting my views using `@login_required`, but it does nothing to protect my APIs (as far as I'm aware). How do I protect my internal API's? Do I integrate token-based JWT authentication?
EDIT: I had my decorators in the wrong order, sorry. `@login_required` wasn't working for me so I figured that it doesn't work with APIs for some reason. I actually discovered my problem: I placed my `l@login_required` decorator before my route handler, not after. Noob mistake.
/r/flask
https://redd.it/8akawc
reddit
[AF] Authenticating internal APIs • r/flask
I built a website using flask_login for handling 'logged in' permissions. This extension works great for protecting my views using...
What would you ask Guido if you had the chance ?
What if you had the chance to interview the creator of python himself ? What would you ask him?
/r/Python
https://redd.it/8amnrd
What if you had the chance to interview the creator of python himself ? What would you ask him?
/r/Python
https://redd.it/8amnrd
reddit
What would you ask Guido if you had the chance ? • r/Python
What if you had the chance to interview the creator of python himself ? What would you ask him?
[N] LSTM inference shoot-out: Intel Skylake vs NVIDIA V100
https://medium.com/@julsimon/lstm-inference-shoot-out-intel-skylake-vs-nvidia-v100-9b7d3f855ea3
/r/MachineLearning
https://redd.it/8ao4w1
https://medium.com/@julsimon/lstm-inference-shoot-out-intel-skylake-vs-nvidia-v100-9b7d3f855ea3
/r/MachineLearning
https://redd.it/8ao4w1
Medium
LSTM inference shoot-out: Intel Skylake vs NVIDIA V100
In a previous post, I showed you how to speed up Deep Learning inference for Apache MXNet by a factor of 7x to 10x, thanks to the Amazon…
Django Rest Framework Nested Models Api Help
https://stackoverflow.com/questions/49715780/connect-nested-models-django-rest-framework-api-serializer
/r/djangolearning
https://redd.it/8aorbb
https://stackoverflow.com/questions/49715780/connect-nested-models-django-rest-framework-api-serializer
/r/djangolearning
https://redd.it/8aorbb
Stackoverflow
Connect nested models django rest framework API serializer
I want to achieve this: a API to get all products for a category.
Models.py
class Category(models.Model):
main_category = models.CharField(max_length=200, default = '')
def __str__(self)...
Models.py
class Category(models.Model):
main_category = models.CharField(max_length=200, default = '')
def __str__(self)...
Serializing a dictionary that is not a model in Django restframework
I have read a few answers and posts about serializing an dictionary . But I still can't get it to work. Here is the problem. I do some data processing in django app , and it returns this dictionary (It has information about a quiz):
{101: {'subject': 'General-Intelligence', 'topics': ['Coding Decoding', 'Dice & Boxes', 'Statement & Conclusion', 'Venn Diagram', 'Mirror and Water Image', 'Paper Cutting and Folding', 'Clock/Time', 'Matrix', 'Direction', 'Blood Relation', 'Series Test', 'Ranking', 'Mathematical Operations', 'Alphabet Test', 'Odd one out', 'Analogy'], 'num_questions': 25, 'creator': 'Rajesh K Swami'}}
I want to serialize this dictionary. So what I have done is created a class for this dictionary. ie.
class PsudoTests:
def __init__(self,body):
self.body = body
Also a serializer:
class PsudoTestSerializer(serializers.Serializer):
body = serializers.DictField()
Now in api view :
class TestListView(generics.ListAPIView):
def get_serializer_class(self):
serializer = PsudoTestSerializer
def get_queryset(self):
me = Studs(self.request.user)
tests = me.toTake_Tests(1) # this method brings in the above dictionary that i want to serialize
p_test = PsudoTests(tests) #this creates an instance of class created above
return p_test
Now when i go to the url there is a key error:
"Got KeyError when attempting to get a value for field body on serializer PsudoTestSerializer.\nThe serializer field might be named incorrectly and not match any attribute or key on the dict instance.\nOriginal exception text was: 'body'."
/r/django
https://redd.it/8apaxg
I have read a few answers and posts about serializing an dictionary . But I still can't get it to work. Here is the problem. I do some data processing in django app , and it returns this dictionary (It has information about a quiz):
{101: {'subject': 'General-Intelligence', 'topics': ['Coding Decoding', 'Dice & Boxes', 'Statement & Conclusion', 'Venn Diagram', 'Mirror and Water Image', 'Paper Cutting and Folding', 'Clock/Time', 'Matrix', 'Direction', 'Blood Relation', 'Series Test', 'Ranking', 'Mathematical Operations', 'Alphabet Test', 'Odd one out', 'Analogy'], 'num_questions': 25, 'creator': 'Rajesh K Swami'}}
I want to serialize this dictionary. So what I have done is created a class for this dictionary. ie.
class PsudoTests:
def __init__(self,body):
self.body = body
Also a serializer:
class PsudoTestSerializer(serializers.Serializer):
body = serializers.DictField()
Now in api view :
class TestListView(generics.ListAPIView):
def get_serializer_class(self):
serializer = PsudoTestSerializer
def get_queryset(self):
me = Studs(self.request.user)
tests = me.toTake_Tests(1) # this method brings in the above dictionary that i want to serialize
p_test = PsudoTests(tests) #this creates an instance of class created above
return p_test
Now when i go to the url there is a key error:
"Got KeyError when attempting to get a value for field body on serializer PsudoTestSerializer.\nThe serializer field might be named incorrectly and not match any attribute or key on the dict instance.\nOriginal exception text was: 'body'."
/r/django
https://redd.it/8apaxg
reddit
Serializing a dictionary that is not a model in Django... • r/django
I have read a few answers and posts about serializing an dictionary . But I still can't get it to work. Here is the problem. I do some data...
Why use threads in Python?
I just learned about the GIL and from the looks of it, it appears even if we use threads in python, our program will take the same time if we just use a single thread due to GIL. If that's the case, using threads for performance isn't really the ideal use case in python, so why use it?
/r/Python
https://redd.it/8ao7lt
I just learned about the GIL and from the looks of it, it appears even if we use threads in python, our program will take the same time if we just use a single thread due to GIL. If that's the case, using threads for performance isn't really the ideal use case in python, so why use it?
/r/Python
https://redd.it/8ao7lt
reddit
Why use threads in Python? • r/Python
I just learned about the GIL and from the looks of it, it appears even if we use threads in python, our program will take the same time if we just...
Create your own Twitter Bot with Python and Tweepy!
https://medium.com/@Fidel_Willis/creating-a-twitter-bot-in-python-with-tweepy-ac524157a607?source=linkShare-11f6119feee0-1523198095
/r/Python
https://redd.it/8aqc1x
https://medium.com/@Fidel_Willis/creating-a-twitter-bot-in-python-with-tweepy-ac524157a607?source=linkShare-11f6119feee0-1523198095
/r/Python
https://redd.it/8aqc1x
Medium
Creating a Twitter Bot in Python with Tweepy
With about 15% of Twitter being composed of bots, I wanted to try my hand in it.
Cryptocurrency from scratch: part 1 Consistent Transactions
https://youtu.be/S0hmc5su4xc
/r/Python
https://redd.it/8apv9z
https://youtu.be/S0hmc5su4xc
/r/Python
https://redd.it/8apv9z
YouTube
Cryptocurrency from scratch: part 1 Consistent Transactions
Part 1: Consistent Transactions. Showing how Bitcoin and other cryptocurrencies handle transactions by writing my own in Python. This first installment just ...
Is Django for freelancing worth it?
I am interested in learning webdev for freelancing. I've tried php, asp mvc and django. I heard from most people that php is the way to go but i prefer python and django.
So how is the freelance landscape for django and python?
/r/django
https://redd.it/8aqdxo
I am interested in learning webdev for freelancing. I've tried php, asp mvc and django. I heard from most people that php is the way to go but i prefer python and django.
So how is the freelance landscape for django and python?
/r/django
https://redd.it/8aqdxo
reddit
Is Django for freelancing worth it? • r/django
I am interested in learning webdev for freelancing. I've tried php, asp mvc and django. I heard from most people that php is the way to go but i...
“The Cathedral and the Bazaar”: Mathematica vs. python, IPython and Jupyter, and their application to scientific papers
https://www.theatlantic.com/science/archive/2018/04/the-scientific-paper-is-obsolete/556676/
/r/Python
https://redd.it/8aqmzk
https://www.theatlantic.com/science/archive/2018/04/the-scientific-paper-is-obsolete/556676/
/r/Python
https://redd.it/8aqmzk
The Atlantic
The Scientific Paper Is Obsolete
Here's what's next.
Pyforms: Embedding a pyplot into a pyForm using ControlMatplotlib
I have come across the ControlMatplotlib control, however I cannot for the life of me figure out how to pass the pyplot to this control.
There is little to no example code for the use of this control and the docs don't have example code.
Any insight is greatly appreciated.
/r/Python
https://redd.it/8apvjp
I have come across the ControlMatplotlib control, however I cannot for the life of me figure out how to pass the pyplot to this control.
There is little to no example code for the use of this control and the docs don't have example code.
Any insight is greatly appreciated.
/r/Python
https://redd.it/8apvjp
reddit
Pyforms: Embedding a pyplot into a pyForm using... • r/Python
I have come across the ControlMatplotlib control, however I cannot for the life of me figure out how to pass the pyplot to this control. There...
[AF] Does anyone use webtest? If so, why use it over flask's built-in test client?
I've been learning unit/integration testing following [sloria/cookiecutter-flask](https://github.com/sloria/cookiecutter-flask) as an example. I know this approach is opinionated, but does anyone know what value webtest brings over flask's built-in test client? I'm relatively new to flask but I suspect that the author simply prefers using webtest (perhaps since it's a more general tool).
/r/flask
https://redd.it/89tvn5
I've been learning unit/integration testing following [sloria/cookiecutter-flask](https://github.com/sloria/cookiecutter-flask) as an example. I know this approach is opinionated, but does anyone know what value webtest brings over flask's built-in test client? I'm relatively new to flask but I suspect that the author simply prefers using webtest (perhaps since it's a more general tool).
/r/flask
https://redd.it/89tvn5
GitHub
GitHub - cookiecutter-flask/cookiecutter-flask: A flask template with Bootstrap, asset bundling+minification with webpack, starter…
A flask template with Bootstrap, asset bundling+minification with webpack, starter templates, and registration/authentication. For use with cookiecutter. - cookiecutter-flask/cookiecutter-flask
Thumbnail in form or formset
Hi everyone,
What's the easiest way to display the image that has been uploaded to the form in addition to or rather than just the filepath of the image within a form or formset. Really struggling with this one.
Thanks!
/r/django
https://redd.it/8as2gu
Hi everyone,
What's the easiest way to display the image that has been uploaded to the form in addition to or rather than just the filepath of the image within a form or formset. Really struggling with this one.
Thanks!
/r/django
https://redd.it/8as2gu
reddit
Thumbnail in form or formset • r/django
Hi everyone, What's the easiest way to display the image that has been uploaded to the form in addition to or rather than just the filepath of...
Allowing user to add details to flask-mail message
So I have a modal on my site from which I want my user to be able to enter their email, hit submit, and then the app to message me with the users email. So far I've got the site sending a message but I'm unsure how to get the users email into the message. Any help would be much appreciated.
My code for sending the email
@app.route('/sendmail/', methods=['POST','GET'])
def send_mail():
try:
#emaiil = request.form['email']
msg = Message("Access request",
sender="SENDING_EMAIL",
recipients=["MY_EMAIL"])
msg.body = "Users email is"
mail.send(msg)
flash('Request sent!')
return redirect(url_for('main'))
except Exception, e:
return(str(e))
My modal for which the user enters their email
<div class="modal-body">
<p>Password can be obtained from somewhere</p>
<form action="{% print url_for('send_mail') %}" class ="form- inline" method="post">
<input type = "email" class = "form-control" placeholder="Email" name = "email">
<a href="/sendmail" class ="btn btn-default">Submit</a>
<button type="button" class="btn btn-secondary" data- dismiss="modal modal2">Close</button>
</form>
The modal is called from here
@app.route("/", methods=['POST','GET'])
def main():
return render_template('main.html')
/r/flask
https://redd.it/8at9sg
So I have a modal on my site from which I want my user to be able to enter their email, hit submit, and then the app to message me with the users email. So far I've got the site sending a message but I'm unsure how to get the users email into the message. Any help would be much appreciated.
My code for sending the email
@app.route('/sendmail/', methods=['POST','GET'])
def send_mail():
try:
#emaiil = request.form['email']
msg = Message("Access request",
sender="SENDING_EMAIL",
recipients=["MY_EMAIL"])
msg.body = "Users email is"
mail.send(msg)
flash('Request sent!')
return redirect(url_for('main'))
except Exception, e:
return(str(e))
My modal for which the user enters their email
<div class="modal-body">
<p>Password can be obtained from somewhere</p>
<form action="{% print url_for('send_mail') %}" class ="form- inline" method="post">
<input type = "email" class = "form-control" placeholder="Email" name = "email">
<a href="/sendmail" class ="btn btn-default">Submit</a>
<button type="button" class="btn btn-secondary" data- dismiss="modal modal2">Close</button>
</form>
The modal is called from here
@app.route("/", methods=['POST','GET'])
def main():
return render_template('main.html')
/r/flask
https://redd.it/8at9sg
reddit
Allowing user to add details to flask-mail message • r/flask
So I have a modal on my site from which I want my user to be able to enter their email, hit submit, and then the app to message me with the users...
How do you code in css without running collectstatic with each change?
How do you guys write css without collecting static on each change to see the effect?
Thanks!
/r/django
https://redd.it/8atv09
How do you guys write css without collecting static on each change to see the effect?
Thanks!
/r/django
https://redd.it/8atv09
reddit
How do you code in css without running collectstatic... • r/django
How do you guys write css without collecting static on each change to see the effect? Thanks!