Skip to content

Commit

Permalink
☔ Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ayan-b committed Feb 2, 2019
1 parent bb6c9a3 commit 45a9275
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
3 changes: 1 addition & 2 deletions moban_velocity/engine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
import codecs

from airspeed import Template
Expand All @@ -19,7 +18,7 @@ def get_template(self, template_file):

def get_template_from_string(self, string):
return Template(string)

def apply_template(self, template, data, output):
rendered_content = template.merge(data)
return rendered_content
8 changes: 8 additions & 0 deletions tests/fixtures/velocity_tests/expected_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Old people:

Bill

Bob


Third person is Mark
8 changes: 8 additions & 0 deletions tests/fixtures/velocity_tests/file_tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"people":[
{"name": "Bill", "age": 100},
{"name": "Bob", "age": 90},
{"name": "Mark", "age": 25}
],
"hello": "World!"
}
8 changes: 8 additions & 0 deletions tests/fixtures/velocity_tests/file_tests.velocity
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Old people:
#foreach ($person in $people)
#if($person.age > 70)
$person.name
#end
#end

Third person is $people[2].name
39 changes: 39 additions & 0 deletions tests/test_velocity_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os

from nose.tools import eq_
from moban.plugins import ENGINES, BaseEngine
from moban_velocity.engine import EngineVelocity


def test_velocity_engine_type():
engine = ENGINES.get_engine("velocity", [], "")
assert engine.engine_cls == EngineVelocity
pass


def test_velocity_file_test():
output = "test.txt"
path = os.path.join("tests", "fixtures", "velocity_tests")
engine = BaseEngine(path, path, EngineVelocity)
engine.render_to_file("file_tests.velocity", "file_tests.json", output)
with open(output, "r") as output_file:
expected_path = os.path.join("tests", "fixtures", "velocity_tests",
"expected_output.txt")
with open(expected_path) as expected_file:
expected = expected_file.read()
content = output_file.read()
eq_(content, expected)
os.unlink(output)


def test_velocity_string_template():
string_template = "Hello $hello"
output = "test.txt"
path = os.path.join("tests", "fixtures", "velocity_tests")
engine = BaseEngine(path, path, EngineVelocity)
engine.render_string_to_file(string_template, "file_tests.json", output)
with open(output, "r") as output_file:
expected = "Hello World!"
content = output_file.read()
eq_(content, expected)
os.unlink(output)

0 comments on commit 45a9275

Please sign in to comment.