Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Basics Test Time Django TDD

Jeff Muday
Jeff Muday
Treehouse Moderator 28,717 Points

Challenge task songs/models.py views.py- insufficient info provided to know what "tests" are NOT passing. Specifics?

I have a workspace which cleanly implements the Challenge "songs" project and runs correctly, but when I paste my work into songs/models.py and songs/views.py into the challenge task windows I get a weak "Bummer! not all tests are passing." message. This is entirely non-helpful in terms of knowing what I was supposed to accomplish or where my errors were.

What tests are being run? My views and models have no problems working with the performer_detail.html that was supplied.

from django.db import models

# Create your models here.
class Performer(models.Model):
  name = models.CharField(max_length=255)

  def __str__(self):
    return self.name

class Song(models.Model):
  title = models.CharField(max_length=255)
  performer = models.ForeignKey(Performer)

  def __str__(self):
    return '{} by {}'.format(self.title,self.performer.name)
from django.shortcuts import render, get_object_or_404
from .models import Performer, Song

# Create your views here.
def song_list(request):
  songs = Song.objects.all()
  return render(request,'songs/song_list.html', {'songs' : songs})

def song_detail(request, pk):
  song = get_object_or_404(Song, pk=pk)
  return render(request, 'songs/song_detail.html', {'song' : song})

def performer_list(request):
  performers = Performer.objects.all()
  return render(request,'songs/performer_list.html', {'performers' : performers})

def performer_detail(request, pk):
  performer = get_object_or_404(Performer, pk=pk)
  return render(request, 'songs/performer_detail.html', {'performer' : performer})
{% extends 'base.html' %}

{% block title %}{{ performer }}{% endblock %}

{% block content %}
<h2>{{ performer }}</h2>
{% endblock %}

3 Answers

Jeff Muday
Jeff Muday
Treehouse Moderator 28,717 Points

The "ah ha!" moment occurred, I did not know there was a canned-workspace to use. I suggest you modify the instructions on the challenge to explicitly state there is a source workspace and have a LINK to the workspace in the instructions. I had to go back to the previous lesson to grab the workspace.

Sorry for taking up your time.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Hey Jeff, the tests being run are the song app tests in songs/tests.py. You can run these yourself locally or in workspaces using the Django manage.py test command. The test command looks for files named tests.py in each of the app directories. You can run all, some, or a single test.

Inspecting the songs/tests.py file, tests are grouped by a class definition and each test is a defined method within each class. Ignore the "setup" tests:

class PerformerModelTests(TestCase):
    def test_performer_string(self):
class SongModelTests(TestCase):
    def test_song_string(self):
class ViewTests(TestCase):
    def test_song_list_view(self):
    def test_song_detail_view(self):
    def test_performer_detail_view(self):

Starting in the "upper" karaoke directory (where manage.py is found), run tests as follows:

# Run all tests
$ python manage.py test

# run all Performer tests
$ python manage.py test songs.tests.PerformerModelTests
# run single Performer test
$ python manage.py test songs.tests.PerformerModelTests.test_performer_string

# run all Model tests
$ python manage.py test songs.tests.SongModelTests
# run single Model test
$ python manage.py test songs.tests.SongModelTests.test_song_string

# run all View tests
$ python manage.py test songs.tests.ViewTests
# run single View test
$ python manage.py test songs.tests.ViewTests.test_song_list_view
$ python manage.py test songs.tests.ViewTests.test_song_detail_view
$ python manage.py test songs.tests.ViewTests.test_performer_detail_view

For help on the test command, type "python manage.py test --help"

A useful command switch:

  --failfast            Tells Django to stop running the test suite after
                        first failed test.

Good Luck!

Jeff Muday
Jeff Muday
Treehouse Moderator 28,717 Points

Thanks for taking the time to respond. I am still a little in the dark about the specific tests that fail. Thank you for suppling a skeletal (scaffold-like) file of songs/test.py. But I was hoping to be prompted on which tests were failing, or at least, some pseudocode or instructions as to what was expected in testing of the classes. I can write my own tests, that is not a problem, but I can't tell what the evaluation expectations of the code-challenge are.

Here is specifically the way I see this challenge-- I supply the code for the TWO files songs/models.py, songs/views.py, given that songs/templates/songs/performer_detail.html is GIVEN to me. When I press submit, I expect that there is a text parser script that runs and returns an evaluation. But when I submit I get some relatively weak feedback about tests.

The bottom line is this: I am supposed to be supplying MORE files? Thanks for the tests.py scaffold you showed me above--though if I complete that in my workspace, how are these files to be included in the code challenge?