2016-05-19 14:53:58 +00:00
|
|
|
# testing imports
|
|
|
|
import pytest
|
2016-05-20 18:19:19 +00:00
|
|
|
import unittest
|
|
|
|
import tempfile
|
|
|
|
import os
|
|
|
|
import requests_mock
|
2016-05-19 14:53:58 +00:00
|
|
|
|
|
|
|
# package imports
|
|
|
|
import celigo
|
|
|
|
|
|
|
|
|
2016-05-20 18:19:19 +00:00
|
|
|
class CeligoTest(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.FAKE_API_KEY = 'fake'
|
|
|
|
|
|
|
|
def test_needs_all_params(self):
|
|
|
|
"""
|
|
|
|
Test that we need to pass in both an api key and a data directory.
|
|
|
|
"""
|
|
|
|
with pytest.raises(TypeError):
|
|
|
|
celigo.BackupCeligo()
|
|
|
|
data_dir = "fakedir"
|
|
|
|
celigo.BackupCeligo(data_dir, self.FAKE_API_KEY)
|
|
|
|
|
|
|
|
def test_ensure_directories(self):
|
|
|
|
"""
|
|
|
|
Test that the ensure_directories_exist works properly.
|
|
|
|
"""
|
|
|
|
tempdir = tempfile.mkdtemp('celigo_testing')
|
|
|
|
bc = celigo.BackupCeligo(tempdir, self.FAKE_API_KEY)
|
|
|
|
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, self.FAKE_API_KEY)
|