<s> from django . http import Http404 <EOL> from django . shortcuts import get_object_or_404 , get_list_or_404 <EOL> from django . test import TestCase <EOL> from models import Author , Article <EOL> class GetObjectOr404Tests ( TestCase ) : <EOL> def test_get_object_or_404 ( self ) : <EOL> a1 = Author . objects . create ( name = "<STR_LIT>" ) <EOL> a2 = Author . objects . create ( name = "<STR_LIT>" ) <EOL> self . assertRaises ( Http404 , get_object_or_404 , Article , title = "<STR_LIT>" ) <EOL> article = Article . objects . create ( title = "<STR_LIT>" ) <EOL> article . authors = [ a1 , a2 ] <EOL> self . assertEqual ( <EOL> get_object_or_404 ( Article , title__contains = "<STR_LIT>" ) , <EOL> article <EOL> ) <EOL> self . assertEqual ( <EOL> get_object_or_404 ( a1 . article_set , title__contains = "<STR_LIT>" ) , <EOL> article <EOL> ) <EOL> self . assertRaises ( Http404 , <EOL> get_object_or_404 , a1 . article_set , title__contains = "<STR_LIT>" <EOL> ) <EOL> self . assertEqual ( <EOL> get_object_or_404 ( Article . by_a_sir , title = "<STR_LIT>" ) , <EOL> article <EOL> ) <EOL> self . assertEqual ( <EOL> get_object_or_404 ( Article . objects . all ( ) , title__contains = "<STR_LIT>" ) , <EOL> article <EOL> ) <EOL> self . assertRaises ( Author . MultipleObjectsReturned , <EOL> get_object_or_404 , Author . objects . all ( ) <EOL> ) <EOL> self . assertRaises ( Http404 , <EOL> get_object_or_404 , Article . objects . none ( ) , title__contains = "<STR_LIT>" <EOL> ) <EOL> self . assertEqual ( <EOL> get_list_or_404 ( a1 . article_set , title__icontains = "<STR_LIT>" ) , <EOL> [ article ] <EOL> ) <EOL> self . assertRaises ( Http404 , <EOL> get_list_or_404 , a1 . article_set , title__icontains = "<STR_LIT>" <EOL> ) <EOL> self . assertEqual ( <EOL> get_list_or_404 ( Article . by_a_sir , title__icontains = "<STR_LIT>" ) , <EOL> [ article ] <EOL> ) <EOL> self . assertEqual ( <EOL> get_list_or_404 ( Article . objects . all ( ) , title__icontains = "<STR_LIT>" ) , <EOL> [ article ] <EOL> ) </s>
