<s> import datetime <EOL> import json <EOL> from unittest . mock import patch <EOL> from django . core . urlresolvers import reverse <EOL> from django . http import QueryDict <EOL> from rest_framework import status <EOL> from rest_framework . test import APITestCase <EOL> from api . views import ( <EOL> PublishedEvents , <EOL> ) <EOL> from workshops . models import ( <EOL> Event , <EOL> Host , <EOL> ) <EOL> from workshops . util import universal_date_format <EOL> class TestListingPublishedEvents ( APITestCase ) : <EOL> view = PublishedEvents <EOL> serializer_class = PublishedEvents . serializer_class <EOL> url = '<STR_LIT>' <EOL> maxDiff = None <EOL> def setUp ( self ) : <EOL> past = datetime . date ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:30> ) <EOL> today = datetime . date . today ( ) <EOL> future = datetime . date ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> ) <EOL> delta_2d = datetime . timedelta ( days = <NUM_LIT:2> ) <EOL> delta_1d = datetime . timedelta ( days = <NUM_LIT:1> ) <EOL> host = Host . objects . create ( domain = '<STR_LIT>' , fullname = '<STR_LIT>' ) <EOL> self . event1 = Event . objects . create ( <EOL> slug = '<STR_LIT>' , start = past - delta_2d , end = past - delta_1d , <EOL> host = host , latitude = <NUM_LIT:3> , longitude = - <NUM_LIT:2> , venue = '<STR_LIT>' , <EOL> address = '<STR_LIT>' , country = '<STR_LIT>' , contact = '<STR_LIT>' , <EOL> url = '<STR_LIT>' , <EOL> ) <EOL> self . event2 = Event . objects . create ( <EOL> slug = '<STR_LIT>' , start = today - delta_2d , end = today + delta_2d , <EOL> host = host , latitude = <NUM_LIT:3> , longitude = - <NUM_LIT:2> , venue = '<STR_LIT>' , <EOL> address = '<STR_LIT>' , country = '<STR_LIT>' , contact = '<STR_LIT>' , <EOL> url = '<STR_LIT>' , <EOL> ) <EOL> self . event3 = Event . objects . create ( <EOL> slug = '<STR_LIT>' , start = future - delta_2d , end = future + delta_2d , <EOL> host = host , latitude = <NUM_LIT:3> , longitude = - <NUM_LIT:2> , venue = '<STR_LIT>' , <EOL> address = '<STR_LIT>' , country = '<STR_LIT>' , contact = '<STR_LIT>' , <EOL> url = '<STR_LIT>' , <EOL> reg_key = '<STR_LIT>' , <EOL> ) <EOL> self . event4 = Event . objects . create ( <EOL> slug = '<STR_LIT>' , end = past + delta_2d , <EOL> host = host , latitude = <NUM_LIT:3> , longitude = - <NUM_LIT:2> , venue = '<STR_LIT>' , <EOL> address = '<STR_LIT>' , country = '<STR_LIT>' , contact = '<STR_LIT>' , <EOL> url = '<STR_LIT>' , <EOL> ) <EOL> self . event5 = Event . objects . create ( <EOL> slug = '<STR_LIT>' , start = future - delta_2d , end = future + delta_2d , <EOL> host = host , latitude = <NUM_LIT:3> , longitude = - <NUM_LIT:2> , venue = '<STR_LIT>' , <EOL> address = '<STR_LIT>' , country = '<STR_LIT>' , contact = '<STR_LIT>' , <EOL> ) <EOL> self . event6 = Event . objects . create ( <EOL> slug = '<STR_LIT>' , start = future - delta_2d , end = future + delta_2d , <EOL> host = host , latitude = <NUM_LIT:3> , longitude = - <NUM_LIT:2> , venue = '<STR_LIT>' , <EOL> address = '<STR_LIT>' , country = None , contact = '<STR_LIT>' , <EOL> url = '<STR_LIT>' , <EOL> ) <EOL> self . event7 = Event . objects . create ( <EOL> slug = '<STR_LIT>' , start = future - delta_2d , end = future + delta_2d , <EOL> host = host , latitude = <NUM_LIT:3> , longitude = - <NUM_LIT:2> , venue = '<STR_LIT>' , <EOL> address = '<STR_LIT>' , country = '<STR_LIT>' , contact = '<STR_LIT>' , <EOL> url = '<STR_LIT>' , <EOL> ) <EOL> self . event8 = Event . objects . create ( <EOL> slug = '<STR_LIT>' , end = future + delta_1d , <EOL> host = host , latitude = <NUM_LIT> , longitude = - <NUM_LIT> , venue = '<STR_LIT>' , <EOL> address = '<STR_LIT>' , country = '<STR_LIT>' , contact = '<STR_LIT>' , <EOL> ) <EOL> self . event9 = Event . objects . create ( <EOL> slug = '<STR_LIT>' , start = future - delta_2d , end = future + delta_1d , <EOL> host = host , latitude = <NUM_LIT> , longitude = - <NUM_LIT> , venue = '<STR_LIT>' , <EOL> address = '<STR_LIT>' , country = None , contact = '<STR_LIT>' , <EOL> url = '<STR_LIT>' , <EOL> ) <EOL> self . event10 = Event . objects . create ( <EOL> slug = '<STR_LIT>' , end = future + delta_1d , <EOL> host = host , latitude = <NUM_LIT> , longitude = - <NUM_LIT> , venue = '<STR_LIT>' , <EOL> address = '<STR_LIT>' , country = None , contact = '<STR_LIT>' , <EOL> ) <EOL> self . expecting = [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:start>' : self . event3 . start , <EOL> '<STR_LIT:end>' : self . event3 . end , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : - <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:address>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:start>' : self . event2 . start , <EOL> '<STR_LIT:end>' : self . event2 . end , <EOL> '<STR_LIT>' : self . event2 . human_readable_date , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : - <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:address>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : [ ] , <EOL> } , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:start>' : self . event1 . start , <EOL> '<STR_LIT:end>' : self . event1 . end , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : - <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:address>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : [ ] , <EOL> } , <EOL> ] <EOL> @ patch . object ( PublishedEvents , '<STR_LIT>' , query_params = QueryDict ( ) , <EOL> create = True ) <EOL> def test_serialization ( self , mock_request ) : <EOL> response = self . serializer_class ( self . view ( ) . get_queryset ( ) , many = True ) <EOL> self . assertEqual ( response . data , self . expecting ) <EOL> def test_view ( self ) : <EOL> for i , event in enumerate ( self . expecting ) : <EOL> for date in [ '<STR_LIT:start>' , '<STR_LIT:end>' ] : <EOL> self . expecting [ i ] [ date ] = universal_date_format ( <EOL> self . expecting [ i ] [ date ] , <EOL> ) <EOL> url = reverse ( self . url ) <EOL> response = self . client . get ( url , format = '<STR_LIT>' ) <EOL> content = response . content . decode ( '<STR_LIT:utf-8>' ) <EOL> self . assertEqual ( response . status_code , status . HTTP_200_OK ) <EOL> self . assertEqual ( json . loads ( content ) , self . expecting ) </s>
