Beispiel #1
0
    def test_read_node_contents(self):
        selector = ModelFileSelector(projection='%(content_file)s', file_field_name='content_file', model_class=Thing)
        node = selector.get_nodes(AbstractNode(selector))[0]

        expected_contents = open(__file__).read()

        self.assertEqual(selector.read_node_contents(node), expected_contents)
Beispiel #2
0
    def test_add_node(self):
        selector = ModelFileSelector(projection='%(content_file)s', file_field_name='content_file', model_class=Thing)
        abs_node = AbstractNode(selector)
        new_node = Node(abstract_node=abs_node, pattern='text_file.txt')

        selector.add_node(new_node)

        node = selector.get_nodes(abs_node)[0]

        self.assertEqual(node.pattern, new_node.pattern)
Beispiel #3
0
    def test_node_contents_length(self):
        selector = ModelFileSelector(projection='%(content_file)s', file_field_name='content_file', model_class=Thing)
        node = selector.get_nodes(AbstractNode(selector))[0]

        with open(__file__) as f:
            f.seek(0, 2)
            expected_file_size = f.tell()
            f.close()

        self.assertEqual(selector.node_contents_length(node), expected_file_size)
Beispiel #4
0
    def test_write_node_contents(self):
        selector = ModelFileSelector(projection='%(content_file)s', file_field_name='content_file', model_class=Thing)
        node = selector.get_nodes(AbstractNode(selector))[0]

        expected_contents = 'Blah blah blah'

        node.write_contents(expected_contents, reset=True)
        self.assertEqual(selector.read_node_contents(node), expected_contents)

        node.write_contents(expected_contents, reset=False)
        self.assertEqual(selector.read_node_contents(node), expected_contents * 2)
Beispiel #5
0
    def test_get_nodes(self):
        from os.path import basename

        selector = ModelFileSelector(projection='%(content_file)s', file_field_name='content_file', model_class=Thing)
        nodes = selector.get_nodes(AbstractNode(selector))

        expected_cotent_file_name = basename(__file__)

        self.assertIsInstance(nodes, list)
        self.assertEqual(len(nodes), 1)
        self.assertEqual(basename(nodes[0].pattern), expected_cotent_file_name)
Beispiel #6
0
today = date.today()

schema = {
    'default': profile([

        #absnode(StaticSelector('users'), [
            #absnode(ModelSelector('%(username)s', User), [

                absnode(
                    QuerySetSelector(
                        'deste_mes',
                        Controle.objects.extra(where=["strftime('%%Y%%m', data) = strftime('%%Y%%m', date('now'))"])
                    ), [
                        absnode(
                            ModelSelector('%(nome)s (%(status)s)', Conta), [
                                absnode(ModelFileSelector(projection='%(arquivo)s', model_class=Conta, file_field_name='arquivo'), writable=True),
                            ]
                        ),
                    ]
                ),

                absnode(
                    QuerySetSelector(
                        'mes_passado',
                        Controle.objects.extra(where=[
                            "strftime('%%Y%%m', data) = strftime('%%Y%%m', date('now', 'start of month', '-1 month'))"
                        ])
                    ), [
                        absnode(
                            ModelSelector('%(nome)s (%(status)s)', Conta), [
                                absnode(ModelFileSelector(projection='%(arquivo)s', model_class=Conta, file_field_name='arquivo'), writable=True),