Skip to content

Commit 4cb17e8

Browse files
committed
DateConstant: blockly xml build
1 parent a15caaa commit 4cb17e8

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

business_logic/blockly/build.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ def visit_constant(self, node, parent_xml):
6767
NumberConstant: 'math_number',
6868
StringConstant: 'text',
6969
BooleanConstant: 'logic_boolean',
70+
DateConstant: 'business_logic_date',
7071
}
7172
field_name = {
7273
NumberConstant: 'NUM',
7374
StringConstant: 'TEXT',
7475
BooleanConstant: 'BOOL',
76+
DateConstant: 'DATE',
7577
}
7678
content_object = node.content_object
7779
cls = content_object.__class__

tests/blockly/test_build.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,22 @@ def test_block_if_sequence(self):
159159
block = block[0]
160160
self.assertEqual('controls_if', block.get('type'))
161161

162+
class BlocklyXmlDateTest(TestCase):
163+
def test_block_date(self):
164+
today = datetime.date.today()
165+
root = Node.add_root(content_object=DateConstant(value=today))
166+
xml_str = BlocklyXmlBuilder().build(root)
167+
xml = etree.parse(StringIO(xml_str))
168+
169+
block = xml.xpath('/xml/block')
170+
self.assertEqual(1, len(block))
171+
block = block[0]
172+
self.assertEqual('business_logic_date', block.get('type'))
173+
174+
field = block.find('field')
175+
self.assertEqual('DATE', field.get('name'))
176+
self.assertEqual(today.strftime('%Y-%m-%d'), field.text)
177+
162178

163179
class BlocklyXmlBuilderBinaryOperatorTest(TestCase):
164180
def _test_math_binary_operator(self, operator, block_type, operator_field_value):

tests/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
import unittest
4+
import datetime
45

56
from decimal import Decimal
67
from pprint import pprint

0 commit comments

Comments
 (0)