<s> import re <EOL> from django . test import TestCase <EOL> from django . test . client import Client <EOL> from django . core . urlresolvers import reverse <EOL> from django . contrib . auth . models import User , AnonymousUser <EOL> from django . contrib . sites . models import Site <EOL> from tastypie . test import ResourceTestCase <EOL> from actstream import follow , action <EOL> from actstream . models import Action <EOL> from mks . models import Member , Party , Membership , MemberAltname , Knesset <EOL> from mks . views import MemberListView <EOL> from laws . models import Law , Bill , PrivateProposal , Vote , VoteAction <EOL> from committees . models import CommitteeMeeting , Committee <EOL> from knesset . utils import RequestFactory <EOL> import datetime <EOL> import feedparser <EOL> import json <EOL> from backlinks . tests . xmlrpc import TestClientServerProxy <EOL> from xmlrpclib import Fault , loads <EOL> from urllib import urlencode <EOL> from backlinks . models import InboundBacklink <EOL> from backlinks . pingback . server import PingbackServer <EOL> from django import template <EOL> from mks . mock import PINGABLE_MEMBER_ID , NON_PINGABLE_MEMBER_ID <EOL> from persons . models import Person , PersonAlias <EOL> TRACKBACK_CONTENT_TYPE = '<STR_LIT>' <EOL> just_id = lambda x : x . id <EOL> class MemberViewsTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> from django . core . cache import cache <EOL> cache . clear ( ) <EOL> d = datetime . date . today ( ) <EOL> self . knesset = Knesset . objects . create ( <EOL> number = <NUM_LIT:1> , <EOL> start_date = d - datetime . timedelta ( <NUM_LIT:10> ) ) <EOL> self . party_1 = Party . objects . create ( name = '<STR_LIT>' , <EOL> knesset = self . knesset ) <EOL> self . party_2 = Party . objects . create ( name = '<STR_LIT>' , <EOL> knesset = self . knesset ) <EOL> self . mk_1 = Member . objects . create ( name = '<STR_LIT>' , <EOL> start_date = datetime . date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> current_party = self . party_1 , <EOL> backlinks_enabled = True ) <EOL> self . mk_2 = Member . objects . create ( name = '<STR_LIT>' , <EOL> start_date = datetime . date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> current_party = self . party_1 , <EOL> backlinks_enabled = False ) <EOL> self . jacob = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . committee_1 = Committee . objects . create ( name = '<STR_LIT>' ) <EOL> self . meeting_1 = self . committee_1 . meetings . create ( <EOL> date = d - datetime . timedelta ( <NUM_LIT:1> ) , <EOL> protocol_text = '<STR_LIT>' ) <EOL> self . meeting_2 = self . committee_1 . meetings . create ( <EOL> date = d - datetime . timedelta ( <NUM_LIT:2> ) , <EOL> protocol_text = '<STR_LIT>' ) <EOL> self . law = Law . objects . create ( title = '<STR_LIT>' ) <EOL> self . pp = PrivateProposal . objects . create ( title = '<STR_LIT>' , date = datetime . date . today ( ) - datetime . timedelta ( <NUM_LIT:3> ) ) <EOL> self . pp . proposers . add ( self . mk_1 ) <EOL> self . bill_1 = Bill . objects . create ( stage = '<STR_LIT:1>' , title = '<STR_LIT>' , law = self . law ) <EOL> self . bill_1 . proposals . add ( self . pp ) <EOL> self . bill_1 . proposers . add ( self . mk_1 ) <EOL> self . meeting_1 . mks_attended . add ( self . mk_1 ) <EOL> self . meeting_1 . save ( ) <EOL> self . meeting_2 . mks_attended . add ( self . mk_1 ) <EOL> self . meeting_2 . save ( ) <EOL> self . vote = Vote . objects . create ( title = '<STR_LIT>' , time = datetime . datetime . now ( ) ) <EOL> self . vote_action = VoteAction . objects . create ( member = self . mk_1 , vote = self . vote , type = '<STR_LIT>' , party = self . mk_1 . current_party ) <EOL> self . domain = '<STR_LIT>' + Site . objects . get_current ( ) . domain <EOL> def testMemberList ( self ) : <EOL> res = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT> ) <EOL> res = self . client . get ( reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> object_list = res . context [ '<STR_LIT>' ] <EOL> self . assertItemsEqual ( map ( just_id , object_list ) , [ self . mk_1 . id , self . mk_2 . id ] ) <EOL> def testMemberDetail ( self ) : <EOL> res = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . mk_1 . id ] ) ) <EOL> self . assertTemplateUsed ( res , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( res . context [ '<STR_LIT:object>' ] . id , self . mk_1 . id ) <EOL> def testMemberDetailOtherVerbs ( self ) : <EOL> """<STR_LIT>""" <EOL> res = self . client . get ( '<STR_LIT>' % <EOL> reverse ( '<STR_LIT>' , args = [ self . mk_1 . id ] ) ) <EOL> self . assertTemplateUsed ( res , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( res . context [ '<STR_LIT:object>' ] . id , self . mk_1 . id ) <EOL> def testPartyList ( self ) : <EOL> res = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( res , reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) , <NUM_LIT> ) <EOL> def testPartyDetail ( self ) : <EOL> res = self . client . get ( reverse ( '<STR_LIT>' , <EOL> args = [ self . party_1 . id ] ) ) <EOL> self . assertTemplateUsed ( res , '<STR_LIT>' ) <EOL> self . assertEqual ( res . context [ '<STR_LIT:object>' ] . id , self . party_1 . id ) <EOL> def testMemberDetailsContext ( self ) : <EOL> mk_1_url = self . mk_1 . get_absolute_url ( ) <EOL> res = self . client . get ( mk_1_url ) <EOL> self . assertFalse ( res . context [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) ) <EOL> res = self . client . get ( mk_1_url ) <EOL> self . assertFalse ( res . context [ '<STR_LIT>' ] ) <EOL> follow ( self . jacob , self . mk_1 ) <EOL> res = self . client . get ( mk_1_url ) <EOL> self . assertTrue ( res . context [ '<STR_LIT>' ] ) <EOL> def testMemberActivityFeed ( self ) : <EOL> res = self . client . get ( reverse ( '<STR_LIT>' , <EOL> args = [ self . mk_1 . id ] ) ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> parsed = feedparser . parse ( res . content ) <EOL> self . assertEqual ( parsed [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , self . domain + <EOL> self . vote . get_absolute_url ( ) ) <EOL> self . assertEqual ( parsed [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ '<STR_LIT>' ] , self . domain + <EOL> self . meeting_1 . get_absolute_url ( ) ) <EOL> self . assertEqual ( parsed [ '<STR_LIT>' ] [ <NUM_LIT:2> ] [ '<STR_LIT>' ] , self . domain + <EOL> self . meeting_2 . get_absolute_url ( ) ) <EOL> self . assertEqual ( parsed [ '<STR_LIT>' ] [ <NUM_LIT:3> ] [ '<STR_LIT>' ] , self . domain + <EOL> self . bill_1 . get_absolute_url ( ) ) <EOL> def testMemberActivityFeedWithVerbProposed ( self ) : <EOL> res = self . client . get ( reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . mk_1 . id } ) , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> parsed = feedparser . parse ( res . content ) <EOL> self . assertEqual ( len ( parsed [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> res = self . client . get ( reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . mk_2 . id } ) , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> parsed = feedparser . parse ( res . content ) <EOL> self . assertEqual ( len ( parsed [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> def testMemberActivityFeedWithVerbAttended ( self ) : <EOL> res = self . client . get ( reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . mk_1 . id } ) , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> parsed = feedparser . parse ( res . content ) <EOL> self . assertEqual ( len ( parsed [ '<STR_LIT>' ] ) , <NUM_LIT:2> ) <EOL> res = self . client . get ( reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . mk_2 . id } ) , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> parsed = feedparser . parse ( res . content ) <EOL> self . assertEqual ( len ( parsed [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> def testMemberActivityFeedWithVerbJoined ( self ) : <EOL> res = self . client . get ( reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . mk_1 . id } ) , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> parsed = feedparser . parse ( res . content ) <EOL> self . assertEqual ( len ( parsed [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> def testMemberActivityFeedWithVerbPosted ( self ) : <EOL> res = self . client . get ( reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : self . mk_1 . id } ) , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> parsed = feedparser . parse ( res . content ) <EOL> self . assertEqual ( len ( parsed [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> def tearDown ( self ) : <EOL> self . party_1 . delete ( ) <EOL> self . party_2 . delete ( ) <EOL> self . mk_1 . delete ( ) <EOL> self . mk_2 . delete ( ) <EOL> self . jacob . delete ( ) <EOL> class MemberBacklinksViewsTest ( TestCase ) : <EOL> urls = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> self . party_1 = Party . objects . create ( name = '<STR_LIT>' ) <EOL> self . party_2 = Party . objects . create ( name = '<STR_LIT>' ) <EOL> self . mk_1 = Member . objects . create ( name = '<STR_LIT>' , <EOL> start_date = datetime . date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> current_party = self . party_1 , <EOL> backlinks_enabled = True ) <EOL> self . mk_2 = Member . objects . create ( name = '<STR_LIT>' , <EOL> start_date = datetime . date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> current_party = self . party_1 , <EOL> backlinks_enabled = False ) <EOL> self . jacob = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . mk_1 . save ( ) <EOL> self . mk_2 . save ( ) <EOL> self . committee_1 = Committee . objects . create ( name = '<STR_LIT>' ) <EOL> self . meeting_1 = self . committee_1 . meetings . create ( date = datetime . date . today ( ) - datetime . timedelta ( <NUM_LIT:1> ) , <EOL> protocol_text = '<STR_LIT>' ) <EOL> self . meeting_2 = self . committee_1 . meetings . create ( date = datetime . date . today ( ) - datetime . timedelta ( <NUM_LIT:2> ) , <EOL> protocol_text = '<STR_LIT>' ) <EOL> self . law = Law . objects . create ( title = '<STR_LIT>' ) <EOL> self . pp = PrivateProposal . objects . create ( title = '<STR_LIT>' , date = datetime . date . today ( ) - datetime . timedelta ( <NUM_LIT:3> ) ) <EOL> self . pp . proposers . add ( self . mk_1 ) <EOL> self . bill_1 = Bill . objects . create ( stage = '<STR_LIT:1>' , title = '<STR_LIT>' , law = self . law ) <EOL> self . bill_1 . proposals . add ( self . pp ) <EOL> self . bill_1 . proposers . add ( self . mk_1 ) <EOL> self . meeting_1 . mks_attended . add ( self . mk_1 ) <EOL> self . meeting_1 . save ( ) <EOL> self . meeting_2 . mks_attended . add ( self . mk_1 ) <EOL> self . meeting_2 . save ( ) <EOL> self . vote = Vote . objects . create ( title = '<STR_LIT>' , time = datetime . datetime . now ( ) ) <EOL> self . vote_action = VoteAction . objects . create ( member = self . mk_1 , vote = self . vote , type = '<STR_LIT>' , party = self . mk_1 . current_party ) <EOL> self . client = Client ( SERVER_NAME = '<STR_LIT>' ) <EOL> self . xmlrpc_client = TestClientServerProxy ( '<STR_LIT>' ) <EOL> self . PINGABLE_MEMBER_ID = str ( self . mk_1 . id ) <EOL> self . NON_PINGABLE_MEMBER_ID = str ( self . mk_2 . id ) <EOL> def trackbackPOSTRequest ( self , path , params ) : <EOL> return self . client . post ( path , urlencode ( params ) , content_type = TRACKBACK_CONTENT_TYPE ) <EOL> def assertTrackBackErrorResponse ( self , response , msg ) : <EOL> if response . content . find ( '<STR_LIT>' ) == - <NUM_LIT:1> : <EOL> raise self . failureException , msg <EOL> '''<STR_LIT>''' <EOL> def testPingNonLinkingSourceURI ( self ) : <EOL> self . assertRaises ( Fault , <EOL> self . xmlrpc_client . pingback . ping , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' + PINGABLE_MEMBER_ID + '<STR_LIT:/>' ) <EOL> try : <EOL> self . xmlrpc_client . pingback . ping ( '<STR_LIT>' , <EOL> '<STR_LIT>' + PINGABLE_MEMBER_ID + '<STR_LIT:/>' ) <EOL> except Fault , f : <EOL> self . assertEquals ( f . faultCode , <EOL> <NUM_LIT> , <EOL> '<STR_LIT>' ) <EOL> def testDisallowedMethod ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEquals ( response . status_code , <EOL> <NUM_LIT> , <EOL> '<STR_LIT>' ) <EOL> def testNonExistentRPCMethod ( self ) : <EOL> self . assertRaises ( Fault , self . xmlrpc_client . foo ) <EOL> def testBadPostData ( self ) : <EOL> post_data = urlencode ( { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' + PINGABLE_MEMBER_ID + '<STR_LIT:/>' } ) <EOL> response = self . client . post ( '<STR_LIT>' , post_data , TRACKBACK_CONTENT_TYPE ) <EOL> self . assertRaises ( Fault , <EOL> loads , <EOL> response . content ) <EOL> def testPingNonExistentTargetURI ( self ) : <EOL> self . assertRaises ( Fault , <EOL> self . xmlrpc_client . pingback . ping , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> try : <EOL> self . xmlrpc_client . pingback . ping ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> except Fault , f : <EOL> self . assertEquals ( f . faultCode , <EOL> <NUM_LIT:32> , <EOL> '<STR_LIT>' ) <EOL> def testPingAlreadyRegistered ( self ) : <EOL> self . xmlrpc_client . pingback . ping ( '<STR_LIT>' , <EOL> '<STR_LIT>' + PINGABLE_MEMBER_ID + '<STR_LIT:/>' ) <EOL> self . assertRaises ( Fault , <EOL> self . xmlrpc_client . pingback . ping , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' + PINGABLE_MEMBER_ID + '<STR_LIT:/>' ) <EOL> try : <EOL> self . xmlrpc_client . pingback . ping ( '<STR_LIT>' , <EOL> '<STR_LIT>' + PINGABLE_MEMBER_ID + '<STR_LIT:/>' ) <EOL> except Fault , f : <EOL> self . assertEqual ( f . faultCode , <EOL> <NUM_LIT> , <EOL> '<STR_LIT>' ) <EOL> def testPingbackLinkTemplateTag ( self ) : <EOL> t = template . Template ( "<STR_LIT>" ) <EOL> c = template . Context ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> rendered = t . render ( c ) <EOL> link_re = re . compile ( r'<STR_LIT>' ) <EOL> match = link_re . search ( rendered ) <EOL> self . assertTrue ( bool ( match ) , '<STR_LIT>' ) <EOL> self . assertEquals ( match . groups ( <NUM_LIT:0> ) [ <NUM_LIT:0> ] , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def testPingNonPingableTargetURI ( self ) : <EOL> self . assertRaises ( Fault , <EOL> self . xmlrpc_client . pingback . ping , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' + str ( self . NON_PINGABLE_MEMBER_ID ) + '<STR_LIT:/>' ) <EOL> try : <EOL> self . xmlrpc_client . pingback . ping ( '<STR_LIT>' , <EOL> '<STR_LIT>' + str ( self . NON_PINGABLE_MEMBER_ID ) + '<STR_LIT:/>' ) <EOL> except Fault , f : <EOL> self . assertEquals ( f . faultCode , <EOL> <NUM_LIT> , <EOL> '<STR_LIT>' ) <EOL> def testPingSourceURILinks ( self ) : <EOL> r = self . xmlrpc_client . pingback . ping ( '<STR_LIT>' , <EOL> '<STR_LIT>' + self . PINGABLE_MEMBER_ID + '<STR_LIT:/>' ) <EOL> self . assertEquals ( r , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> registered_ping = InboundBacklink . objects . get ( source_url = '<STR_LIT>' , <EOL> target_url = '<STR_LIT>' + self . PINGABLE_MEMBER_ID + '<STR_LIT:/>' ) <EOL> self . assertEquals ( str ( registered_ping . target_object . id ) , <EOL> PINGABLE_MEMBER_ID , <EOL> '<STR_LIT>' ) <EOL> def testDisallowedTrackbackMethod ( self ) : <EOL> response = self . client . get ( '<STR_LIT>' + PINGABLE_MEMBER_ID + '<STR_LIT:/>' ) <EOL> self . assertEquals ( response . status_code , <EOL> <NUM_LIT> , <EOL> '<STR_LIT>' ) <EOL> def testPingNoURLParameter ( self ) : <EOL> params = { '<STR_LIT:title>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> response = self . trackbackPOSTRequest ( '<STR_LIT>' + self . PINGABLE_MEMBER_ID + '<STR_LIT:/>' , <EOL> params ) <EOL> self . assertTrackBackErrorResponse ( response , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def testPingBadURLParameter ( self ) : <EOL> params = { '<STR_LIT:url>' : '<STR_LIT>' } <EOL> response = self . trackbackPOSTRequest ( '<STR_LIT>' + self . PINGABLE_MEMBER_ID + '<STR_LIT:/>' , <EOL> params ) <EOL> self . assertTrackBackErrorResponse ( response , <EOL> '<STR_LIT>' ) <EOL> def testPingNonExistentTarget ( self ) : <EOL> params = { '<STR_LIT:url>' : '<STR_LIT>' } <EOL> response = self . trackbackPOSTRequest ( '<STR_LIT>' , <EOL> params ) <EOL> self . assertTrackBackErrorResponse ( response , <EOL> '<STR_LIT>' ) <EOL> def testPingNonPingableTarget ( self ) : <EOL> params = { '<STR_LIT:url>' : '<STR_LIT>' + PINGABLE_MEMBER_ID + '<STR_LIT:/>' } <EOL> response = self . trackbackPOSTRequest ( '<STR_LIT>' + self . NON_PINGABLE_MEMBER_ID + '<STR_LIT:/>' , <EOL> params ) <EOL> self . assertTrackBackErrorResponse ( response , <EOL> '<STR_LIT>' ) <EOL> def testPingSuccess ( self ) : <EOL> title = '<STR_LIT>' <EOL> excerpt = '<STR_LIT>' <EOL> params = { '<STR_LIT:url>' : '<STR_LIT>' , '<STR_LIT:title>' : title , '<STR_LIT>' : excerpt } <EOL> track_target = '<STR_LIT>' + self . PINGABLE_MEMBER_ID + '<STR_LIT:/>' <EOL> response = self . trackbackPOSTRequest ( track_target , <EOL> params ) <EOL> self . assertTrue ( response . content . find ( '<STR_LIT>' ) > - <NUM_LIT:1> , <EOL> '<STR_LIT>' ) <EOL> registered_ping = InboundBacklink . objects . get ( source_url = '<STR_LIT>' , <EOL> target_url = '<STR_LIT>' + self . mk_1 . get_absolute_url ( ) ) <EOL> self . assertEquals ( registered_ping . title , <EOL> title , <EOL> '<STR_LIT>' ) <EOL> self . assertEquals ( registered_ping . excerpt , <EOL> excerpt , <EOL> '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> self . party_1 . delete ( ) <EOL> self . party_2 . delete ( ) <EOL> self . mk_1 . delete ( ) <EOL> self . mk_2 . delete ( ) <EOL> self . jacob . delete ( ) <EOL> class MemberAPITests ( ResourceTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( MemberAPITests , self ) . setUp ( ) <EOL> d = datetime . date . today ( ) <EOL> self . knesset = Knesset . objects . create ( <EOL> number = <NUM_LIT:1> , <EOL> start_date = d - datetime . timedelta ( <NUM_LIT:10> ) ) <EOL> self . party_1 = Party . objects . create ( name = '<STR_LIT>' , <EOL> knesset = self . knesset ) <EOL> self . mk_1 = Member . objects . create ( name = '<STR_LIT>' , <EOL> start_date = datetime . date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> current_party = self . party_1 , <EOL> backlinks_enabled = True ) <EOL> PersonAlias . objects . create ( name = "<STR_LIT>" , <EOL> person = Person . objects . get ( mk = self . mk_1 ) ) <EOL> def testSimpleGet ( self ) : <EOL> res1 = self . api_client . get ( '<STR_LIT>' , data = { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> self . assertValidJSONResponse ( res1 ) <EOL> ret = self . deserialize ( res1 ) <EOL> self . assertEqual ( ret [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> def testAliases ( self ) : <EOL> res1 = self . api_client . get ( '<STR_LIT>' , data = { '<STR_LIT:name>' : '<STR_LIT>' } , format = '<STR_LIT>' ) <EOL> self . assertValidJSONResponse ( res1 ) <EOL> res2 = self . api_client . get ( '<STR_LIT>' , data = { '<STR_LIT:name>' : '<STR_LIT>' } , format = '<STR_LIT>' ) <EOL> self . assertValidJSONResponse ( res2 ) <EOL> self . assertEqual ( self . deserialize ( res1 ) , self . deserialize ( res2 ) ) <EOL> def tearDown ( self ) : <EOL> self . mk_1 . delete ( ) <EOL> class MemberModelsTests ( TestCase ) : <EOL> def testNames ( self ) : <EOL> m = Member ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( m . names , [ '<STR_LIT>' ] ) <EOL> m . save ( ) <EOL> MemberAltname ( member = m , name = '<STR_LIT>' ) . save ( ) <EOL> self . assertEqual ( m . names , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> from agendas . models import Agenda , AgendaVote <EOL> class MKAgendasTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . knesset = Knesset . objects . create ( <EOL> number = <NUM_LIT:1> , <EOL> start_date = datetime . date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> self . party_1 = Party . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> number_of_seats = <NUM_LIT:1> , <EOL> knesset = self . knesset ) <EOL> self . mk_1 = Member . objects . create ( name = '<STR_LIT>' , <EOL> start_date = datetime . date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> current_party = self . party_1 ) <EOL> self . mk_2 = Member . objects . create ( name = '<STR_LIT>' , <EOL> start_date = datetime . date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> current_party = self . party_1 ) <EOL> self . mk_3 = Member . objects . create ( name = '<STR_LIT>' , <EOL> start_date = datetime . date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> current_party = self . party_1 ) <EOL> self . agenda_1 = Agenda . objects . create ( name = '<STR_LIT>' , <EOL> description = '<STR_LIT>' , <EOL> public_owner_name = '<STR_LIT>' , <EOL> is_public = True ) <EOL> self . agenda_2 = Agenda . objects . create ( name = '<STR_LIT>' , <EOL> description = '<STR_LIT>' , <EOL> public_owner_name = '<STR_LIT>' , <EOL> is_public = True ) <EOL> self . agenda_3 = Agenda . objects . create ( name = '<STR_LIT>' , <EOL> description = '<STR_LIT>' , <EOL> public_owner_name = '<STR_LIT>' , <EOL> is_public = False ) <EOL> self . vote_1 = Vote . objects . create ( title = '<STR_LIT>' , time = datetime . datetime . now ( ) ) <EOL> self . vote_2 = Vote . objects . create ( title = '<STR_LIT>' , time = datetime . datetime . now ( ) ) <EOL> self . voteactions = [ VoteAction . objects . create ( vote = self . vote_1 , <EOL> member = self . mk_1 , type = '<STR_LIT>' , party = self . mk_1 . current_party ) , <EOL> VoteAction . objects . create ( vote = self . vote_2 , <EOL> member = self . mk_1 , type = '<STR_LIT>' , party = self . mk_1 . current_party ) , <EOL> VoteAction . objects . create ( vote = self . vote_1 , <EOL> member = self . mk_2 , type = '<STR_LIT>' , party = self . mk_2 . current_party ) , <EOL> VoteAction . objects . create ( vote = self . vote_2 , <EOL> member = self . mk_2 , type = '<STR_LIT>' , party = self . mk_2 . current_party ) <EOL> ] <EOL> self . agendavotes = [ AgendaVote . objects . create ( agenda = self . agenda_1 , <EOL> vote = self . vote_1 , <EOL> score = - <NUM_LIT:1> , <EOL> reasoning = "<STR_LIT>" ) , <EOL> AgendaVote . objects . create ( agenda = self . agenda_2 , <EOL> vote = self . vote_2 , <EOL> score = <NUM_LIT:0.5> , <EOL> reasoning = "<STR_LIT>" ) , <EOL> AgendaVote . objects . create ( agenda = self . agenda_1 , <EOL> vote = self . vote_2 , <EOL> score = <NUM_LIT:0.5> , <EOL> reasoning = "<STR_LIT>" ) , <EOL> ] <EOL> self . domain = '<STR_LIT>' + Site . objects . get_current ( ) . domain <EOL> def testMemberValues ( self ) : <EOL> agenda_values1 = self . mk_1 . get_agendas_values ( ) <EOL> self . assertEqual ( len ( agenda_values1 ) , <NUM_LIT:2> ) <EOL> agenda_values2 = self . mk_2 . get_agendas_values ( ) <EOL> self . assertEqual ( len ( agenda_values2 ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( agenda_values1 , <EOL> { <NUM_LIT:1> : { '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : - <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } , <EOL> <NUM_LIT:2> : { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } } ) <EOL> self . assertEqual ( agenda_values2 , <EOL> { <NUM_LIT:1> : { '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } , <EOL> <NUM_LIT:2> : { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : - <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } } ) <EOL> agenda_values = self . mk_3 . get_agendas_values ( ) <EOL> self . assertFalse ( agenda_values ) <EOL> def testAPIv2 ( self ) : <EOL> res = self . client . get ( '<STR_LIT>' % self . mk_1 . id ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> data = json . loads ( res . content ) <EOL> self . assertEqual ( data [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] , self . party_1 . name ) <EOL> self . assertEqual ( data [ '<STR_LIT>' ] , self . party_1 . get_absolute_url ( ) ) <EOL> agendas_uri = data [ '<STR_LIT>' ] <EOL> expected_agendas_uri = '<STR_LIT>' % self . mk_1 . id <EOL> self . assertEqual ( agendas_uri , expected_agendas_uri , "<STR_LIT>" ) <EOL> res2 = self . client . get ( expected_agendas_uri + '<STR_LIT>' ) <EOL> agendas = json . loads ( res2 . content ) <EOL> self . assertEqual ( agendas [ '<STR_LIT>' ] , [ <EOL> { '<STR_LIT:id>' : <NUM_LIT:1> , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : - <NUM_LIT> , '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : - <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : - <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> } , <EOL> { '<STR_LIT:id>' : <NUM_LIT:2> , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : - <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : - <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> } ] ) <EOL> def tearDown ( self ) : <EOL> for av in self . agendavotes : <EOL> av . delete ( ) <EOL> for va in self . voteactions : <EOL> va . delete ( ) <EOL> self . vote_1 . delete ( ) <EOL> self . vote_2 . delete ( ) <EOL> self . mk_1 . delete ( ) <EOL> self . mk_2 . delete ( ) <EOL> self . party_1 . delete ( ) <EOL> self . agenda_1 . delete ( ) <EOL> self . agenda_2 . delete ( ) <EOL> self . agenda_3 . delete ( ) </s>
