Questions tagged [django-testing]

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. This tag is about writing and running tests for your Django apps.

Django

Testing overview

Testing a Web application is a complex task, because a Web application is made of several layers of logic – from HTTP-level request handling, to form validation and processing, to template rendering. With Django’s test-execution framework and assorted utilities, you can simulate requests, insert test data, inspect your application’s output and generally verify your code is doing what it should be doing.

1023 questions
0
votes
1 answer

How to generate a unit tests in Django

I read the official doc for generating the unit tests but it is too messy. I have to generate a unit test cases for the AdminPasswordChangeForm, and two defined function in views.py which are changing the status of is_staff and is_active. I have…
Amit Pal
  • 9,143
  • 23
  • 64
  • 141
0
votes
2 answers

Python: What's the right way to make modules visible to a TestRunner?

after watching a couple of presentations about django testing, I want to code my own TestRunner in order to skip django tests, and create better packages structures for my tests. The problem is that we've changed the project structure and the test…
santiagobasulto
  • 10,542
  • 9
  • 61
  • 85
0
votes
1 answer

Using completely project-independent settings for testing

I'm trying to test an app that creates some custom permissions during intialization. These are created right after database creation: custom_permissions = getattr(settings,'SOMEAPP_PERMISSIONS',() ) def create_custom_permissions(sender, **kwargs): …
marue
  • 5,010
  • 6
  • 34
  • 62
0
votes
1 answer

Unit testing in Django

Let's suppose I do some change to a function in the tests.py file, like monkey patching the clean method of some form... When all the tests are finished, will that method still have associated the function I assigned? A concrete example (to avoid…
Oscar Mederos
  • 26,873
  • 20
  • 76
  • 120
0
votes
1 answer

Cannot create test suite for Django

I'm having trouble creating a test suite in Django 1.3. Say I have an installed app in a directory called app_name. One of the files in that directory is foo.py which defines a class named Foo. I want to test that, so I also have a file that…
shadowmatter
  • 1,292
  • 1
  • 18
  • 30
-1
votes
1 answer

Django test __str__(self) for ForeignKey

So I have this ForeignKey in my class Adress: class Adresse(models.Model): place = models.ForeignKey('Place', on_delete = models.CASCADE) def __str__(self): return self.place.city The ForeignKey comes from the Model Place: class…
-1
votes
1 answer

Django Test: type object has no attribute 'objects'

In my web application, I have locations and respective opening hours. The OpeningHours model looks as follows: class OpeningHours(models.Model): location = models.ForeignKey( Location, related_name='hours', on_delete=models.CASCADE) …
Simon
  • 312
  • 2
  • 12
-1
votes
2 answers

How to write a TestCase for user login

I should test login functionality for this Django project, but it seems it can't login properly. This is the login method on views.py def login_request(request): if request.method == "POST": form = AuthenticationForm(request, data=request.POST) …
-1
votes
1 answer

Test password protected page django

I want to write test cases about password-protected pages. I have /management/edit page. it is loginrequired page. My test case currently likes below, but it is failed. I am expecting to get 200 but instead of I got redirection(302) Tests.py from…
sevdimali
  • 349
  • 3
  • 10
-1
votes
1 answer

django redirect test - AssertionError: 302 != 200 : Couldn't retrieve content: Response code was 302 (expected 200)

I can't get my test to accept the redirect works... I keep getting this error "AssertionError: 302 != 200 : Couldn't retrieve content: Response code was 302 (expected 200)" but the redirect working logs web_1 | [11/Oct/2020 12:41:33] "GET…
-1
votes
2 answers

Django TestCase object has no attribute 'login'

I have used selenium to test my login method and it works fine. Then, I tried to test other parts of the website. So, I needed to create a user in my test. To do that, I've used client instead of request factory (since there are middleware…
EarlyCoder
  • 977
  • 1
  • 12
  • 27
-1
votes
1 answer

Is there a better way to write these tests?

So basically, the test works, it says OK when I put into the console python3 manage.py test apps/diary but the thing is that, when I check other sources, especially W.S. Vincent's(https://wsvincent.com/) way of doing tests, it's quite cleaner; it…
-1
votes
1 answer

writing unit test for many to many model in django program

in my django projects, I have a two class like following: class DataTag(models.Model): title = models.CharField(max_length=120, unique=True) relations = models.ManyToManyField('DataTag', related_name='related_data_tags', blank=True) and the another…
m.ar
  • 33
  • 5
-1
votes
1 answer

Fail in test of function, it doesn't update database

There is my function: views.py def save(request): data = {'mark':request.POST.get('mark'), 'task':request.POST.get('task')} Task.objects.filter(id=request.POST.get('s')).update(mark=data['mark'], task=data['task']) return…
JDxun
  • 1
  • 1
-1
votes
2 answers

How to initialize test database in django?

I am writing a test cases for my project written in django, it's giving an unexpected output that looks like {u'message': u'', u'result': {u'username': u'john', u'user_fname': u'', u'user_lname': u'', u'cur_time': 1442808291000.0, u'dofb': None,…
geeks
  • 1,833
  • 3
  • 28
  • 46
1 2 3
68
69