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
0
votes
1 answer

Django external mysql db connection in test complains "unknown database"

In my django project I have a few database connections: eg. DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql_psycopg2", "NAME": "awesome", ... }, "other_1": { "ENGINE":…
James Lin
  • 25,028
  • 36
  • 133
  • 233
0
votes
1 answer

How to POST data to a Django Form that contains checkboxes

I have a problem when I am testing my registration form in Django. I am trying to make a POST request but I cannot select a checkbox field. self.response = self.client.post(url, { 'username': 'testuser', 'password':…
cpit
  • 147
  • 11
0
votes
1 answer

Django DRF APITestCase chain test cases

For example I want to write several tests cases like this class Test(APITestCase): def setUp(self): ....some payloads def test_create_user(self): ....create the object using payload from setUp def…
0
votes
1 answer

Django 2.1 SimpleTestCase, assertFieldOutput for DateField - AssertionError: ValidationError not raised

I have this simple Form (Django 2.1, Python 3.6.5). class RenewBookForm(forms.Form): renewal_date = forms.DateField( help_text="Enter a date between now and 4 weeks (default 3)." ) def…
Jan
  • 5
  • 4
0
votes
1 answer

Testing a Django model with custom save method calling external API

i'm pretty new to unittests and want to make some "simple" beginner tests in my Django application, I have a model with a "custom" save method that calls a external api if new. Can't figure out how to that that model without calling the external…
pkdkk
  • 3,905
  • 8
  • 44
  • 69
0
votes
1 answer

Django REST framework FileField PUT Testcase

I have a model that contains a FileField which may not be blank. When creating tests for this model, I've run into the problem that I get errors when testing with PUT, while the exact same thing works when doing a POST. As views I'm simply using…
0
votes
1 answer

Test Django url 'name' is correct url

I think what I'm trying to is self evident: urls.py urlpatterns = [ path('', views.home_page, name='home_page'), ] test.py def test_home_page_view_name_uses_correct_url(self): name = self.client.get(reverse('home_page')) path =…
Carl Brubaker
  • 1,602
  • 11
  • 26
0
votes
2 answers

Python - How to mask a class from being executed in unittest on runtime

Please see the code below. I was trying to implement a test suite for my project import unittest class TestClass1(unittest.TestCase): def test_1_first(self): print("First test case") def test_2_second(self): print("Second…
shafeeq
  • 1,499
  • 1
  • 14
  • 30
0
votes
0 answers

Why my testing view response is none?

I have a post detail view as below. class PostDetailView(AjaxResponseMixin, UpdateView): model = UserPost context_object_name = 'post' template_name = 'feed/post_detail.html' form_class = CommentForm def get_initial(self): initial_data =…
0
votes
0 answers

Django 2.0 - KeyError on View Test for Login

I'm having some problems testing my Django application. I have a view that gets information from a login form and then validate / authenticate the user, therefore redirecting him to a home view that displays various informations. I also put a…
Fsanna
  • 347
  • 1
  • 4
  • 11
0
votes
0 answers

Pass test case input and output data in html report in python

I am newbie to python and and unitesting. I am generating a report with testcase assertion input and status , but i want to show to user with testcase input data and output data in htmltestcase report PLease help me on this.
priya
  • 158
  • 5
  • 16
0
votes
0 answers

How to test my views function using Django unit testing?

I have a Django app called sample. I need to check a function inside sample app's views.py file. When I try to import the function , I get an error saying sample.views is not a package. I am trying to import the function like this : from…
Siddharth Singh
  • 105
  • 3
  • 15
0
votes
0 answers

Context manager decorator never runs __exit__ if setUp fails inside test

I'm trying to solve a bug in django. The bug involves a class called TextContextDecorator which can be used a class decorator and/or context manager. As the bug description mentions, when using TextContextDecorator as class decorator enable is…
0
votes
0 answers

Django login_required unittesting

I have a problem with template testing. Everything has worked fine until I've added a login_required decorator. Now I receive an assertion error when I testing status code and error with template load during Template Used testing. I've tried many…
0
votes
2 answers

What are alternatives to status codes that can be accessed from where a function is called? Exceptions? (Python, Django)

I would like to raise an exception in a function, and then check somewhere else (in the Django view and my unit tests) if it was raised. The following code uses status codes, and it works. But I can't figure out how to do the same thing with…
Watchduck
  • 1,076
  • 1
  • 9
  • 29