class TestS3Sub(unittest.TestCase): def setUp(self): self.site = Site() self.config = Config() cfg = { "options": { "s3sub": { "bucket": "asdf", "profile": "asdf", "md5path": "asdf", "redirects": "asdf", "site_url": "asdf", "skip_upload": "asdf" }, "writer": { "directory": "asdf" } } } self.config.from_dict(cfg) def test_compare_md5s_not_found(self): """should add key to changed""" s3d = Deploy(self.site, self.config) s3d.new_md5s["foo"] = 1 s3d.compare_md5s() self.assertEquals(s3d.changed[0], "foo") def test_compare_md5s_changed(self): """should add key to changed""" s3d = Deploy(self.site, self.config) s3d.new_md5s["foo"] = 1 s3d.old_md5s["foo"] = 2 s3d.compare_md5s() self.assertEquals(s3d.changed[0], "foo") def test_compare_md5s_no_change(self): """should add key to changed""" s3d = Deploy(self.site, self.config) s3d.new_md5s["foo"] = 1 s3d.old_md5s["foo"] = 1 s3d.compare_md5s() self.assertEquals(len(s3d.changed), 0) def test_should_upload_skip(self): """should skip uploading""" s3d = Deploy(self.site, self.config) s3d.skip_upload = ["/foo/foo", "bar"] s3d.changed = ["/foo/foo"] self.assertFalse(s3d.should_upload) def test_should_upload(self): """should_upload should return True""" s3d = Deploy(self.site, self.config) s3d.skip_upload = ["foo", "bar"] s3d.changed = ["asdf/foo", "bazbaz/zap"] self.assertTrue(s3d.should_upload)
class TestS3Sub(unittest.TestCase): def setUp(self): self.site = Site() self.config = Config() cfg = { "options": { "s3sub": { "bucket": "asdf", "profile": "asdf", "md5path": "asdf", "redirects": "asdf", "site_url": "asdf", "skip_upload": "asdf" }, "writer": { "directory": "asdf" } } } self.config.from_dict(cfg) def test_compare_md5s_not_found(self): """should add key to changed""" s3d = Deploy(self.site, self.config) s3d.new_md5s["foo"] = 1 s3d.compare_md5s() self.assertEqual(s3d.changed[0], "foo") def test_compare_md5s_changed(self): """should add key to changed""" s3d = Deploy(self.site, self.config) s3d.new_md5s["foo"] = 1 s3d.old_md5s["foo"] = 2 s3d.compare_md5s() self.assertEqual(s3d.changed[0], "foo") def test_compare_md5s_no_change(self): """should add key to changed""" s3d = Deploy(self.site, self.config) s3d.new_md5s["foo"] = 1 s3d.old_md5s["foo"] = 1 s3d.compare_md5s() self.assertEqual(len(s3d.changed), 0) def test_should_upload_skip(self): """should skip uploading""" s3d = Deploy(self.site, self.config) s3d.skip_upload = ["/foo/foo", "bar"] s3d.changed = ["/foo/foo"] self.assertFalse(s3d.should_upload) def test_should_upload(self): """should_upload should return True""" s3d = Deploy(self.site, self.config) s3d.skip_upload = ["foo", "bar"] s3d.changed = ["asdf/foo", "bazbaz/zap"] self.assertTrue(s3d.should_upload)
def setUp(self): config = Config() config.options = { "jinja": { "template": "foo", } } self.entity = Entity(config) site = Site() site.entities.append(self.entity) self.render = Render(site, config)
def setUp(self): self.config = Config() self.config.options = {"markdown": {"extras": "."}} self.site = Site() self.entity = Entity(self.config) self.entity.raw = "foobar"
class TestConfig(unittest.TestCase): def setUp(self): self.yaml = """ reader: bar plugins: ["1", "2", "3"] """ self.cfg = { "reader": "bar", "plugins": ["1", "2", "3"] } self.options = { "reader": { "directory": "foobar", }, "markdown": { "plugins": [1, 2, 3], "highlight": True } } self.config = Config() def test_parse_yaml(self): """should have a reader and plugins set""" self.config.parse_yaml(self.yaml) self.assertEqual(self.config.reader, "bar") self.assertEqual(len(self.config.plugins), 3) def test_config_from_drict(self): """should have a reader and plugins set""" self.config.from_dict(self.cfg) self.assertEqual(self.config.reader, "bar") self.assertEqual(len(self.config.plugins), 3) def test_get_options(self): """should return valid options""" self.config.options = self.options self.assertEqual( self.config.get_option("reader", "directory"), "foobar" ) self.assertEqual(len(self.config.get_option("markdown", "plugins")), 3) self.assertTrue(self.config.get_option("markdown", "highlight")) def test_get_options_exception(self): """should raise an exception""" self.assertRaises(Exception, self.config.get_option) def test_get_option_redirects(self): """should return a dictionary for a root element""" self.config.redirects = {"foo": "bar"} redirects = self.config.get_option(None, "redirects") self.assertEqual(type(redirects), dict)
def setUp(self): self.site = Site() self.config = Config() cfg = { "options": { "s3cf": { "bucket": "asdf", "md5path": "asdf", "redirects": "asdf", "site_url": "asdf", "skip_upload": "asdf", "aws_access_key": "asdf", "aws_secret_key": "asdf", "cloudfront_id": "asdf", }, } } self.config.from_dict(cfg)
def setUp(self): self.yaml = """ reader: bar plugins: ["1", "2", "3"] """ self.cfg = {"reader": "bar", "plugins": ["1", "2", "3"]} self.options = { "reader": { "directory": "foobar", }, "markdown": { "plugins": [1, 2, 3], "highlight": True } } self.config = Config()
def setUp(self): self.site = Site() self.config = Config() cfg = { "options": { "s3sub": { "bucket": "asdf", "profile": "asdf", "md5path": "asdf", "redirects": "asdf", "site_url": "asdf", "skip_upload": "asdf" }, "writer": { "directory": "asdf" } } } self.config.from_dict(cfg)
def setUp(self): self.config = Config() self.config.reader = "filesystem" self.config.options = { "reader": { "directory": "foo", "extension": "md" } } self.site = Site()
def setUp(self): self.config = Config() self.config.options = { "blank": { "generate": { "foo": "bar", "baz": "wusa" } } } self.site = Site()
def setUp(self): self.config = Config() self.config.reader = "filesystem" self.config.options = { "reader": { "content": "foo", "extension": "md", "template": "bar", } } self.site = Site()
class TestConfig(unittest.TestCase): def setUp(self): self.yaml = """ reader: bar plugins: ["1", "2", "3"] """ self.cfg = {"reader": "bar", "plugins": ["1", "2", "3"]} self.options = { "reader": { "directory": "foobar", }, "markdown": { "plugins": [1, 2, 3], "highlight": True } } self.config = Config() def test_parse_yaml(self): """should have a reader and plugins set""" self.config.parse_yaml(self.yaml) self.assertEqual(self.config.reader, "bar") self.assertEqual(len(self.config.plugins), 3) def test_config_from_drict(self): """should have a reader and plugins set""" self.config.from_dict(self.cfg) self.assertEqual(self.config.reader, "bar") self.assertEqual(len(self.config.plugins), 3) def test_get_options(self): """should return valid options""" self.config.options = self.options self.assertEqual(self.config.get_option("reader", "directory"), "foobar") self.assertEqual(len(self.config.get_option("markdown", "plugins")), 3) self.assertTrue(self.config.get_option("markdown", "highlight")) def test_get_options_exception(self): """should raise an exception""" self.assertRaises(Exception, self.config.get_option) def test_get_option_redirects(self): """should return a dictionary for a root element""" self.config.redirects = {"foo": "bar"} redirects = self.config.get_option(None, "redirects") self.assertEqual(type(redirects), dict)
def setUp(self): self.yaml = """ reader: bar plugins: ["1", "2", "3"] """ self.cfg = { "reader": "bar", "plugins": ["1", "2", "3"] } self.options = { "reader": { "directory": "foobar", }, "markdown": { "plugins": [1, 2, 3], "highlight": True } } self.config = Config()
def setUp(self): self.config = Config() self.site = Site() self.plugin = Plugin(self.site, self.config)
class TestS3cf(unittest.TestCase): def setUp(self): self.site = Site() self.config = Config() cfg = { "options": { "s3cf": { "bucket": "asdf", "md5path": "asdf", "redirects": "asdf", "site_url": "asdf", "skip_upload": "asdf", "aws_access_key": "asdf", "aws_secret_key": "asdf", "cloudfront_id": "asdf", }, } } self.config.from_dict(cfg) def test_init_missing_bucket(self): """ should raise an exception if there is a dot in the bucket name and not s3_host specified """ self.config.options["s3cf"]["bucket"] = "foo.bar" self.assertRaises( S3HostMissingException, Deploy, self.site, self.config, ) self.config.options["s3cf"]["s3_host"] = "foo" Deploy(self.site, self.config) def test_guess_mime_type(self): """should guess the correct mime type""" self.assertEqual(guess_mime_type("foo"), "binary/octet-stream") self.assertEqual(guess_mime_type("foo.jpg"), "image/jpeg") self.assertEqual(guess_mime_type("foo.png"), "image/png") self.assertEqual(guess_mime_type("foo.html"), "text/html") self.assertEqual(guess_mime_type("foo.css"), "text/css") def test_redirects(self): """should always get the correct redirects""" deploy = Deploy(self.site, self.config) self.assertEqual(deploy.redirects, "asdf") self.config.redirects = "1234" self.config.options["s3cf"]["redirects"] = None deploy = Deploy(self.site, self.config) self.assertEqual(deploy.redirects, "1234") def test_redirect_exists(self): """should return True if a redirect exists, False if not""" class BucketMock(object): @classmethod def get_key(cls, redirect): return redirect deploy = Deploy(self.site, self.config) deploy.bucket = BucketMock() self.assertTrue(deploy.redirect_exists(True)) self.assertFalse(deploy.redirect_exists(False)) @patch("drupan.deployment.s3cf.Deploy.upload") def test_upload_assets(self, mock): """should only add one asset to the upload dictionary""" deploy = Deploy(self.site, self.config) deploy.site.assets["foo"] = "foo" deploy.site.assets["_bar"] = "bar" deploy.upload_assets() mock.assert_called_once_with("foo", "foo")
def as_config(self): cfg = Config() cfg.parse_yaml(self.yaml) return cfg
def setUp(self): self.config = Config() self.entity = Entity(self.config)