Skip to content

Commit

Permalink
DateConstant: blockly xml parse/create
Browse files Browse the repository at this point in the history
  • Loading branch information
dgk committed Nov 30, 2016
1 parent 4cb17e8 commit 090fbb0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion business_logic/blockly/parse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import datetime
from lxml import etree, objectify

from django.utils.six import StringIO
Expand Down Expand Up @@ -213,12 +213,18 @@ def visit_field_text(self, node):
def visit_field_bool(self, node):
return self._visit_field(BooleanConstant, value=node.text.lower() == 'true')

def visit_field_date(self, node):
return self._visit_field(DateConstant, value=datetime.datetime.strptime(node.text, '%Y-%m-%d').date())

def visit_value(self, node):
return self._visit_single_child(node)

def visit_statement(self, node):
return self._visit_single_child(node)

def visit_block_business_logic_date(self, node):
return self._visit_single_child(node)

def visit_block_business_logic_reference(self, node):
data = {
'data': {
Expand Down
10 changes: 10 additions & 0 deletions tests/blockly/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ def test_create_reference_constant(self):
self.assertIsNot(tree1, tree2)
self.assertFalse(self.tree_diff(tree1, tree2))

def test_create_date(self):
today = datetime.date.today()
tree1 = variable_assign_value(value=DateConstant(value=today))
dict1 = self.build_dict(tree1)

tree2 = NodeTreeCreator().create(dict1)

self.assertIsInstance(tree2, Node)
self.assertIsNot(tree1, tree2)
self.assertFalse(self.tree_diff(tree1, tree2))

def test_create_function(self):
function_definition = PythonCodeFunctionDefinition.objects.create(title='xxx')
Expand Down
3 changes: 3 additions & 0 deletions tests/blockly/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def test_boolean_constant(self):
for value in (True, False):
self._test_constant(BooleanConstant, value)

def test_date_constantant(self):
self._test_constant(DateConstant, datetime.date.today())


class BlocklyXmlParserReferenceConstantTest(BlocklyXmlParserTestCase):
def setUp(self):
Expand Down

0 comments on commit 090fbb0

Please sign in to comment.