<s> from datetime import datetime , timedelta <EOL> from nose import tools as nt <EOL> from tests . base import OsfTestCase <EOL> from tests . factories import CommentFactory , AuthUserFactory <EOL> from website . project . model import Comment <EOL> from scripts import migrate_spam <EOL> class TestMigrateSpam ( OsfTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestMigrateSpam , self ) . setUp ( ) <EOL> self . generic_report = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:text>' : '<STR_LIT>' , <EOL> '<STR_LIT:date>' : datetime . utcnow ( ) , <EOL> '<STR_LIT>' : False <EOL> } <EOL> Comment . remove ( ) <EOL> self . user = AuthUserFactory ( ) <EOL> self . comment_1 = CommentFactory ( ) <EOL> self . comment_1 . spam_status = <NUM_LIT:0> <EOL> self . comment_1 . reports [ self . user . _id ] = self . generic_report <EOL> self . comment_1 . save ( ) <EOL> self . comment_2 = CommentFactory ( ) <EOL> self . comment_2 . spam_status = <NUM_LIT:0> <EOL> self . comment_2 . reports [ self . user . _id ] = self . generic_report <EOL> self . comment_2 . save ( ) <EOL> self . comment_3 = CommentFactory ( ) <EOL> self . comment_3 . spam_status = <NUM_LIT:0> <EOL> self . comment_3 . save ( ) <EOL> self . comment_4 = CommentFactory ( ) <EOL> self . comment_4 . date_last_reported = None <EOL> self . comment_4 . spam_status = Comment . FLAGGED <EOL> self . comment_4 . reports [ self . user . _id ] = self . generic_report <EOL> self . comment_4 . save ( ) <EOL> self . comment_5 = CommentFactory ( ) <EOL> self . comment_5 . date_last_reported = None <EOL> self . comment_5 . spam_status = Comment . UNKNOWN <EOL> self . comment_5 . save ( ) <EOL> self . comment_6 = CommentFactory ( ) <EOL> self . comment_6 . date_last_reported = None <EOL> self . comment_6 . spam_status = Comment . SPAM <EOL> self . comment_6 . reports [ self . user . _id ] = self . generic_report <EOL> self . comment_6 . save ( ) <EOL> def test_get_status_targets ( self ) : <EOL> targets = migrate_spam . get_no_status_targets ( ) <EOL> nt . assert_equal ( len ( targets ) , <NUM_LIT:3> ) <EOL> def test_get_latest_targets ( self ) : <EOL> migrate_spam . migrate_status ( migrate_spam . get_no_status_targets ( ) ) <EOL> targets = migrate_spam . get_no_latest_targets ( ) <EOL> nt . assert_equal ( len ( targets ) , <NUM_LIT:4> ) <EOL> def test_migrate_status ( self ) : <EOL> migrate_spam . migrate_status ( migrate_spam . get_no_status_targets ( ) ) <EOL> self . comment_2 . reload ( ) <EOL> self . comment_1 . reload ( ) <EOL> self . comment_3 . reload ( ) <EOL> nt . assert_equal ( self . comment_1 . spam_status , Comment . FLAGGED ) <EOL> nt . assert_equal ( self . comment_2 . spam_status , Comment . FLAGGED ) <EOL> nt . assert_equal ( self . comment_3 . spam_status , Comment . UNKNOWN ) <EOL> def test_migrate_latest ( self ) : <EOL> migrate_spam . migrate_status ( migrate_spam . get_no_status_targets ( ) ) <EOL> migrate_spam . migrate_latest ( migrate_spam . get_no_latest_targets ( ) ) <EOL> date = self . generic_report [ '<STR_LIT:date>' ] <EOL> self . comment_4 . reload ( ) <EOL> self . comment_6 . reload ( ) <EOL> nt . assert_almost_equal ( <EOL> self . comment_4 . date_last_reported , date , <EOL> delta = timedelta ( microseconds = <NUM_LIT:1000> ) <EOL> ) <EOL> nt . assert_almost_equal ( <EOL> self . comment_6 . date_last_reported , date , <EOL> delta = timedelta ( microseconds = <NUM_LIT:1000> ) <EOL> ) </s>
