<s> from django . contrib . auth import get_user_model <EOL> from django . test import TestCase <EOL> import re <EOL> from test_app import models <EOL> import httpretty <EOL> from stream_django . enrich import Enrich <EOL> from stream_django . feed_manager import feed_manager <EOL> api_url = re . compile ( r'<STR_LIT>' ) <EOL> class PinTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> feed_manager . enable_model_tracking ( ) <EOL> self . User = get_user_model ( ) <EOL> self . bogus = self . User . objects . create ( ) <EOL> self . enricher = Enrich ( ) <EOL> def register_post_api ( self ) : <EOL> httpretty . register_uri ( httpretty . POST , api_url , <EOL> body = '<STR_LIT:{}>' , status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' ) <EOL> def register_delete_api ( self ) : <EOL> httpretty . register_uri ( httpretty . DELETE , api_url , <EOL> body = '<STR_LIT:{}>' , status = <NUM_LIT:200> , <EOL> content_type = '<STR_LIT:application/json>' ) <EOL> @ httpretty . activate <EOL> def test_create ( self ) : <EOL> self . register_post_api ( ) <EOL> pin = models . Pin . objects . create ( author = self . bogus ) <EOL> last_req = httpretty . last_request ( ) <EOL> req_body = last_req . parsed_body <EOL> self . assertEqual ( req_body [ '<STR_LIT>' ] , '<STR_LIT>' % pin . id ) <EOL> self . assertEqual ( req_body [ '<STR_LIT:object>' ] , '<STR_LIT>' % pin . id ) <EOL> self . assertEqual ( req_body [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( req_body [ '<STR_LIT>' ] , '<STR_LIT>' % self . bogus . id ) <EOL> @ httpretty . activate <EOL> def test_delete ( self ) : <EOL> self . register_post_api ( ) <EOL> self . register_delete_api ( ) <EOL> pin = models . Pin . objects . create ( author = self . bogus ) <EOL> pin . delete ( ) <EOL> last_req = httpretty . last_request ( ) <EOL> self . assertEqual ( last_req . method , httpretty . DELETE ) <EOL> @ httpretty . activate <EOL> def test_enrich_instance ( self ) : <EOL> self . register_post_api ( ) <EOL> pin = models . Pin . objects . create ( author = self . bogus ) <EOL> pin . save ( ) <EOL> activity = pin . create_activity ( ) <EOL> enriched_data = self . enricher . enrich_activities ( [ activity ] ) <EOL> self . assertEqual ( enriched_data [ <NUM_LIT:0> ] [ '<STR_LIT:object>' ] . id , pin . id ) <EOL> self . assertIsInstance ( enriched_data [ <NUM_LIT:0> ] [ '<STR_LIT:object>' ] , models . Pin ) <EOL> self . assertEqual ( enriched_data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] . id , pin . author_id ) <EOL> self . assertIsInstance ( enriched_data [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , self . User ) <EOL> @ httpretty . activate <EOL> def test_enrich_data_with_missing_reference ( self ) : <EOL> self . register_post_api ( ) <EOL> self . register_delete_api ( ) <EOL> pin = models . Pin . objects . create ( author = self . bogus ) <EOL> pin . save ( ) <EOL> activity = pin . create_activity ( ) <EOL> pin . delete ( ) <EOL> enriched_data = self . enricher . enrich_activities ( [ activity ] ) <EOL> self . assertFalse ( enriched_data [ <NUM_LIT:0> ] . enriched ) <EOL> self . assertIn ( '<STR_LIT:object>' , enriched_data [ <NUM_LIT:0> ] . not_enriched_data ) <EOL> self . assertDictContainsSubset ( dict ( object = activity [ '<STR_LIT:object>' ] ) , enriched_data [ <NUM_LIT:0> ] . not_enriched_data ) <EOL> self . assertEqual ( activity [ '<STR_LIT:object>' ] , enriched_data [ <NUM_LIT:0> ] [ '<STR_LIT:object>' ] ) <EOL> def test_disabled_tracking ( self ) : <EOL> feed_manager . disable_model_tracking ( ) <EOL> pin = models . Pin . objects . create ( author = self . bogus ) <EOL> pin . save ( ) <EOL> pin . delete ( ) </s>
