Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)