Questions tagged [django-unittest]

django-unittest tag refers to writing unit tests in Django, tests that are expressed as methods on a Python class that subclasses unittest.TestCase or Django's customized TestCase.

django-unittest tag refers to writing unit tests in Django, tests that are expressed as methods on a Python class that subclasses unittest.TestCase or Django’s customized TestCase.

329 questions
1
vote
1 answer

Why coverage is not showing error for generic views?

I am using coverage to check which unit tests to write. I'm checking in accounts/views.py, for which I haven't written any tests, but why it's not showing tests missing case(i.e in red)? I expect around 50+ statements to be in error stage, excluding…
1
vote
2 answers

Django : How to upload csv file in unit test case using APIClient

I would like to write a unit test for a view on a Django REST Framework application. The test should upload a CSV file using the POST. @staticmethod def _file_upload(client, string, args, file_name): base_path =…
Muthu Kumar
  • 885
  • 2
  • 14
  • 25
1
vote
1 answer

Get type of django model attribute

I'm writing some schema tests for django, using django's wrapper of the unittest framework. I want to check that a field is always going to be DateTimeField, rather than DateField. So I attempted the following: class TestSuite(TestCase): def…
OneRaynyDay
  • 3,658
  • 2
  • 23
  • 56
1
vote
1 answer

Django Unittest 302 response

I am trying to do a unit test for my django application. Whenever i try a get request to a particular page, it redirects me to the login page. I have logged into the web app once in setUp as shown below. I have referred to many questions such as…
Vishal Raghavan
  • 456
  • 3
  • 13
1
vote
1 answer

Test django project with native unittest lib

Is it possible not to use a unit test tool provided by Django but use native python unittest library? I know that for simple tests it works just fine. But when i involve other apps and models into the test i get various exceptions like 'apps are…
Laimonas Sutkus
  • 3,247
  • 2
  • 26
  • 47
1
vote
1 answer

How should I write view unittest in Django?

I want to write a unittest for this method in Django. def activate(request): id = int(request.GET.get('id')) user = User.objects.get(id=id) user.is_active = True user.save() return render(request,…
polix
  • 19
  • 1
1
vote
2 answers

Django Unittest runs into Error

Environment: Intellij PyCharm, Python Django, Sqlite3 I use a standard Django setup project. I try to write some Unittests, but I run into the following error. After some research, I ended up here. DB Config DATABASES = { 'default': { …
michael-mammut
  • 2,595
  • 5
  • 28
  • 46
1
vote
0 answers

How can I ensure changes to my Celery countdown wont break anything?

I have a number of celery tasks in my Django application that are currently being tested synchronously using CELERY_ALWAYS_EAGER. However this option means that I can't test that changes to the countdown value in apply_async won't break…
JKiely
  • 120
  • 1
  • 2
  • 10
1
vote
1 answer

Django Unittest fails when run parallel on CircleCI

I am running Django Unit tests on CircleCI with 1 container setup. The tests run fine when I do not add Django's --parallel argument. However, when I add --parallel=2 to the test run, it fails with this cryptic error below. I've tried both versions:…
rtindru
  • 5,107
  • 9
  • 41
  • 59
1
vote
2 answers

Django unit test not modifying database

I am creating a unit test for a view PersonRemoveView that simply modifies a datetime field called deletion_date in a model called Person. This field is None until this view is executed, then it is set to timezone.now() The problem is that the value…
juankysmith
  • 11,839
  • 5
  • 37
  • 62
1
vote
1 answer

Django upload file test returns 301

I am trying to test an API post call which allow file uploading but I cannot get it to work, I am always receiving a 301 with open('video.mp4') as f: data = {'file': f} response = self.client.post('/api/upload_file', data,…
1
vote
1 answer

Import error across entire Django project

I am getting strange error in Django when trying to run tests: [homebrewpython3] cchilders:~/projects/homebrew_app (CKC/finish-db-update-script) $ python manage.py test Creating test database for alias…
codyc4321
  • 9,014
  • 22
  • 92
  • 165
1
vote
1 answer

using self.method_name inside a class method

I'm new to OOP in Python. I'm using the unittest package for the first time. In the code below, which is from Python official documentation, when we use self.assertEqual are we calling the assertEqual method from the base class unittest.Testcase?…
adam smith
  • 27
  • 1
  • 5
1
vote
2 answers

Django testing a form is valid when it contains a ModelChoiceField

I have the following test... def test_contact_form(self): form_data = {'name': 'Reiss Johnson', 'email': 'reissjohnson@test.com', '_type': 'General Enquiry', 'content': 'This is some content'} …
Reiss Johnson
  • 1,419
  • 1
  • 13
  • 19
1
vote
0 answers

Django Test Errors

I am in the midst of writing unit tests for an application I am working on. My tests work fine on my 2012 Macbook pro but not my 2015 iMac. Both are running the latest OSX and the django version is version 1.9.1 with custom modifications that can be…
rady
  • 428
  • 5
  • 12