14
14
15
15
import unittest
16
16
17
+ import mock
18
+
17
19
18
20
def make_mock_credentials ():
19
- import mock
20
21
from google .auth import credentials
21
22
22
23
credentials = mock .Mock (spec = credentials .Credentials )
@@ -92,21 +93,21 @@ def test_document_from_html_factory_failure(self):
92
93
with self .assertRaises (TypeError ):
93
94
client .document_from_html ('abc' , doc_type = 'foo' )
94
95
95
- def test_document_from_url_factory (self ):
96
+ def test_document_from_gcs_url_factory (self ):
96
97
from google .cloud .language .document import Document
97
98
98
99
creds = make_mock_credentials ()
99
100
client = self ._make_one (credentials = creds , http = object ())
100
101
101
102
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 )
103
104
self .assertIsInstance (document , Document )
104
105
self .assertIs (document .client , client )
105
106
self .assertIsNone (document .content )
106
107
self .assertEqual (document .gcs_url , gcs_url )
107
108
self .assertEqual (document .doc_type , Document .PLAIN_TEXT )
108
109
109
- def test_document_from_url_factory_explicit (self ):
110
+ def test_document_from_gcs_url_factory_explicit (self ):
110
111
from google .cloud .language .document import Document
111
112
from google .cloud .language .document import Encoding
112
113
@@ -115,11 +116,31 @@ def test_document_from_url_factory_explicit(self):
115
116
116
117
encoding = Encoding .UTF32
117
118
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 )
120
122
self .assertIsInstance (document , Document )
121
123
self .assertIs (document .client , client )
122
124
self .assertIsNone (document .content )
123
125
self .assertEqual (document .gcs_url , gcs_url )
124
126
self .assertEqual (document .doc_type , Document .HTML )
125
127
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