#NEWLINE# def test_all( self ) : #NEWLINE# #INDENT# account = Account . objects . get ( id = 1 ) #NEWLINE# self . assertEqual ( account . id , 1 ) #NEWLINE# self . assertEqual ( account . email , 'john@example.com' ) #NEWLINE# account = Account . objects . get ( email = 'paul@example.com' ) #NEWLINE# self . assertEqual ( account . id , 2 ) #NEWLINE# self . assertEqual ( account . email , 'paul@example.com' ) #NEWLINE# accounts = Account . objects . all ( ) #NEWLINE# self . assertEqual ( accounts . count ( ) , 2 ) #NEWLINE# self . assertEqual ( accounts [ 0 ] . id , 1 ) #NEWLINE# self . assertEqual ( accounts [ 0 ] . email , 'john@example.com' ) #NEWLINE# self . assertEqual ( accounts [ 1 ] . id , 2 ) #NEWLINE# self . assertEqual ( accounts [ 1 ] . email , 'paul@example.com' ) #NEWLINE# accounts = Account . objects . filter ( email = 'paul@example.com' ) #NEWLINE# self . assertEqual ( accounts . count ( ) , 1 ) #NEWLINE# self . assertEqual ( accounts [ 0 ] . id , 2 ) #NEWLINE# self . assertEqual ( accounts [ 0 ] . email , 'paul@example.com' ) #NEWLINE# reporter = Reporter . objects . get ( id = 1 ) #NEWLINE# self . assertEqual ( reporter . first_name , 'John' ) #NEWLINE# self . assertEqual ( reporter . account . id , 1 ) #NEWLINE# self . assertEqual ( reporter . account . email , 'john@example.com' ) #NEWLINE# articles = reporter . articles . all ( ) #NEWLINE# self . assertEqual ( articles . count ( ) , 2 ) #NEWLINE# self . assertEqual ( articles [ 0 ] . id , 1 ) #NEWLINE# self . assertEqual ( articles [ 0 ] . headline , "John's first story" ) #NEWLINE# self . assertEqual ( articles [ 1 ] . id , 2 ) #NEWLINE# self . assertEqual ( articles [ 1 ] . headline , "John's second story" ) #NEWLINE# article = Article . objects . get ( id = 1 ) #NEWLINE# self . assertEqual ( article . reporter . id , 1 ) #NEWLINE# self . assertEqual ( article . reporter . first_name , 'John' ) #NEWLINE# tags = articles [ 0 ] . tags . all ( ) #NEWLINE# self . assertEqual ( tags . count ( ) , 2 ) #NEWLINE# self . assertEqual ( tags [ 0 ] . id , 1 ) #NEWLINE# self . assertEqual ( tags [ 0 ] . label , 'news' ) #NEWLINE# self . assertEqual ( tags [ 1 ] . id , 2 ) #NEWLINE# self . assertEqual ( tags [ 1 ] . label , 'january' ) #NEWLINE# tag = Tag . objects . get ( id = 1 ) #NEWLINE# self . assertEqual ( tag . label , 'news' ) #NEWLINE# articles = tag . articles . all ( ) #NEWLINE# self . assertEqual ( articles . count ( ) , 3 ) #NEWLINE# self . assertEqual ( articles [ 0 ] . id , 1 ) #NEWLINE# self . assertEqual ( articles [ 0 ] . headline , "John's first story" ) #NEWLINE# self . assertEqual ( articles [ 1 ] . id , 2 ) #NEWLINE# self . assertEqual ( articles [ 1 ] . headline , "John's second story" ) #NEWLINE# self . assertEqual ( articles [ 2 ] . id , 3 ) #NEWLINE# self . assertEqual ( articles [ 2 ] . headline , "Paul's story" ) #NEWLINE# new_account = Account ( ) #NEWLINE# new_account . email = 'peter@example.com' #NEWLINE# new_account . save ( ) #NEWLINE# self . assertIsNotNone ( new_account . id ) #NEWLINE# accounts = Account . objects . all ( ) #NEWLINE# self . assertEqual ( accounts . count ( ) , 3 ) #NEWLINE# self . assertEqual ( accounts [ 0 ] . email , 'john@example.com' ) #NEWLINE# self . assertEqual ( accounts [ 1 ] . email , 'paul@example.com' ) #NEWLINE# self . assertEqual ( accounts [ 2 ] . email , 'peter@example.com' ) #NEWLINE# new_account . delete ( ) #NEWLINE# self . assertIsNone ( new_account . pk ) #NEWLINE# accounts = Account . objects . all ( ) #NEWLINE# self . assertEqual ( accounts . count ( ) , 2 ) #NEWLINE# count_accounts = Account . objects . count ( ) #NEWLINE# count_reporters = Reporter . objects . count ( ) #NEWLINE# count_articles = Article . objects . count ( ) #NEWLINE# new_account = Account ( ) #NEWLINE# new_account . email = 'james@example.com' #NEWLINE# new_account . save ( ) #NEWLINE# new_reporter = Reporter ( ) #NEWLINE# new_reporter . account = new_account #NEWLINE# new_reporter . first_name = 'James' #NEWLINE# new_reporter . last_name = 'Doe' #NEWLINE# new_reporter . save ( ) #NEWLINE# new_article = Article ( ) #NEWLINE# new_article . headline = "James's story" #NEWLINE# new_article . reporter = new_reporter #NEWLINE# self . assertRaises ( ROAException , new_article . save ) #NEWLINE# new_article . pub_date = now ( ) . date ( ) #NEWLINE# new_article . save ( ) #NEWLINE# self . assertEqual ( Account . objects . count ( ) , ( count_accounts + 3 ) ) #NEWLINE# self . assertEqual ( Reporter . objects . count ( ) , ( count_reporters + 2 ) ) #NEWLINE# self . assertEqual ( Article . objects . count ( ) , ( count_articles + 1 ) ) #NEWLINE# article = Article . objects . get ( headline = "James's story" ) #NEWLINE# self . assertEqual ( article . reporter . first_name , 'James' ) #NEWLINE# self . assertEqual ( article . reporter . account . email , 'james@example.com' )