Questions tagged [django-tests]

Use for questions about testing applications based upon the Python web framework Django, or the features provided in the module itself (django.test)

docs: https://docs.djangoproject.com/en/2.1/topics/testing/overview/

450 questions
0
votes
0 answers

Writing a test in Django with request.user is not passing when it should

Here's what I'm trying to do. Use a mixin to validate ownership of an object. Test the detail url to make sure that request.user == obj.owner I expect the detail test to pass with a 200 assertion. But it's giving me a 302. But when I do a print…
Dave Merwin
  • 1,382
  • 2
  • 22
  • 44
0
votes
1 answer

'module' object has no attribute 'commit_unless_managed'

I am using django 1.8 and django-nose 1.4 and while I run REUSE_DB=1 python manage.py test It shows error message 'module' object has no attribute 'commit_unless_managed' What may the the solution ?
Bishnu Bhattarai
  • 2,800
  • 8
  • 36
  • 44
0
votes
0 answers

Reverse in test gives me back a 404

my test below returns a response 404. If I replace the 'party:detail' by '/party/party/1' , now it will pass. Per the documentation, I do pass the parameters correctly, so what is causing the issue? class UrlTests(TestCase): def…
vcd
  • 31
  • 1
  • 1
  • 4
0
votes
2 answers

How to test login functionality using LiveServerTestCase and Selenium in Django

I am writing test cases for a project, and want to test my login functionality. I am using LiveServerTestCase class, selenium and following this documentation in Django website [link] (https://docs.djangoproject.com/en/1.8/topics/testing/tools/). If…
python
  • 4,403
  • 13
  • 56
  • 103
0
votes
1 answer

How to test login rest api in django?

Edit2: I got Why I am getting error, password miss-match. It is due to test database does not contain username and password itself. Edit1: Following I am tried to write test cases for login api, when I write test out-side any class then it does…
Neelabh Singh
  • 2,600
  • 12
  • 51
  • 88
0
votes
1 answer

Getting error: Username and Password mismatch, when tried to test login rest api?

Following I am tried to write test cases for login api, when I write test out-side any class then it does not gives any error, But when I created class class TestCase(TestCase): and define method def test_login(self):. It gives password…
Neelabh Singh
  • 2,600
  • 12
  • 51
  • 88
0
votes
1 answer

Tests in subdirectory

In Django 1.8, I have an app with this setting: app |- tests/ | |- test_ook.py | |- __init__.py |- models.py |- __init__.py ... When I run python manage.py test -v 2 app, I get this error: ImportError: 'tests' module incorrectly imported…
Sardathrion - against SE abuse
  • 17,269
  • 27
  • 101
  • 156
0
votes
0 answers

Reusable permissions testing in django rest framework

I'm coding tests for an restful service (with DRF), I wanna tests that I don't must need to modify when permissions View change. Example: view.py class List(generics.ListAPIView): permission_classes = (IsAuthenticated, ) queryset =…
aslheyrr
  • 372
  • 1
  • 4
  • 15
0
votes
1 answer

Write test for views containing os.remove in django

I have a function based view function in django that receives an ID from a model, retrieve a file address and delete it using os.remove image = Images.objects.get(id=image_id) os.remove(image.file) the image_id is valid and is a part of my…
mmohaveri
  • 528
  • 7
  • 23
0
votes
1 answer

Django-behave - no behave tests

Does someone has expiriences with django-behave? I can not run behave tests. I have newests versions of 'behave' and 'django-behave' installed. 'django_behave' is in my INSTALLED_APPS and in my settings.py i also added TEST_RUNNER =…
krzyhub
  • 6,285
  • 11
  • 42
  • 68
0
votes
0 answers

django tastypie - Post request tests are not working

I am trying to create a POST api using tastypie. It is working fine when I am running from postman. But when I created django tests for the same, the data is not coming in request.POST instead it is coming in request.body. Is there a way to test it…
Anuj
  • 1,160
  • 2
  • 20
  • 40
0
votes
1 answer

Django 1.6 test discovery cannot find test modules

Django 1.6.10 cannot find test modules located outside my apps when running any of these code (ref: https://docs.djangoproject.com/en/1.6/topics/testing/overview/#running-tests) ./manage.py test tests/app1/ ./manage.py test…
green
  • 226
  • 2
  • 12
0
votes
1 answer

How to handle CommandError exceptions in Django tests

I'm creating a Management Command in which I raise a CommandError exception when something goes wrong. One of my test cases executes the command in a way that it will raise the exception so the result of the test is Error. How can I make it pass?
Rafael Redrado
  • 493
  • 1
  • 6
  • 19
0
votes
2 answers

django test client doesnt call POST, but GET

I try to test view calling by POST. I use follow=True. But test client uses GET method and my POST data are not passed. here is my view: def aaa(request): n = request.method d = request.POST template = 'shop/test.html' return…
Joe Bobson
  • 1,216
  • 15
  • 19
0
votes
1 answer

"Unable to login with provided credentials" (on Testing)

I'm programming a test case for user register and login, I tested whit postman (chrome) and it works but the test case doesn't. I'm using djangorestframework-jwt for authentication Test: class PublicUserTests(APITestCase): def…
aslheyrr
  • 372
  • 1
  • 4
  • 15