# testing imports import pytest import unittest import tempfile import os import requests_mock # package imports import celigo class CeligoTest(unittest.TestCase): def setUp(self): self.FAKE_API_KEY = 'fake' os.environ['CELIGO_API_KEY'] = self.FAKE_API_KEY def test_needs_all_params(self): """ Test that we need to pass in a data directory. """ with self.assertRaises(TypeError): celigo.BackupCeligo() data_dir = "fakedir" celigo.BackupCeligo(data_dir) def test_needs_api_key_env(self): """ Test that we need to pass in a data directory. """ data_dir = "fakedir" os.environ['CELIGO_API_KEY'] = '' with self.assertRaises(Exception): celigo.BackupCeligo(data_dir) os.environ['CELIGO_API_KEY'] = self.FAKE_API_KEY celigo.BackupCeligo(data_dir) def test_ensure_directories(self): """ Test that the ensure_directories_exist works properly. """ tempdir = tempfile.mkdtemp('celigo_testing') bc = celigo.BackupCeligo(tempdir) imports_dir = os.path.join(tempdir, "imports") connections_dir = os.path.join(tempdir, "connections") # Check that the directories don't exist already. self.assertFalse( os.path.exists(imports_dir), "imports dir exists") self.assertFalse( os.path.exists(connections_dir), "connections dir exists") # Make the directories. bc.ensure_directories_exist() self.assertTrue( os.path.exists(imports_dir), "Did not create proper directory" ) self.assertTrue( os.path.exists(connections_dir), "Did not create proper directory" ) # Make sure nothing errors if the directories exist already. bc.ensure_directories_exist() @requests_mock.Mocker() def test_fake_requests(self, rqm): rqm.get(celigo.DEFAULT_BASE_URL, text='resp') tempdir = tempfile.mkdtemp('celigo_testing') bc = celigo.BackupCeligo(tempdir)