<s> """<STR_LIT>""" <EOL> import json <EOL> from django . test import TestCase <EOL> from django . test . client import Client <EOL> from django . test . utils import override_settings <EOL> from django . core . urlresolvers import reverse <EOL> from django . contrib . auth . models import User as DjangoUser <EOL> from treeio . core . models import User , Group , Perspective , ModuleSetting , Object <EOL> from treeio . events . models import Event <EOL> from datetime import datetime <EOL> @ override_settings ( HARDTREE_API_AUTH_ENGINE = '<STR_LIT>' ) <EOL> class EventsViewsTest ( TestCase ) : <EOL> "<STR_LIT>" <EOL> username = "<STR_LIT>" <EOL> password = "<STR_LIT>" <EOL> prepared = False <EOL> authentication_headers = { "<STR_LIT>" : "<STR_LIT:application/json>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } <EOL> content_type = '<STR_LIT:application/json>' <EOL> def setUp ( self ) : <EOL> "<STR_LIT>" <EOL> if not self . prepared : <EOL> Object . objects . all ( ) . delete ( ) <EOL> try : <EOL> self . group = Group . objects . get ( name = '<STR_LIT:test>' ) <EOL> except Group . DoesNotExist : <EOL> Group . objects . all ( ) . delete ( ) <EOL> self . group = Group ( name = '<STR_LIT:test>' ) <EOL> self . group . save ( ) <EOL> try : <EOL> self . user = DjangoUser . objects . get ( username = self . username ) <EOL> self . user . set_password ( self . password ) <EOL> try : <EOL> self . profile = self . user . profile <EOL> except Exception : <EOL> User . objects . all ( ) . delete ( ) <EOL> self . user = DjangoUser ( username = self . username , password = '<STR_LIT>' ) <EOL> self . user . set_password ( self . password ) <EOL> self . user . save ( ) <EOL> except DjangoUser . DoesNotExist : <EOL> User . objects . all ( ) . delete ( ) <EOL> self . user = DjangoUser ( username = self . username , password = '<STR_LIT>' ) <EOL> self . user . set_password ( self . password ) <EOL> self . user . save ( ) <EOL> try : <EOL> perspective = Perspective . objects . get ( name = '<STR_LIT:default>' ) <EOL> except Perspective . DoesNotExist : <EOL> Perspective . objects . all ( ) . delete ( ) <EOL> perspective = Perspective ( name = '<STR_LIT:default>' ) <EOL> perspective . set_default_user ( ) <EOL> perspective . save ( ) <EOL> ModuleSetting . set ( '<STR_LIT>' , perspective . id ) <EOL> self . event = Event ( name = '<STR_LIT>' , end = datetime . now ( ) ) <EOL> self . event . set_default_user ( ) <EOL> self . event . save ( ) <EOL> self . client = Client ( ) <EOL> self . prepared = True <EOL> def test_unauthenticated_access ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> def test_get_events_list ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( <EOL> path = reverse ( '<STR_LIT>' ) , ** self . authentication_headers ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> def test_get_field ( self ) : <EOL> response = self . client . get ( path = reverse ( <EOL> '<STR_LIT>' , kwargs = { '<STR_LIT>' : self . event . id } ) , ** self . authentication_headers ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> def test_update_field ( self ) : <EOL> updates = { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:start>" : "<STR_LIT>" , "<STR_LIT:end>" : "<STR_LIT>" } <EOL> response = self . client . put ( path = reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : self . event . id } ) , <EOL> content_type = self . content_type , data = json . dumps ( updates ) , <EOL> ** self . authentication_headers ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> data = json . loads ( response . content ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEquals ( data [ '<STR_LIT:name>' ] , updates [ '<STR_LIT:name>' ] ) <EOL> self . assertEquals ( data [ '<STR_LIT>' ] , updates [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( data [ '<STR_LIT:start>' ] . replace ( "<STR_LIT:T>" , "<STR_LIT:U+0020>" ) , updates [ '<STR_LIT:start>' ] ) <EOL> self . assertEquals ( data [ '<STR_LIT:end>' ] . replace ( "<STR_LIT:T>" , "<STR_LIT:U+0020>" ) , updates [ '<STR_LIT:end>' ] ) </s>
