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

asserting an error message matches a string in Django

Is this possible? I have an custom error message and I would like to check that it is raised when a validation is not met. Can I do something similar to the following? self.assertEqual(ValidationError.message, 'name validation not met')
Reiss Johnson
  • 1,419
  • 1
  • 13
  • 19
1
vote
3 answers

Can't test password change in Django unittest

I'm trying to write an integration test for a Django application to test if the password was changed from a rest API. However, after calling the password change API, testing for the new password doesn't work. What I'm doing here is: I change the…
Ahmed
  • 2,825
  • 1
  • 25
  • 39
1
vote
1 answer

TestCase self.assertEqual does not match a similar string

I'am trying to create a model unittest for a ManyToMany relationship. The aim is to check, if there is the right category saved in the table Ingredient. class IngredientModelTest(TestCase): def test_db_saves_ingredient_with_category(self): …
1
vote
0 answers

Django unit Test-case trying to resolve custom-decorator before executing setUpModule

I'm trying to use a custom-decorator in django unit-test case "@client_login" before every test-assertion in Django-unit test-case. I was expecting that "setUpModule " should execute first then Decorator should be resolve . but Actually test-case…
1
vote
1 answer

Why timezone inside unittest in Django is different from timezone in view?

I'm using TestCase.client to test my views. And when I call timezone.now() from test case, i get 2015-11-17 07:48:26.826661+00:00, but when I call start = timezone.make_aware(datetime.strptime( date_text + ' ' + time, '%y/%m/%d…
Bunyk
  • 7,635
  • 8
  • 47
  • 79
1
vote
1 answer

How can I set up Phabricator to run my django unit tests?

It seems like it could be pretty simple to set up Arcanist to run unit tests in a Django project. But the only documentation on setting up unit tests that seems to exist says that I'll have to write a php class to extend ArcanistUnitTestEngine. I…
Brendan W
  • 3,303
  • 3
  • 18
  • 37
1
vote
1 answer

Django / DjangoRestFramework - unittest not authenticating user created using ORM

This is my test: class PageTests(APITestCase): def setUp(self): Location.objects.create(locationName = 'Location of Mine', LocationCode = 'LOM') User.objects.create(username='b', password='b', email='b@hotmail.com') def…
SilentDev
  • 20,997
  • 28
  • 111
  • 214
1
vote
0 answers

Django unittest easiest way to compare whole databases

I would like to unit test a parser which populates a database from csv files. I'm looking fo an easy method to test the parser functionality. One method which came to mind is to populate the database with ground truth values and do a database dump…
tisch
  • 1,098
  • 3
  • 13
  • 30
1
vote
2 answers

request.POST used by ModelForm with prefix not working with client.post in unit test

I try to create some Integration tests to test a view in my django project. In my view I create a ModelForm with a prefix customer_form = CustomerForm(request.POST or None, prefix="customer", instance=customer) I am trying the following code on my…
Apostolos
  • 7,763
  • 17
  • 80
  • 150
1
vote
0 answers

Django unit tests: Can I specify default label/location?

I know that when I run $ ./manage.py test then it will discover tests in any file named test*.py under the current working directory. I also know that I can specify a test label like this: $ ./manage.py test animals.tests Then all the tests in…
geckon
  • 8,316
  • 4
  • 35
  • 59
1
vote
1 answer

How do you find the form name in a Django unittest?

How do you find what Django name's a form within its context, so that you can assert tests on the form? I have a simple unittest like: def test_stuff(self): client = Client() response = client.post('/admin/app/model/add', {'name': 'Some…
Cerin
  • 60,957
  • 96
  • 316
  • 522
1
vote
5 answers

How to overwrite django app settings in unittests?

Django allows overwriting settings, when running tests through SimpleTestCase.settings() (https://docs.djangoproject.com/en/1.8/topics/testing/tools/#django.test.SimpleTestCase.settings). That works fine when I try to overwrite one of Django's…
Dunedan
  • 7,848
  • 6
  • 42
  • 52
1
vote
1 answer

Simulating responses from third party server in Django

I have a function that makes a call : GET www.thirdpartydomain.com/objectlist/ and fetches a JSON list in the following way: [ { id: 1, name: 'abc', }, { id: 2, name: 'def', } ] and then the function…
dowjones123
  • 3,695
  • 5
  • 40
  • 83
1
vote
1 answer

Django WebServer During Testing

I'm writing a complicated web application in Django. There are many components. Two in particular, are the Django server (lets call this Server), and a C++ application server (lets call this Calculator) which serves calculations to Server. When…
DrBards
  • 104
  • 6
1
vote
1 answer

Django tests - print all test failures for a series of n times the same test

I'd like that every assertion test in a TestCase is actually tested, even if the first one fails. In my situation, all the assertions are of the same nature. Actually I have something that evaluates formulas written as Python objects (figure it as…
lajarre
  • 4,910
  • 6
  • 42
  • 69