472,353 Members | 1,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 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 2271

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...
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...
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,...
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...
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...
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 -...
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...
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....
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...
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...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.