<s> from nose . tools import * <EOL> import json <EOL> import httpretty <EOL> import datetime , dateutil <EOL> from tests . base import OsfTestCase <EOL> from tests . factories import ProjectFactory , UserFactory <EOL> from website . project . model import Auth , Node <EOL> from website . settings import POPULAR_LINKS_NODE , NEW_AND_NOTEWORTHY_LINKS_NODE <EOL> from scripts import populate_new_and_noteworthy_projects as script <EOL> class TestPopulateNewAndNoteworthy ( OsfTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestPopulateNewAndNoteworthy , self ) . setUp ( ) <EOL> self . pop1 = ProjectFactory ( ) <EOL> self . pop2 = ProjectFactory ( ) <EOL> self . pop3 = ProjectFactory ( ) <EOL> self . pop4 = ProjectFactory ( ) <EOL> self . pop5 = ProjectFactory ( ) <EOL> self . nn1 = ProjectFactory ( is_public = True ) <EOL> self . nn2 = ProjectFactory ( is_public = True ) <EOL> self . nn3 = ProjectFactory ( is_public = True ) <EOL> self . nn4 = ProjectFactory ( is_public = True ) <EOL> self . nn5 = ProjectFactory ( is_public = True ) <EOL> self . user = UserFactory ( ) <EOL> today = datetime . datetime . now ( ) <EOL> self . last_month = ( today - dateutil . relativedelta . relativedelta ( months = <NUM_LIT:1> ) ) . isoformat ( ) <EOL> popular_json = { "<STR_LIT>" : [ self . pop1 . _id , self . pop2 . _id , self . pop3 . _id , self . pop4 . _id , self . pop5 . _id ] } <EOL> self . popular_json_body = json . dumps ( popular_json ) <EOL> def tearDown ( self ) : <EOL> super ( TestPopulateNewAndNoteworthy , self ) . tearDown ( ) <EOL> Node . remove ( ) <EOL> def test_get_new_and_noteworthy_nodes ( self ) : <EOL> new_noteworthy = script . get_new_and_noteworthy_nodes ( ) <EOL> assert_equal ( set ( new_noteworthy ) , { self . nn1 . _id , self . nn2 . _id , self . nn3 . _id , self . nn4 . _id , self . nn5 . _id } ) <EOL> def test_populate_new_and_noteworthy ( self ) : <EOL> self . popular_links_node = ProjectFactory ( creator = self . user ) <EOL> self . popular_links_node . _id = POPULAR_LINKS_NODE <EOL> self . popular_links_node . save ( ) <EOL> self . new_and_noteworthy_links_node = ProjectFactory ( ) <EOL> self . new_and_noteworthy_links_node . _id = NEW_AND_NOTEWORTHY_LINKS_NODE <EOL> self . new_and_noteworthy_links_node . save ( ) <EOL> popular_nodes = [ self . pop1 , self . pop2 , self . pop3 , self . pop4 , self . pop5 ] <EOL> for node in popular_nodes : <EOL> self . popular_links_node . add_pointer ( node , auth = Auth ( self . user ) , save = True ) <EOL> assert_equal ( len ( self . popular_links_node . nodes ) , <NUM_LIT:5> ) <EOL> assert_equal ( len ( self . new_and_noteworthy_links_node . nodes ) , <NUM_LIT:0> ) <EOL> script . main ( dry_run = False ) <EOL> self . popular_links_node . reload ( ) <EOL> self . new_and_noteworthy_links_node . reload ( ) <EOL> assert_equal ( len ( self . popular_links_node . nodes ) , <NUM_LIT:0> ) <EOL> assert_equal ( len ( self . new_and_noteworthy_links_node . nodes ) , <NUM_LIT:5> ) <EOL> script . main ( dry_run = False ) <EOL> self . popular_links_node . reload ( ) <EOL> self . new_and_noteworthy_links_node . reload ( ) <EOL> popular_node_links = [ pointer . node . _id for pointer in self . popular_links_node . nodes ] <EOL> assert_equal ( popular_node_links , [ ] ) <EOL> new_and_noteworthy_node_links = { pointer . node . _id for pointer in self . new_and_noteworthy_links_node . nodes } <EOL> assert_equal ( set ( new_and_noteworthy_node_links ) , { self . nn1 . _id , self . nn2 . _id , self . nn3 . _id , self . nn4 . _id , self . nn5 . _id } ) </s>
