Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RUN apt-get update -y && \
phantomjs \
wget \
postgresql-11 \
git
git

RUN apt-get autoremove -y

Expand Down
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
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
2 changes: 2 additions & 0 deletions docker-compose.development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Empty file.
13 changes: 13 additions & 0 deletions sirius/coding/snapshots/snap_test_image_coding_snapshots.py
Original file line number Diff line number Diff line change
@@ -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')
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions sirius/coding/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
1 change: 0 additions & 1 deletion sirius/coding/test_image_coding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
48 changes: 48 additions & 0 deletions sirius/coding/test_image_coding_snapshots.py
Original file line number Diff line number Diff line change
@@ -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': '<html><body>Hello, world!</body></html>',
}

for name, html in fixtures.items():
self._check_html(name, html)

def test_snapshot_template_fixtures(self):
fixtures = {
'hello_world': '<p>Hello, world!</p>',
}

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
)
)