示例#1
0
class TestsBusinessCodeImporterCSVUpdate(HPCStatsTestCase):
    @mock.patch("HPCStats.DB.HPCStatsDB.psycopg2", mock_psycopg2())
    def setUp(self):
        self.filename = 'fake'
        self.cluster = Cluster('testcluster')
        HPCStatsConf.__bases__ = (MockConfigParser, object)
        self.conf = HPCStatsConf(self.filename, self.cluster.name)
        self.conf.conf = CONFIG
        self.app = None
        self.db = HPCStatsDB(self.conf)
        self.db.bind()
        self.importer = BusinessCodeImporterCSV(self.app, self.db, self.conf)

    def test_update_not_exists(self):
        """ProjectImporterCSV.update() works when business code does not exist
        """
        business1 = Business('code1', 'business description 1')
        self.importer.businesses = [business1]
        self.importer.update()

    @mock.patch("%s.Business.save" % (module))
    def test_update_not_exists_with_mock(self, mock_save):
        """ProjectImporterCSV.update() call Business.save() when business code
           does not exist
        """

        business1 = Business('code1', 'business description 1')

        MockPg2.PG_REQS['existing_business'].set_assoc(
            params=(business1.code, ), result=[])

        self.importer.businesses = [business1]
        self.importer.update()
        mock_save.assert_called_with(self.db)

    def test_update_exists(self):
        """ProjectImporterCSV.update() works when business code exists
        """

        business1 = Business('code1', 'business description 1')

        MockPg2.PG_REQS['existing_business'].set_assoc(
            params=(business1.code, ), result=[['code1']])

        self.importer.businesses = [business1]
        self.importer.update()

    @mock.patch("%s.Business.update" % (module))
    def test_update_exists_with_mock(self, mock_update):
        """ProjectImporterCSV.update() call Business.update() when business
           code exists
        """
        business1 = Business('code1', 'business description 1')

        MockPg2.PG_REQS['existing_business'].set_assoc(
            params=(business1.code, ), result=[['code1']])

        self.importer.businesses = [business1]
        self.importer.update()
        mock_update.assert_called_with(self.db)
class TestsBusinessCodeImporterCSVUpdate(HPCStatsTestCase):

    @mock.patch("HPCStats.DB.HPCStatsDB.psycopg2", mock_psycopg2())
    def setUp(self):
        self.filename = 'fake'
        self.cluster = Cluster('testcluster')
        HPCStatsConf.__bases__ = (MockConfigParser, object)
        self.conf = HPCStatsConf(self.filename, self.cluster.name)
        self.conf.conf = CONFIG
        self.app = None
        self.db = HPCStatsDB(self.conf)
        self.db.bind()
        self.importer = BusinessCodeImporterCSV(self.app, self.db, self.conf)

    def test_update_not_exists(self):
        """ProjectImporterCSV.update() works when business code does not exist
        """
        business1 = Business('code1', 'business description 1')
        self.importer.businesses = [ business1 ]
        self.importer.update()

    @mock.patch("%s.Business.save" % (module))
    def test_update_not_exists_with_mock(self, mock_save):
        """ProjectImporterCSV.update() call Business.save() when business code
           does not exist
        """

        business1 = Business('code1', 'business description 1')

        MockPg2.PG_REQS['existing_business'].set_assoc(
          params=( business1.code, ),
          result=[ ]
        )

        self.importer.businesses = [ business1 ]
        self.importer.update()
        mock_save.assert_called_with(self.db)

    def test_update_exists(self):
        """ProjectImporterCSV.update() works when business code exists
        """

        business1 = Business('code1', 'business description 1')

        MockPg2.PG_REQS['existing_business'].set_assoc(
          params=( business1.code, ),
          result=[ [ 'code1' ] ]
        )

        self.importer.businesses = [ business1 ]
        self.importer.update()

    @mock.patch("%s.Business.update" % (module))
    def test_update_exists_with_mock(self, mock_update):
        """ProjectImporterCSV.update() call Business.update() when business
           code exists
        """
        business1 = Business('code1', 'business description 1')

        MockPg2.PG_REQS['existing_business'].set_assoc(
          params=( business1.code, ),
          result=[ [ 'code1' ] ]
        )

        self.importer.businesses = [ business1 ]
        self.importer.update()
        mock_update.assert_called_with(self.db)