def test_event_tweets_states(self): event = Event.objects.get(title='Test event') assert event in Event.objects.approved() group = Group.objects.create(name='testapprover') Approval.objects.create( event=event, group=group, ) assert event not in Event.objects.approved() url = reverse('manage:event_tweets', args=(event.pk, )) response = self.client.get(url) eq_(response.status_code, 200) tweet = EventTweet.objects.create( event=event, text='Bla bla', send_date=timezone.now(), ) response = self.client.get(url) eq_(response.status_code, 200) ok_('Bla bla' in response.content) ok_('Needs to be approved first' in response.content) from airmozilla.main.helpers import js_date ok_( js_date(tweet.send_date.replace( microsecond=0)) not in response.content) # also check that 'Bla bla' is shown on the Edit Event page edit_url = reverse('manage:event_edit', args=(event.pk, )) response = self.client.get(edit_url) eq_(response.status_code, 200) ok_('Bla bla' in response.content) tweet.tweet_id = '1234567890' tweet.sent_date = (timezone.now() - datetime.timedelta(days=1)) tweet.save() response = self.client.get(url) eq_(response.status_code, 200) ok_('Bla bla' in response.content) ok_('https://twitter.com/%s/status/1234567890' % settings.TWITTER_USERNAME in response.content) ok_( js_date(tweet.sent_date.replace( microsecond=0)) in response.content) tweet.tweet_id = None tweet.error = "Some error" tweet.save() response = self.client.get(url) eq_(response.status_code, 200) ok_('Bla bla' in response.content) ok_('https://twitter.com/%s/status/1234567890' % settings.TWITTER_USERNAME not in response.content) ok_( js_date(tweet.sent_date.replace( microsecond=0)) in response.content) ok_('Failed to send' in response.content)
def get(self, request, slug): event = self.get_event(slug, request) if not self.can_view_event(event, request): return self.cant_view_event(event, request) if not self.can_edit_event(event, request): return self.cant_edit_event(event, request) if request.GET.get('all'): qs = Chapter.objects.filter(event=event, is_active=True) chapters = [] for chapter in qs.select_related('user'): chapters.append({ 'timestamp': chapter.timestamp, 'text': chapter.text, 'user': { 'email': chapter.user.email, 'first_name': chapter.user.first_name, 'last_name': chapter.user.last_name, }, 'js_date_tag': js_date(chapter.modified), }) response = http.JsonResponse({'chapters': chapters}) add_never_cache_headers(response) return response video = get_video_tagged(event, request) context = { 'event': event, 'video': video, } return render(request, self.template_name, context)
def get(self, request, slug): event = self.get_event(slug, request) if not self.can_view_event(event, request): return self.cant_view_event(event, request) if not self.can_edit_event(event, request): return self.cant_edit_event(event, request) if request.GET.get('all'): qs = Chapter.objects.filter( event=event, is_active=True ) chapters = [] for chapter in qs.select_related('user'): chapters.append({ 'timestamp': chapter.timestamp, 'text': chapter.text, 'user': { 'email': chapter.user.email, 'first_name': chapter.user.first_name, 'last_name': chapter.user.last_name, }, 'js_date_tag': js_date(chapter.modified), }) response = http.JsonResponse({'chapters': chapters}) add_never_cache_headers(response) return response video = get_video_tagged(event, request) context = { 'event': event, 'video': video, } return render(request, self.template_name, context)
def get(self, request, slug): event = self.get_event(slug, request) if not self.can_view_event(event, request): return self.cant_view_event(event, request) if not self.can_edit_event(event, request): return self.cant_edit_event(event, request) if request.GET.get("all"): qs = Chapter.objects.filter(event=event, is_active=True) chapters = [] for chapter in qs.select_related("user"): chapters.append( { "timestamp": chapter.timestamp, "text": chapter.text, "user": { "email": chapter.user.email, "first_name": chapter.user.first_name, "last_name": chapter.user.last_name, }, "js_date_tag": js_date(chapter.modified), } ) response = http.JsonResponse({"chapters": chapters}) add_never_cache_headers(response) return response video = get_video_tagged(event, request) context = {"event": event, "video": video} return render(request, self.template_name, context)
def test_all_event_tweets_states(self): event = Event.objects.get(title='Test event') assert event in Event.objects.approved() group = Group.objects.get(name='testapprover') Approval.objects.create( event=event, group=group, ) assert event not in Event.objects.approved() url = reverse('manage:all_event_tweets') response = self.client.get(url) eq_(response.status_code, 200) tweet = EventTweet.objects.create( event=event, text='Bla bla', send_date=timezone.now(), ) response = self.client.get(url) eq_(response.status_code, 200) ok_('Bla bla' in response.content) ok_('Needs to be approved first' in response.content) from airmozilla.main.helpers import js_date ok_( js_date(tweet.send_date.replace(microsecond=0)) not in response.content ) # also check that 'Bla bla' is shown on the Edit Event page edit_url = reverse('manage:event_edit', args=(event.pk,)) response = self.client.get(edit_url) eq_(response.status_code, 200) ok_('Bla bla' in response.content) tweet.tweet_id = '1234567890' tweet.sent_date = ( timezone.now() - datetime.timedelta(days=1) ) tweet.save() response = self.client.get(url) eq_(response.status_code, 200) ok_('Bla bla' in response.content) ok_( 'https://twitter.com/%s/status/1234567890' % settings.TWITTER_USERNAME in response.content ) ok_( js_date(tweet.sent_date.replace(microsecond=0)) in response.content ) tweet.tweet_id = None tweet.error = "Some error" tweet.save() response = self.client.get(url) eq_(response.status_code, 200) ok_('Bla bla' in response.content) ok_( 'https://twitter.com/%s/status/1234567890' % settings.TWITTER_USERNAME not in response.content ) ok_( js_date(tweet.sent_date.replace(microsecond=0)) in response.content ) ok_('Failed to send' in response.content)