<s> from nose . tools import * <EOL> from framework import sessions <EOL> from framework . flask import request <EOL> from website . models import Session <EOL> from website . addons . osfstorage . tests import factories <EOL> from website . addons . osfstorage import utils <EOL> from website . addons . osfstorage . tests . utils import StorageTestCase <EOL> class TestSerializeRevision ( StorageTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestSerializeRevision , self ) . setUp ( ) <EOL> self . path = '<STR_LIT>' <EOL> self . record = self . node_settings . get_root ( ) . append_file ( self . path ) <EOL> self . versions = [ <EOL> factories . FileVersionFactory ( creator = self . user ) <EOL> for __ in range ( <NUM_LIT:3> ) <EOL> ] <EOL> self . record . versions = self . versions <EOL> self . record . save ( ) <EOL> def test_serialize_revision ( self ) : <EOL> sessions . sessions [ request . _get_current_object ( ) ] = Session ( ) <EOL> utils . update_analytics ( self . project , self . record . _id , <NUM_LIT:0> ) <EOL> utils . update_analytics ( self . project , self . record . _id , <NUM_LIT:0> ) <EOL> utils . update_analytics ( self . project , self . record . _id , <NUM_LIT:2> ) <EOL> expected = { <EOL> '<STR_LIT:index>' : <NUM_LIT:1> , <EOL> '<STR_LIT:user>' : { <EOL> '<STR_LIT:name>' : self . user . fullname , <EOL> '<STR_LIT:url>' : self . user . url , <EOL> } , <EOL> '<STR_LIT:date>' : self . versions [ <NUM_LIT:0> ] . date_created . isoformat ( ) , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> } <EOL> observed = utils . serialize_revision ( <EOL> self . project , <EOL> self . record , <EOL> self . versions [ <NUM_LIT:0> ] , <EOL> <NUM_LIT:0> , <EOL> ) <EOL> assert_equal ( expected , observed ) <EOL> assert_equal ( self . record . get_download_count ( ) , <NUM_LIT:3> ) <EOL> assert_equal ( self . record . get_download_count ( version = <NUM_LIT:2> ) , <NUM_LIT:1> ) <EOL> assert_equal ( self . record . get_download_count ( version = <NUM_LIT:0> ) , <NUM_LIT:2> ) <EOL> def test_anon_revisions ( self ) : <EOL> sessions . sessions [ request . _get_current_object ( ) ] = Session ( ) <EOL> utils . update_analytics ( self . project , self . record . _id , <NUM_LIT:0> ) <EOL> utils . update_analytics ( self . project , self . record . _id , <NUM_LIT:0> ) <EOL> utils . update_analytics ( self . project , self . record . _id , <NUM_LIT:2> ) <EOL> expected = { <EOL> '<STR_LIT:index>' : <NUM_LIT:2> , <EOL> '<STR_LIT:user>' : None , <EOL> '<STR_LIT:date>' : self . versions [ <NUM_LIT:0> ] . date_created . isoformat ( ) , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> } <EOL> observed = utils . serialize_revision ( <EOL> self . project , <EOL> self . record , <EOL> self . versions [ <NUM_LIT:0> ] , <EOL> <NUM_LIT:1> , <EOL> anon = True <EOL> ) <EOL> assert_equal ( expected , observed ) </s>
