title: Django testing user model fails but it works in the browser
body: <p>I am new to testing and am trying to run the following tests but I get a <em>404 assertion error</em> because the method that tries to reverse the url cannot find the <strong>category</strong> that had been created in the <strong>setUp</strong> method. I can create <strong>categories</strong> in the browser using the <strong>superuser</strong> with no problem and the url responds with 200 status. Could you help me understand what I am doing wrong?</p>
  
  <p><strong>Test:</strong></p>
  
  <pre><code>from __future__ import unicode_literals
  from django.core.urlresolvers import reverse
  from django.test import TestCase
  from django.contrib.auth.models import User
  from cataloger.models import Category
  
  class CatalogerCategoriesTests(TestCase):
  
      def setUp(self):
         tom = User.objects.create_user(username="tom", password="1234567")
         Category.objects.create(name="cell phone", 
                              description="current cell phone types in the market.",
                              created_by=tom)
  
      def test_category_page_success_status_code(self):
         url = reverse('category_items', kwargs={'pk': 1})
         response = self.client.get(url)
         self.assertEquals(response.status_code, 200)
  </code></pre>
  
  <p><strong>Fail:</strong></p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/ubuntu/workspace/cataloger/tests_categories.py", line 48, in test_category_page_success_status_code
      self.assertEquals(response.status_code, 200)
  AssertionError: 404 != 200
  </code></pre>
  
  <p><strong>Models:</strong></p>
  
  <pre><code># -*- coding: utf-8 -*-
  from __future__ import unicode_literals
  
  from django.db import models
  from django.contrib.auth.models import User
  
  
  class Category(models.Model):
      name = models.CharField(max_length=50)
      description = models.CharField(max_length=300)
      created_at = models.DateTimeField(auto_now_add=True)
      updated_at = models.DateTimeField(null=True)
      created_by = models.ForeignKey(User, related_name="categories")
  </code></pre>
  
  <p><strong>Views:</strong></p>
  
  <pre><code>from django.shortcuts import render, redirect, get_object_or_404
  from django.contrib.auth.models import User
  from cataloger.models import Category
  
  def category_items(request, pk):
      category = get_object_or_404(Category, pk=pk)
      return render(request, 'category_items.html', {'category': category})
  </code></pre>
  
  <p><strong>urls:</strong></p>
  
  <pre><code>from django.conf.urls import url
  from . import views
  
  urlpatterns = [
          url(r'^cataloger/$', views.cataloger, name='cataloger'),
          url(r'^cataloger/categories/(?P&lt;pk&gt;\d+)/$', views.category_items, name='category_items')
      ]
  </code></pre>