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

Mocking a decorator in one Django app

I want to test if a views decorator works properly if a proper view is called So, here's decorator get_object and view features are in myapp.views. @get_object def features(request, object): return {} I try mocking this: new_view =…
culebrón
  • 34,265
  • 20
  • 72
  • 110
1
vote
2 answers

Django Reverse Inverse

Is there an inverse method for Django's django.core.urlresolvers.reverse()? I want a function f(x) such that f(django.core.urlresolvers.reverse('shadowfax')) == 'shadowfax'. Does anybody have anything to say on whether this would be a proper…
1
vote
0 answers

Running selenium tests on dependent projects

I have two Django projects (project A and project B) that use the same codebase and have separate settings files (we use the contrib.sites framework). The projects also use the same database. Project A depends on project B: If a user wants to login…
ppetrid
  • 3,745
  • 27
  • 29
1
vote
0 answers

django unit-test login user causes "duplicate entry" error

I have the following test Class FriendsTest(TestCase): # always login user def setUp(self): self.user = User.objects.all().order_by('date_joined')[0] self.client.login(facebook_id = self.user.get_profile().facebook_id) …
Rui Xia
  • 175
  • 4
  • 20
1
vote
2 answers

Django Unit Testing: CSS selectors to test HTML?

There's something I discovered about the Rails framework which I really like, the ability to test the output of templates really easily with css selector, for example test how many "li" elements are in a page, if an element with a certain ID is…
nemesisdesign
  • 8,159
  • 12
  • 58
  • 97
1
vote
0 answers

Django Unit Test fails project-wide but passes app-wide

I'm using Django 1.4 with Python 2.7 on Ubuntu 12.10. I have a project with several apps and dozens of unit tests. We've recently run into a little issue using the @override_settings decorator. Here is some…
Rico
  • 5,692
  • 8
  • 46
  • 63
1
vote
1 answer

Logging in using django-social-auth in a django unittest

I'm writing a test suite for a django project which needs to login via django-social-auth (its facebook backend) in order to access the website. The method I'm taking now is: for each test: create a test user using facebook API use selenium to…
AmirW
  • 816
  • 9
  • 20
1
vote
1 answer

Good approach/design to unittest django application

My django application is having a handler for each functionality (e.g. Salesinvoice handler for create/save/retrieve the invoice models with validation). These handlers are used in the views to perform the action user wanted (e.g. Create…
18bytes
  • 5,951
  • 7
  • 42
  • 69
1
vote
1 answer

Django - Timestamp Unit Test

My application provides a status depending on the date and time of day that is provided as input to a custom URL. Normally it will use the current time (datetime.now()), but I'd like to create unit tests to verify future times. However, I'm having…
user496650
1
vote
1 answer

How does django/sqllite3 build database for testing?

Hi I'm attempting to write some unittests for my django web application but I'm running into some database problems when trying to run my tests. I'm using Factory Boy in some places in order to create instances for the tests…
bgrantdev
  • 1,622
  • 4
  • 17
  • 29
0
votes
2 answers

django 1.4c1 unit test looks for 'other' database

In order to pass the unit tests running on a fresh install of django trunk (1.4c1), it is necessary to add in a 'dummy' other database in settings.py, like this:- DATABASES = { 'default': { 'ENGINE':…
Calvin Cheng
  • 35,640
  • 39
  • 116
  • 167
0
votes
1 answer

jwt decode giving empty username in django unittest while using request.META

I am generating the token as follows: class LoginView(APIView): @swagger_auto_schema(request_body=UserSerializer) def post(self, request): username = request.data['email'] password = request.data['password'] user =…
0
votes
1 answer

cannot static file through static url using django.test.client

1.env python : 3.8.14 django version : '4.2.4' 2.Purpose Make sure that the static file is saved Make sure that the static file can be accessed from the web browser 3.Issue The problem is that after running django server, the static file can be…
Soulduck
  • 569
  • 1
  • 6
  • 17
0
votes
1 answer

How can I mock dynamic attributes using django test case?

I have some functionality that makes a request to a third party. Within that request are some values that are dynamically created—for example, a date. # example.py ... payload = json.dumps({ 'id': uuid.uuid4(), 'name': 'example', …
Damon
  • 4,151
  • 13
  • 52
  • 108
0
votes
0 answers

Testing Django Model Form with Overridden Save Method and Custom Email Sending Function

I'm trying to test a Django model form that overrides the save method and implements a custom send_mail function. The send_mail function uses loader.render_to_string to generate an email body and then calls a custom send_email function to send the…