11# Copyright The IETF Trust 2009-2019, All Rights Reserved
22# -*- coding: utf-8 -*-
33
4- import json
54import os
65import shutil
76import datetime
87import urllib .parse
8+ import six
99import random
10- from unittest import skipIf
1110
12- import debug # pyflakes:ignore
11+ from unittest import skipIf
12+ from mock import patch
13+ from pyquery import PyQuery
14+ from io import StringIO , BytesIO
15+ from bs4 import BeautifulSoup
1316
1417from django .urls import reverse as urlreverse
1518from django .conf import settings
1619from django .contrib .auth .models import User
1720
18- from mock import patch
19- from pyquery import PyQuery
20- from io import StringIO
21- from bs4 import BeautifulSoup
21+ import debug # pyflakes:ignore
2222
2323from ietf .doc .models import Document
2424from ietf .group .models import Group , Role
@@ -393,9 +393,9 @@ def test_proceedings_acknowledgements(self):
393393 self .assertEqual (response .status_code , 200 )
394394 self .assertIn ('test acknowledgements' , response .content )
395395
396- @patch ('urllib2 .urlopen' )
396+ @patch ('six.moves.urllib.request .urlopen' )
397397 def test_proceedings_attendees (self , mock_urlopen ):
398- mock_urlopen .return_value = StringIO ( '[{"LastName":"Smith","FirstName":"John","Company":"ABC","Country":"US"}]' )
398+ mock_urlopen .return_value = BytesIO ( b '[{"LastName":"Smith","FirstName":"John","Company":"ABC","Country":"US"}]' )
399399 make_meeting_test_data ()
400400 meeting = MeetingFactory (type_id = 'ietf' , date = datetime .date (2016 ,7 ,14 ), number = "96" )
401401 finalize (meeting )
@@ -406,12 +406,12 @@ def test_proceedings_attendees(self, mock_urlopen):
406406 q = PyQuery (response .content )
407407 self .assertEqual (1 ,len (q ("#id_attendees tbody tr" )))
408408
409- @patch ('urllib2 .urlopen' )
409+ @patch ('six.moves.urllib.request .urlopen' )
410410 def test_proceedings_overview (self , mock_urlopen ):
411411 '''Test proceedings IETF Overview page.
412412 Note: old meetings aren't supported so need to add a new meeting then test.
413413 '''
414- mock_urlopen .return_value = StringIO ( '[{"LastName":"Smith","FirstName":"John","Company":"ABC","Country":"US"}]' )
414+ mock_urlopen .return_value = BytesIO ( b '[{"LastName":"Smith","FirstName":"John","Company":"ABC","Country":"US"}]' )
415415 make_meeting_test_data ()
416416 meeting = MeetingFactory (type_id = 'ietf' , date = datetime .date (2016 ,7 ,14 ), number = "96" )
417417 finalize (meeting )
@@ -952,7 +952,7 @@ def test_upcoming(self):
952952 ames_interim = Meeting .objects .filter (date__gt = today , type = 'interim' , session__group__acronym = 'ames' , session__status = 'canceled' ).first ()
953953 self .assertContains (r , mars_interim .number )
954954 self .assertContains (r , ames_interim .number )
955- self .assertContains (r , 'IETF - 42 ' )
955+ self .assertContains (r , 'IETF - 72 ' )
956956 # cancelled session
957957 q = PyQuery (r .content )
958958 self .assertIn ('CANCELLED' , q ('[id*="-ames"]' ).text ())
@@ -1642,7 +1642,7 @@ def test_ajax_get_utc(self):
16421642 self .assertIn ('timezone' , data )
16431643 self .assertIn ('time' , data )
16441644 self .assertIn ('utc' , data )
1645- self .assertIn ('error' not , data )
1645+ self .assertNotIn ('error' , data )
16461646 self .assertEqual (data ['utc' ], '20:00' )
16471647
16481648class FloorPlanTests (TestCase ):
@@ -1688,9 +1688,9 @@ def test_iphone_app_json(self):
16881688 self .assertEqual (r .status_code ,200 )
16891689
16901690class FinalizeProceedingsTests (TestCase ):
1691- @patch ('urllib2 .urlopen' )
1691+ @patch ('six.moves.urllib.request .urlopen' )
16921692 def test_finalize_proceedings (self , mock_urlopen ):
1693- mock_urlopen .return_value = StringIO ( '[{"LastName":"Smith","FirstName":"John","Company":"ABC","Country":"US"}]' )
1693+ mock_urlopen .return_value = BytesIO ( b '[{"LastName":"Smith","FirstName":"John","Company":"ABC","Country":"US"}]' )
16941694 make_meeting_test_data ()
16951695 meeting = Meeting .objects .filter (type_id = 'ietf' ).order_by ('id' ).last ()
16961696 meeting .session_set .filter (group__acronym = 'mars' ).first ().sessionpresentation_set .create (document = Document .objects .filter (type = 'draft' ).first (),rev = None )
@@ -1731,8 +1731,6 @@ def crawl_materials(self, url, top):
17311731 def follow (url ):
17321732 seen .add (url )
17331733 r = self .client .get (url )
1734- if r .status_code != 200 :
1735- debug .show ('url' )
17361734 self .assertEqual (r .status_code , 200 )
17371735 if not ('.' in url and url .rsplit ('.' , 1 )[1 ] in ['tgz' , 'pdf' , ]):
17381736 if r .content :
@@ -1754,7 +1752,7 @@ def test_upload_bluesheets(self):
17541752 q = PyQuery (r .content )
17551753 self .assertIn ('Upload' , str (q ("title" )))
17561754 self .assertFalse (session .sessionpresentation_set .exists ())
1757- test_file = StringIO (b '%PDF-1.4\n %âãÏÓ\n this is some text for a test' )
1755+ test_file = StringIO ('%PDF-1.4\n %âãÏÓ\n this is some text for a test' )
17581756 test_file .name = "not_really.pdf"
17591757 r = self .client .post (url ,dict (file = test_file ))
17601758 self .assertEqual (r .status_code , 302 )
@@ -1789,7 +1787,7 @@ def test_upload_bluesheets_interim(self):
17891787 q = PyQuery (r .content )
17901788 self .assertIn ('Upload' , str (q ("title" )))
17911789 self .assertFalse (session .sessionpresentation_set .exists ())
1792- test_file = StringIO (b '%PDF-1.4\n %âãÏÓ\n this is some text for a test' )
1790+ test_file = StringIO ('%PDF-1.4\n %âãÏÓ\n this is some text for a test' )
17931791 test_file .name = "not_really.pdf"
17941792 r = self .client .post (url ,dict (file = test_file ))
17951793 self .assertEqual (r .status_code , 302 )
0 commit comments