|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
| 15 | +from collections import UserDict |
15 | 16 | from datetime import datetime
|
16 | 17 | import json
|
| 18 | +import uuid |
| 19 | + |
| 20 | +from mock import MagicMock, patch |
17 | 21 |
|
18 | 22 | import main
|
19 | 23 |
|
@@ -76,6 +80,43 @@ def test_auth(capsys):
|
76 | 80 | assert 'Email: [email protected]' in out
|
77 | 81 |
|
78 | 82 |
|
| 83 | +@patch('main.client') |
| 84 | +def test_make_upper_case(firestore_mock, capsys): |
| 85 | + |
| 86 | + firestore_mock.collection = MagicMock(return_value=firestore_mock) |
| 87 | + firestore_mock.document = MagicMock(return_value=firestore_mock) |
| 88 | + firestore_mock.set = MagicMock(return_value=firestore_mock) |
| 89 | + |
| 90 | + user_id = str(uuid.uuid4()) |
| 91 | + date_string = datetime.now().isoformat() |
| 92 | + email_string = '%s@%s.com' % (uuid.uuid4(), uuid.uuid4()) |
| 93 | + |
| 94 | + data = { |
| 95 | + 'uid': user_id, |
| 96 | + 'metadata': {'createdAt': date_string}, |
| 97 | + 'email': email_string, |
| 98 | + 'value': { |
| 99 | + 'fields': { |
| 100 | + 'original': { |
| 101 | + 'stringValue': 'foobar' |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + context = UserDict() |
| 108 | + context.resource = '/documents/some_collection/path/some/path' |
| 109 | + |
| 110 | + main.make_upper_case(data, context) |
| 111 | + |
| 112 | + out, _ = capsys.readouterr() |
| 113 | + |
| 114 | + assert 'Replacing value: foobar --> FOOBAR' in out |
| 115 | + firestore_mock.collection.assert_called_with('some_collection') |
| 116 | + firestore_mock.document.assert_called_with('path/some/path') |
| 117 | + firestore_mock.set.assert_called_with({'original': 'FOOBAR'}) |
| 118 | + |
| 119 | + |
79 | 120 | def test_analytics(capsys):
|
80 | 121 | timestamp = int(datetime.utcnow().timestamp())
|
81 | 122 |
|
|
0 commit comments