<s> from datetime import datetime <EOL> from django . conf import settings <EOL> from django . test import TransactionTestCase <EOL> from django . test . client import Client <EOL> from django . utils import simplejson as json <EOL> import pytz <EOL> from panda . models import Notification , UserProxy <EOL> from panda . tests import utils <EOL> class TestAPINotifications ( TransactionTestCase ) : <EOL> fixtures = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def setUp ( self ) : <EOL> settings . CELERY_ALWAYS_EAGER = True <EOL> utils . setup_test_solr ( ) <EOL> self . user = utils . get_panda_user ( ) <EOL> self . dataset = utils . get_test_dataset ( self . user ) <EOL> self . upload = utils . get_test_data_upload ( self . user , self . dataset ) <EOL> self . dataset . import_data ( self . user , self . upload , <NUM_LIT:0> ) <EOL> self . auth_headers = utils . get_auth_headers ( ) <EOL> self . client = Client ( ) <EOL> def test_get ( self ) : <EOL> notification = Notification . objects . all ( ) [ <NUM_LIT:0> ] <EOL> response = self . client . get ( '<STR_LIT>' % notification . id , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> body = json . loads ( response . content ) <EOL> sent_at = datetime . strptime ( body [ '<STR_LIT>' ] , "<STR_LIT>" ) . replace ( tzinfo = pytz . timezone ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( sent_at , notification . sent_at . replace ( microsecond = <NUM_LIT:0> ) ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] , None ) <EOL> self . assertEqual ( body [ '<STR_LIT:message>' ] , notification . message ) <EOL> def test_get_not_recipient ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' % self . dataset . current_task . id ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_get_unauthorized ( self ) : <EOL> UserProxy . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> notification = Notification . objects . all ( ) [ <NUM_LIT:0> ] <EOL> response = self . client . get ( '<STR_LIT>' % notification . id , ** utils . get_auth_headers ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_list ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' , data = { '<STR_LIT>' : <NUM_LIT:5> } , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertEqual ( len ( body [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:5> ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , None ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , None ) <EOL> def test_list_unauthorized ( self ) : <EOL> UserProxy . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> response = self . client . get ( '<STR_LIT>' , data = { '<STR_LIT>' : <NUM_LIT:5> } , ** utils . get_auth_headers ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> body = json . loads ( response . content ) <EOL> self . assertEqual ( len ( body [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:5> ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , None ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , None ) <EOL> def test_update ( self ) : <EOL> notification = Notification . objects . all ( ) [ <NUM_LIT:0> ] <EOL> data = json . dumps ( { '<STR_LIT>' : datetime . utcnow ( ) . strftime ( '<STR_LIT>' ) } ) <EOL> response = self . client . put ( '<STR_LIT>' % notification . id , data = data , content_type = '<STR_LIT:application/json>' , ** self . auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> notification = Notification . objects . all ( ) [ <NUM_LIT:0> ] <EOL> self . assertNotEqual ( notification . read_at , None ) <EOL> def test_update_unauthorized ( self ) : <EOL> UserProxy . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> notification = Notification . objects . all ( ) [ <NUM_LIT:0> ] <EOL> data = json . dumps ( { '<STR_LIT>' : datetime . utcnow ( ) . strftime ( '<STR_LIT>' ) } ) <EOL> response = self . client . put ( '<STR_LIT>' % notification . id , data = data , content_type = '<STR_LIT:application/json>' , ** utils . get_auth_headers ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) </s>
