473,287 Members | 1,880 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Writing Django Unit Tests

1 Bit
I am relatively new to Django and very new to writing unit tests. I'd like to ask for assistance but I'm a bit stuck with where to even begin. The app I'm working with allows a teacher to assign multiple assignments to a student. On the student dashboard, an assignment should only be available if the start date <= today's date. The student should only see the first assignment in the list.

I need to compose a unit test to cover this scenario:
  • manually assign multiple assignments to a student
  • use the same query that is used for the student dashboard to ensure that the only assignments returned are the ones with a start date <= today's date
  • ensure that the student only sees the first assignment (with the earliest start date) in the list.
Below I have posted the relevant code that is pulling what displays on the student dashboard. Please let me know if additional code is needed to help me get started with this. Thanks very much for any help you can offer!

Note: I would like to only use the built in django.test features for now, if possible

from my home/views.py file

Expand|Select|Wrap|Line Numbers
  1. @login_required
  2. def index(request):
  3.     user_type = request.user.type.text
  4.     if user_type == 'Student':
  5.         """ Only return the first test so the student sees one test at a time"""
  6.  
  7.         assignment = Assignment.objects.filter(
  8.             student=request.user,
  9.             start_date__lte=datetime.date.today(),
  10.             completed=False).first()
  11.  
  12.         if (assignment):
  13.             context = {
  14.                 'test_pk': assignment.test.pk,
  15.             }
  16.         else:
  17.             context = {}
  18.         return render(request, 'home/student.html', context)
  19.  
  20.  
Sep 16 '21 #1
0 2407

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Chris Burgess | last post by:
I'm starting a small application to get my feet wet with Test Driven Development. I understand the mechanics of setting up NUnit, but I'm not sure what types of tests I should be writing. The...
2
by: Ben Finney | last post by:
Howdy all, My practice when writing unit tests for a project is to make 'test/' subdirectories for each directory containing modules I want to test. project-foo/ +-- lib/ | +-- test/ +--...
6
by: Ben Finney | last post by:
Howdy all, Summary: I'm looking for idioms in unit tests for factoring out repetitive iteration over test data. I explain my current practice, and why it's unsatisfactory. When following...
6
by: Jeremy | last post by:
I understand what a unit test is. No problem there. What I'm wondering is what, specifically, do most of you more experienced developers mean by "writing" a unit test. Am I correct to believe...
6
by: Michael Bray | last post by:
I've just inherited a fairly large project with multiple classes. The developer also wrote a huge number of unit tests (using NUnit) to validate that the classes work correctly. However, I don't...
7
by: Andrew Ducker | last post by:
I'm writing some unit tests, to make sure that my windows forms code works properly after refactoring, and I've bumped into a problem - Messagebox.show. There are a couple of places where my...
1
by: Richard Lewis Haggard | last post by:
We're using VS05 and today the units tests have stopped working in our development environment. I'm sure that it is something really silly and simple but I'll be darned if I can figure out what it...
5
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
I'm working in Visual Studio 2005 Team Edition for Software Developers I've used the wizard under the Test menu to create a bunch of unit tests. When I click "Test -Start Selected Test Project...
0
by: Jordan S. | last post by:
Okay so I've finally "seen the Light" about writing automated unit tests ahead of time. Question: What is a very simple approach that I can use to setting up automated unit tests, considering...
0
by: naziashahabudin | last post by:
Need to write unit tests for the attached python module. Wanted to create mock objects for logger concept. need help in creating and using logger mock objects for writing unit tests for display...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.