def test_content_type_no_cache(self, m_getFile): # Mocking such that we simulate a valid API root and an existing # item reference # Dummy requests return value expected_mimetype = 'some/type' m_getFile.return_value = {'mimeType': expected_mimetype} e = GirderDataElement('foo') actual_type = e.content_type() nose.tools.assert_equal(actual_type, expected_mimetype) m_getFile.assert_called_once() # Ensure that calling content_type a second time doesn't call getFile again nose.tools.assert_equal(e.content_type(), expected_mimetype) m_getFile.assert_called_once()
def test_content_type_no_cache(self, m_getFile): # Mocking such that we simulate a valid API root and an existing # item reference # Dummy requests return value expected_mimetype = 'some/type' m_getFile.return_value = { 'mimeType': expected_mimetype } e = GirderDataElement('foo') actual_type = e.content_type() self.assertEqual(actual_type, expected_mimetype) m_getFile.assert_called_once() # Ensure that calling content_type a second time doesn't call # getFile again. self.assertEqual(e.content_type(), expected_mimetype) m_getFile.assert_called_once()
def test_content_type_cached(self, m_gtm, m_requests): expected_mimetype = 'some/type' e = GirderDataElement('id') e._content_type = expected_mimetype actual_type = e.content_type() nose.tools.assert_equal(actual_type, expected_mimetype) nose.tools.assert_equal(m_requests.get.call_count, 0) nose.tools.assert_equal(m_requests.get().json.call_count, 0)
def test_content_type_no_cache(self, m_gtm, m_requests): # Mocking such that we simulate a valid API root and an existing # item reference # Dummy requests return value expected_mimetype = 'some/type' m_requests.get('setting json mock return value')\ .json.return_value = { 'mimeType': expected_mimetype } e = GirderDataElement('foo') actual_type = e.content_type() nose.tools.assert_equal(actual_type, expected_mimetype) # once above to set return_value and once it function nose.tools.assert_equal(m_requests.get.call_count, 2) m_requests.get().json.assert_called_once()