Exemplo n.º 1
0
    def test_system_exporter_markdown_cron_markdown_path_no_write_permission(self):
        """test markdown export via scheduled task to server file system"""

        # change config
        set_markdown_path('/root')

        # export markdown without GET by directly calling the function
        system_cron()

        # login testuser
        self.client.login(
            username='******',
            password='******',
        )
        # get response
        response = self.client.get('/system/')
        # get messages
        messages = list(get_messages(response.wsgi_request))
        # compare
        self.assertEqual(
            str(response.context['user']), 'testuser_system_exporter_markdown'
        )
        self.assertEqual(
            messages[0].message,
            '[Scheduled task markdown exporter] No write permission for markdown path. Check config or file system!',
        )
        self.assertEqual(messages[0].level_tag, 'error')
        # switch user context
        self.client.logout()
        self.client.login(username='******', password='******')
        # get response
        response = self.client.get('/system/')
        # get messages
        messages = list(get_messages(response.wsgi_request))
        # compare
        self.assertEqual(str(response.context['user']), 'message_user')
        self.assertEqual(
            messages[0].message,
            '[Scheduled task markdown exporter] No write permission for markdown path. Check config or file system!',
        )
        self.assertEqual(messages[0].level_tag, 'error')
    def test_system_exporter_markdown_cron_domainsorted(self):
        """ test markdown export via scheduled task to server file system """

        # change config
        set_markdown_sorting_dom()

        # export markdown without GET by directly calling the function
        system_cron()

        # compare
        self.assertTrue(os.path.exists('/tmp/dfirtrack_test/docs/systems/'))
        self.assertTrue(
            os.path.exists('/tmp/dfirtrack_test/docs/systems/domain_1/'))
        self.assertTrue(
            os.path.exists('/tmp/dfirtrack_test/docs/systems/domain_2/'))
        self.assertTrue(
            os.path.exists('/tmp/dfirtrack_test/docs/systems/other_domains/'))
        self.assertTrue(os.path.isfile('/tmp/dfirtrack_test//mkdocs.yml'))
        self.assertTrue(
            os.path.isfile(
                '/tmp/dfirtrack_test/docs/systems/domain_1/system_1_domain_1_20200102_123456.md'
            ))
        self.assertTrue(
            os.path.isfile(
                '/tmp/dfirtrack_test/docs/systems/domain_2/system_2_domain_2.md'
            ))
        self.assertTrue(
            os.path.isfile(
                '/tmp/dfirtrack_test/docs/systems/other_domains/system_3.md'))
        self.assertFalse(
            os.path.isfile(
                '/tmp/dfirtrack_test/docs/systems/other_domains/system_4.md'))
        self.assertTrue(
            os.path.isfile(
                '/tmp/dfirtrack_test/docs/systems/domain_2/system_5_domain_2.md'
            ))
        self.assertTrue(
            os.path.isfile(
                '/tmp/dfirtrack_test/docs/systems/other_domains/system_6.md'))
        self.assertTrue(
            filecmp.cmp(
                '/tmp/dfirtrack_test/docs/systems/domain_1/system_1_domain_1_20200102_123456.md',
                os.path.join(
                    BASE_DIR,
                    'dfirtrack_main/tests/system/files/system_exporter_markdown_testfile_system_1.md'
                ),
                shallow=False))
        self.assertTrue(
            filecmp.cmp(
                '/tmp/dfirtrack_test/docs/systems/domain_2/system_2_domain_2.md',
                os.path.join(
                    BASE_DIR,
                    'dfirtrack_main/tests/system/files/system_exporter_markdown_testfile_system_2.md'
                ),
                shallow=False))
        self.assertTrue(
            filecmp.cmp(
                '/tmp/dfirtrack_test/docs/systems/other_domains/system_3.md',
                os.path.join(
                    BASE_DIR,
                    'dfirtrack_main/tests/system/files/system_exporter_markdown_testfile_system_3.md'
                ),
                shallow=False))
        self.assertTrue(
            filecmp.cmp(
                '/tmp/dfirtrack_test/docs/systems/domain_2/system_5_domain_2.md',
                os.path.join(
                    BASE_DIR,
                    'dfirtrack_main/tests/system/files/system_exporter_markdown_testfile_system_5.md'
                ),
                shallow=False))
        self.assertTrue(
            filecmp.cmp(
                '/tmp/dfirtrack_test/docs/systems/other_domains/system_6.md',
                os.path.join(
                    BASE_DIR,
                    'dfirtrack_main/tests/system/files/system_exporter_markdown_testfile_system_6.md'
                ),
                shallow=False))