1414
1515import unittest
1616
17+ import mock
18+
1719
1820def make_mock_credentials ():
19- import mock
2021 from google .auth import credentials
2122
2223 credentials = mock .Mock (spec = credentials .Credentials )
@@ -92,21 +93,21 @@ def test_document_from_html_factory_failure(self):
9293 with self .assertRaises (TypeError ):
9394 client .document_from_html ('abc' , doc_type = 'foo' )
9495
95- def test_document_from_url_factory (self ):
96+ def test_document_from_gcs_url_factory (self ):
9697 from google .cloud .language .document import Document
9798
9899 creds = make_mock_credentials ()
99100 client = self ._make_one (credentials = creds , http = object ())
100101
101102 gcs_url = 'gs://my-text-bucket/sentiment-me.txt'
102- document = client .document_from_url (gcs_url )
103+ document = client .document_from_gcs_url (gcs_url )
103104 self .assertIsInstance (document , Document )
104105 self .assertIs (document .client , client )
105106 self .assertIsNone (document .content )
106107 self .assertEqual (document .gcs_url , gcs_url )
107108 self .assertEqual (document .doc_type , Document .PLAIN_TEXT )
108109
109- def test_document_from_url_factory_explicit (self ):
110+ def test_document_from_gcs_url_factory_explicit (self ):
110111 from google .cloud .language .document import Document
111112 from google .cloud .language .document import Encoding
112113
@@ -115,11 +116,31 @@ def test_document_from_url_factory_explicit(self):
115116
116117 encoding = Encoding .UTF32
117118 gcs_url = 'gs://my-text-bucket/sentiment-me.txt'
118- document = client .document_from_url (gcs_url , doc_type = Document .HTML ,
119- encoding = encoding )
119+ document = client .document_from_gcs_url (gcs_url ,
120+ doc_type = Document .HTML ,
121+ encoding = encoding )
120122 self .assertIsInstance (document , Document )
121123 self .assertIs (document .client , client )
122124 self .assertIsNone (document .content )
123125 self .assertEqual (document .gcs_url , gcs_url )
124126 self .assertEqual (document .doc_type , Document .HTML )
125127 self .assertEqual (document .encoding , encoding )
128+
129+ def test_document_from_url_deprecation (self ):
130+ import warnings
131+
132+ creds = make_mock_credentials ()
133+ client = self ._make_one (credentials = creds , http = object ())
134+
135+ Client = self ._get_target_class ()
136+ with mock .patch .object (Client , 'document_from_gcs_url' ) as dfgu :
137+ with mock .patch .object (warnings , 'warn' ) as warn :
138+ client .document_from_url (gcs_url = 'gs://bogus' )
139+
140+ # Establish that the warning happened and sent a
141+ # DeprecationWarning.
142+ self .assertEqual (warn .call_count , 1 )
143+ self .assertEqual (warn .mock_calls [0 ][1 ][1 ], DeprecationWarning )
144+
145+ # Establish that the new (renamed) method is called.
146+ dfgu .assert_called_once_with (gcs_url = 'gs://bogus' )
0 commit comments