def test_files_get(self, m_FileExt, m_File): sha256 = "whatever" m_response = MagicMock() api_files.get(m_response, sha256) m_File.load_from_sha256.assert_called_once_with(sha256, self.db.session) m_func = m_FileExt.query_find_by_hash m_func.assert_called_once_with("sha256", sha256, None, self.db.session, distinct_name=False)
def test_files_get_offset_limit(self, m_FileExt, m_File): sha256 = "whatever" offset = randint(1000, 2000) limit = randint(0, 1000) m_response = MagicMock() api_files.get(m_response, sha256, offset=offset, limit=limit) m_File.load_from_sha256.assert_called_once_with( sha256, self.db.session) m_query = m_FileExt.query_find_by_hash m_query().limit.assert_called_once_with(limit) m_query().limit().offset.assert_called_once_with(offset)
def test_files_get_offset_limit(self, m_FileExt, m_File): sha256 = "whatever" offset = randint(1000, 2000) limit = randint(0, 1000) m_response = MagicMock() api_files.get(m_response, sha256, offset=offset, limit=limit) m_File.load_from_sha256.assert_called_once_with(sha256, self.db.session) m_query = m_FileExt.query_find_by_hash m_query().limit.assert_called_once_with(limit) m_query().limit().offset.assert_called_once_with(offset)
def test_files_get(self, m_FileExt, m_File): sha256 = "whatever" m_response = MagicMock() api_files.get(m_response, sha256) m_File.load_from_sha256.assert_called_once_with( sha256, self.db.session) m_func = m_FileExt.query_find_by_hash m_func.assert_called_once_with("sha256", sha256, None, self.db.session, distinct_name=False)
def test_download(self, m_File, m_open): sha256 = "whatever" m_response = MagicMock() api_files.get(m_response, sha256, alt="media") m_File.load_from_sha256.assert_called_once_with(sha256, self.session)
def test_files_get_error(self, m_File): sha256 = "whatever" exception = Exception() m_File.load_from_sha256.side_effect = exception with self.assertRaises(Exception): api_files.get(sha256, self.db)