class TestsHPCStatsImporter(HPCStatsTestCase):

    def setUp(self):
        self.filename = 'fake'
        self.cluster = 'testcluster'
        HPCStatsConf.__bases__ = (MockConfigParser, object)
        self.conf = HPCStatsConf(self.filename, self.cluster)
        self.conf.conf = CONFIG.copy()
        self.importer = HPCStatsImporter(self.conf, self.cluster, {})
        init_reqs()

    def test_init(self):
        """HPCStatsImporter.__init__() run w/o problem
        """
        pass

    @mock.patch("HPCStats.DB.HPCStatsDB.psycopg2", mock_psycopg2())
    @mock.patch("HPCStats.Importer.Jobs.JobImporterFactory.JobImporterSlurm")
    @mock.patch("HPCStats.Importer.Events.EventImporterFactory.EventImporterSlurm")
    @mock.patch("HPCStats.Importer.FSUsage.FSUsageImporterFactory.FSUsageImporterSSH")
    @mock.patch("HPCStats.Importer.Users.UserImporterFactory.UserImporterLdap")
    @mock.patch("HPCStats.Importer.Architectures.ArchitectureImporterFactory.ArchitectureImporterArchfile")
    def test_run(self, arch_m, user_m, fs_m, event_m, job_m):
        """HPCStatsImporter.run() calls all importer load/update methods.
        """

        # Get mocked classes instances, and configure the cluster attribute of
        # ArchImporter instance
        arch_i = arch_m.return_value
        arch_i.cluster = Cluster(self.cluster, 0)
        user_i = user_m.return_value
        fs_i = fs_m.return_value
        event_i = event_m.return_value
        job_i = job_m.return_value

        self.importer.run()

        arch_i.load.assert_called_once_with()
        arch_i.update.assert_called_once_with()
        user_i.load.assert_called_once_with()
        user_i.update.assert_called_once_with()
        fs_i.load.assert_called_once_with()
        fs_i.update.assert_called_once_with()
        event_i.load.assert_called_once_with()
        event_i.update.assert_called_once_with()
        job_i.load_update_window.assert_called_once_with()

    def test_run_exception_no_hpcstatsdb(self):
        """HPCStatsImporter.run() raise exception when hpcstatsdb section is
           missing.
        """
        del self.conf.conf['hpcstatsdb']

        self.assertRaisesRegexp(
               HPCStatsConfigurationException,
               "section hpcstatsdb not found",
               self.importer.run)
 def setUp(self):
     self.filename = 'fake'
     self.cluster = 'testcluster'
     HPCStatsConf.__bases__ = (MockConfigParser, object)
     self.conf = HPCStatsConf(self.filename, self.cluster)
     self.conf.conf = CONFIG.copy()
     self.importer = HPCStatsImporter(self.conf, self.cluster, {})
     init_reqs()