diff --git a/Dockerfile b/Dockerfile index 11c3390..ddf2df0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,7 +20,7 @@ RUN apt-get update -y && \ phantomjs \ wget \ postgresql-11 \ - git + git RUN apt-get autoremove -y diff --git a/Makefile b/Makefile index 97ec990..67786db 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,11 @@ +run: + docker-compose -f docker-compose.yml + run-development: - docker-compose -f docker-compose.yml -f docker-compose.db.yml -f docker-compose.development.yml up --build + docker-compose -f docker-compose.yml -f docker-compose.db.yml -f docker-compose.development.yml up ci: - docker-compose -f docker-compose.yml -f docker-compose.test.yml build - docker-compose -f docker-compose.yml -f docker-compose.test.yml run --rm --entrypoint "nosetests" sirius \ No newline at end of file + docker-compose -f docker-compose.yml -f docker-compose.test.yml run --rm --entrypoint "nosetests" sirius + +ci-snapshot-update: + docker-compose -f docker-compose.yml -f docker-compose.test.yml run --rm --entrypoint "nosetests --snapshot-update" sirius \ No newline at end of file diff --git a/docker-compose.development.yml b/docker-compose.development.yml index 3e212d0..9bc1383 100644 --- a/docker-compose.development.yml +++ b/docker-compose.development.yml @@ -8,6 +8,8 @@ services: - VIRTUAL_HOST=sirius.localhost - DATABASE_URL=postgresql://postgres:plop@sirius-database/sirius-dev - OAUTHLIB_INSECURE_TRANSPORT=1 + volumes: + - ./:/sirius sirius-database: ports: diff --git a/docker-compose.test.yml b/docker-compose.test.yml index ca02c6d..3167108 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -9,6 +9,8 @@ services: command: "bin/wait-for-it.sh sirius-database-test:5432 -- bin/docker-entrypoint.sh" environment: - DATABASE_URL=postgresql://postgres:plop@sirius-database-test/sirius-test + volumes: + - ./:/sirius sirius-database-test: container_name: sirius-database-test diff --git a/requirements.txt b/requirements.txt index 8ab88a2..93e819e 100755 --- a/requirements.txt +++ b/requirements.txt @@ -36,5 +36,6 @@ requests==2.22.0 requests-oauthlib==1.2.0 selenium==3.141.0 six==1.12.0 +git+git://github.com/syrusakbary/snapshottest.git@4ac2b4fb09e9e7728bebb11967c164a914775d1d#snapshottest twitter==1.18.0 websocket-client==0.56.0 diff --git a/sirius/coding/snapshots/__init__.py b/sirius/coding/snapshots/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sirius/coding/snapshots/snap_test_image_coding_snapshots.py b/sirius/coding/snapshots/snap_test_image_coding_snapshots.py new file mode 100644 index 0000000..06aa55c --- /dev/null +++ b/sirius/coding/snapshots/snap_test_image_coding_snapshots.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# snapshottest: v1 - https://goo.gl/zC4yUc +from __future__ import unicode_literals + +from snapshottest import Snapshot +from snapshottest.file import FileSnapshot + + +snapshots = Snapshot() + +snapshots['ImageCodingSnapshotCase::test_snapshot_fixtures hello_world'] = FileSnapshot('snap_test_image_coding_snapshots/ImageCodingSnapshotCase::test_snapshot_fixtures hello_world.png') + +snapshots['ImageCodingSnapshotCase::test_snapshot_template_fixtures hello_world'] = FileSnapshot('snap_test_image_coding_snapshots/ImageCodingSnapshotCase::test_snapshot_template_fixtures hello_world.png') diff --git a/sirius/coding/snapshots/snap_test_image_coding_snapshots/ImageCodingSnapshotCase::test_snapshot_fixtures hello_world.png b/sirius/coding/snapshots/snap_test_image_coding_snapshots/ImageCodingSnapshotCase::test_snapshot_fixtures hello_world.png new file mode 100644 index 0000000..b8389f2 Binary files /dev/null and b/sirius/coding/snapshots/snap_test_image_coding_snapshots/ImageCodingSnapshotCase::test_snapshot_fixtures hello_world.png differ diff --git a/sirius/coding/snapshots/snap_test_image_coding_snapshots/ImageCodingSnapshotCase::test_snapshot_template_fixtures hello_world.png b/sirius/coding/snapshots/snap_test_image_coding_snapshots/ImageCodingSnapshotCase::test_snapshot_template_fixtures hello_world.png new file mode 100644 index 0000000..15104fb Binary files /dev/null and b/sirius/coding/snapshots/snap_test_image_coding_snapshots/ImageCodingSnapshotCase::test_snapshot_template_fixtures hello_world.png differ diff --git a/sirius/coding/templating.py b/sirius/coding/templating.py index 188ad4d..ef90484 100644 --- a/sirius/coding/templating.py +++ b/sirius/coding/templating.py @@ -8,13 +8,16 @@ # TODO apply scrubber library if wanted. # https://pypi.python.org/pypi/scrubber -def default_template(raw_html, from_name): +def default_template(raw_html, from_name, date=None): + if date is None: + date = datetime.datetime.now() + with open(DEFAULT_TEMPLATE_FILE) as f: template = f.read() t = ENV.from_string(template) return t.render( raw_html=raw_html, - date=datetime.datetime.now(), + date=date, from_name=from_name ) diff --git a/sirius/coding/test_image_coding.py b/sirius/coding/test_image_coding.py index 081b8af..c8b684f 100644 --- a/sirius/coding/test_image_coding.py +++ b/sirius/coding/test_image_coding.py @@ -3,7 +3,6 @@ from sirius.coding import image_encoding - class ImageCase(unittest.TestCase): def test_normal_text(self): data = image_encoding.html_to_png( diff --git a/sirius/coding/test_image_coding_snapshots.py b/sirius/coding/test_image_coding_snapshots.py new file mode 100644 index 0000000..d6e920a --- /dev/null +++ b/sirius/coding/test_image_coding_snapshots.py @@ -0,0 +1,48 @@ +import os +import datetime +from tempfile import TemporaryDirectory +from PIL import Image + +import snapshottest +from snapshottest.file import FileSnapshot + +from sirius.coding import image_encoding +from sirius.coding import templating + + +class ImageCodingSnapshotCase(snapshottest.TestCase): + def _check_html(self, name, html): + print('Cheking fixture named: %s' % name) + + with TemporaryDirectory() as tmpdir: + data = image_encoding.html_to_png(html) + image = Image.open(data) + + temp_file_name = os.path.join(tmpdir, '%s.png' % name) + image.save(temp_file_name, format='PNG') + self.assertMatchSnapshot(FileSnapshot(temp_file_name), name) + + def test_snapshot_fixtures(self): + fixtures = { + 'hello_world': 'Hello, world!', + } + + for name, html in fixtures.items(): + self._check_html(name, html) + + def test_snapshot_template_fixtures(self): + fixtures = { + 'hello_world': '

Hello, world!

', + } + + fixture_username = 'somebody' + fixture_date = datetime.datetime(2012, 2, 3, 15, 46, 12) + + for name, snippet in fixtures.items(): + self._check_html( + name, templating.default_template( + snippet, + fixture_username, + fixture_date + ) + ) \ No newline at end of file