5ee6c1579f
Added default to the package init. Redid testing suite to use unittest. Allow headers to be overwritten.
60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
# 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'
|
|
|
|
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)
|