Skip to content

Commit 964ad26

Browse files
committed
update tests
1 parent 5372647 commit 964ad26

File tree

1 file changed

+0
-65
lines changed

1 file changed

+0
-65
lines changed

pythesint/tests/test_mmd_vocabulary.py

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -87,59 +87,12 @@ def test_fetch_online_data(self):
8787
self.assertCountEqual(self.voc._fetch_online_data(version=version), expected_list)
8888
mock_download.assert_called_with(version='a5c8573')
8989

90-
def test_get_local_file_github_blob_sha(self):
91-
"""Test that the correct hash is returned"""
92-
buffer = io.BytesIO(b'file contents\n')
93-
with mock.patch('pythesint.mmd_vocabulary.open') as mock_open, \
94-
mock.patch('os.path.isfile', return_value=True):
95-
mock_open.return_value.__enter__.return_value = buffer
96-
self.assertEqual(
97-
MMDVocabulary._get_local_file_github_blob_sha('test.txt'),
98-
'd03e2425cf1c82616e12cb430c69aaa6cc08ff84')
99-
100-
def test_get_remote_file_github_blob_sha(self):
101-
"""Test that the correct sha is fetched from github's API"""
102-
response = '''{
103-
"sha": "20b5eab06834b02b609097e9285dba1e2d266fe0",
104-
"url": "https://api.github.com/repos/metno/mmd/git/trees/20b5eab06834b02b609097e9285dba1e2d266fe0",
105-
"tree": [
106-
{
107-
"path": "mmd-vocabulary.ttl",
108-
"mode": "100644",
109-
"type": "blob",
110-
"sha": "21bc582a136d0dac8461f66e169f25e067f05e3b",
111-
"size": 89829,
112-
"url": "https://api.github.com/repos/metno/mmd/git/blobs/21bc582a136d0dac8461f66e169f25e067f05e3b"
113-
},
114-
{
115-
"path": "mmd-vocabulary.xml",
116-
"mode": "100644",
117-
"type": "blob",
118-
"sha": "4105803f5f54789116ba840afb5b4e7c22cb4286",
119-
"size": 114697,
120-
"url": "https://api.github.com/repos/metno/mmd/git/blobs/4105803f5f54789116ba840afb5b4e7c22cb4286"
121-
}
122-
],
123-
"truncated": false
124-
}
125-
'''
126-
with mock.patch('requests.get') as mock_get:
127-
mock_get.return_value.text = response
128-
self.assertEqual(
129-
self.voc._get_remote_file_github_blob_sha('master'),
130-
'4105803f5f54789116ba840afb5b4e7c22cb4286')
131-
mock_get.assert_called_with(
132-
'https://api.github.com/repos/metno/mmd/git/trees/master:thesauri')
133-
13490

13591
class DownloadTestCase(unittest.TestCase):
13692
"""Tests for the MMDVocabulary._download_data_file() method"""
13793

13894
def setUp(self):
13995
self.voc = MMDVocabulary(name='test_voc', collection_label='foo')
140-
self.mock_local_sha = mock.patch.object(self.voc, '_get_local_file_github_blob_sha').start()
141-
self.mock_remote_sha = mock.patch.object(
142-
self.voc, '_get_remote_file_github_blob_sha').start()
14396
self.mock_open = mock.patch('pythesint.mmd_vocabulary.open').start()
14497
self.mock_get = mock.patch('requests.get').start()
14598
self.addCleanup(mock.patch.stopall)
@@ -151,24 +104,6 @@ def test_download_data_file_if_not_present(self):
151104

152105
self.mock_get.assert_called_with(self.voc.base_url, stream=True)
153106

154-
def test_download_data_file_if_sha_does_not_match(self):
155-
"""The file should be downloaded if the sha hashes do not match"""
156-
with mock.patch('os.path.isfile', return_value=True):
157-
self.mock_local_sha.return_value = 'a4b5'
158-
self.mock_remote_sha.return_value = 'b4c2'
159-
self.voc._download_data_file()
160-
161-
self.mock_get.assert_called_with(self.voc.base_url, stream=True)
162-
163-
def test_dont_download_data_file_if_sha_match(self):
164-
"""The file should not be downloaded if the sha hashes match"""
165-
with mock.patch('os.path.isfile', return_value=True):
166-
self.mock_local_sha.return_value = 'a4b5'
167-
self.mock_remote_sha.return_value = 'a4b5'
168-
self.voc._download_data_file()
169-
170-
self.mock_get.assert_not_called()
171-
172107
def test_download_data_file_version(self):
173108
"""Test that the specified version is downloaded"""
174109
with mock.patch('os.path.isfile', return_value=False):

0 commit comments

Comments
 (0)