Ignore:
Timestamp:
29/04/09 17:18:46 (11 years ago)
Author:
cbyrom
Message:

Add code to retrieve repository info by name - and add appropriate tests.

Location:
TI01-discovery/trunk/OAIInfoEditor/oai_info_editor
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/dal/editorfileclient.py

    r5233 r5238  
    227227        Get the change request details for the specified list 
    228228        @param providerInfoName: name of the provider info to retrieve  
    229         @raise ValueError: if provider info with name not found 
    230         @return ProviderInfo: object with requested data in or None, if data not found 
     229        @return ProviderInfo: object with requested data - or None if no data found 
    231230        '''  
    232231        logging.info("Retrieving provider info with name, '%s'" %(providerInfoName)) 
     
    241240             
    242241        return pi 
     242         
     243         
     244    def getRepositoryInfo(self, providerInfoName, repositoryInfoName): 
     245        ''' 
     246        Get the repository info object for the specified provider and repository name 
     247        @param providerInfoName: name of the provider info to retrieve  
     248        @param repositoryInfoName: name of the repository info to retrieve  
     249        @return RepositoryInfo object with the requested data - or None if no data found 
     250        ''' 
     251        logging.debug("Retrieving repository info, '%s' for provider, '%s'" \ 
     252                      %(repositoryInfoName, providerInfoName)) 
     253        ri = None 
     254        self.pic, fileName = self.__getProviderInfoData() 
     255         
     256        try: 
     257            pi = self.pic.getProviderInfoByName(providerInfoName) 
     258            ri = pi.getRepositoryInfoByName(repositoryInfoName) 
     259            logging.info("- returning repository info details") 
     260        except ValueError: 
     261            logging.info("- no data found with specified name - returning None") 
     262        return ri 
    243263 
    244264 
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/dal/interfaceeditordbclient.py

    r5233 r5238  
    3838                                  "been implemented yet") 
    3939   
     40   
    4041    def getProviderInfo(self, providerInfoName): 
    4142        ''' 
     
    4546        raise NotImplementedError("This is an interface class and this method has not " + \ 
    4647                                  "been implemented yet") 
     48 
     49                
     50    def getRepositoryInfo(self, providerInfoName, repositoryInfoName): 
     51        ''' 
     52        Get the repository info object for the specified provider and repository name 
     53        @param providerInfoName: name of the provider info to retrieve  
     54        @param repositoryInfoName: name of the repository info to retrieve  
     55        @raise ValueError: if repository info with name not found 
     56        @return RepositoryInfo object with the requested data 
     57        ''' 
     58        raise NotImplementedError("This is an interface class and this method has not " + \ 
     59                                  "been implemented yet") 
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/dal/providerinfodao.py

    r5233 r5238  
    2323    @return: ProviderInfoDAO with the specified data access client type 
    2424    ''' 
    25     logging.info("Setting up DAO with '%s' editor client" %client) 
     25    logging.debug("Setting up DAO with '%s' editor client" %client) 
    2626    if client == FILE_CLIENT_TYPE: 
    2727         
     
    3636    dao = ProviderInfoDAO(client) 
    3737     
    38     logging.info("- returning DAO") 
     38    logging.debug("- returning DAO") 
    3939    return dao 
    4040 
     
    5151        vocabtermeditor.dal.InterfaceEditorDataClient interface 
    5252        ''' 
    53         logging.info("Initialising ProviderInfoDAO object") 
     53        logging.debug("Initialising ProviderInfoDAO object") 
    5454 
    5555        if not isinstance(client, InterfaceEditorDataClient): 
     
    5858        self.client = client 
    5959 
    60         logging.info("ProviderInfoDAO initialised") 
     60        logging.debug("ProviderInfoDAO initialised") 
    6161     
    6262         
     
    9494        @param providerInfoName: name of the provider info to retrieve  
    9595        @raise ValueError: if provider info with name not found 
    96         @return ProviderInfo object with the requested data or None if data not found 
     96        @return ProviderInfo object with the requested data 
    9797        ''' 
    9898        return self.client.getProviderInfo(providerInfoName) 
     99         
     100         
     101    def getRepositoryInfo(self, providerInfoName, repositoryInfoName): 
     102        ''' 
     103        Get the repository info object for the specified provider and repository name 
     104        @param providerInfoName: name of the provider info to retrieve  
     105        @param repositoryInfoName: name of the repository info to retrieve  
     106        @raise ValueError: if repository info with name not found 
     107        @return RepositoryInfo object with the requested data 
     108        ''' 
     109        return self.client.getRepositoryInfo(providerInfoName, repositoryInfoName) 
    99110 
    100111 
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/model/providerinfo.py

    r5232 r5238  
    136136 
    137137     
    138      
    139138    def removeRepositoryInfo(self, repositoryInfo): 
    140139        ''' 
     
    154153        self.repositoryInfos = ris 
    155154        logging.debug("- provider info removed") 
     155 
     156 
     157    def getRepositoryInfoByName(self, repositoryInfoName): 
     158        ''' 
     159        Return repository info record with the specified name 
     160        @param repositoryInfoName: name of repository info record to return 
     161        @raise ValueError: if name not found  
     162        @return RepositoryInfo object with matching name 
     163        ''' 
     164        logging.debug("Retrieving provider info with name, '%s'" %repositoryInfoName) 
     165 
     166        for ri in self.repositoryInfos: 
     167            if ri.name == repositoryInfoName: 
     168                logging.debug("- returning repository info with matching name") 
     169                return ri 
     170                 
     171        raise ValueError("Repository info with name, '%s' not found in collection" %repositoryInfoName) 
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/model/providerinfocollection.py

    r5235 r5238  
    214214        for pi in self.providerInfos: 
    215215            if pi.name == providerInfoName: 
    216                 logging.debug("- returning request with matching name") 
     216                logging.debug("- returning provider info with matching name") 
    217217                return pi 
    218218                 
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/tests/dal/testeditorfileclient.py

    r5233 r5238  
    141141 
    142142 
     143    def testGetRepositoryInfo(self): 
     144        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_2) 
     145        self.files.append(fileName) 
     146 
     147        ri = self.client.getRepositoryInfo(PROVIDER_INFO_2.name, VALID_REP_NAME_1) 
     148        self.assertEquals(VALID_REP_NAME_1, ri.name) 
     149        self.assertEquals(VALID_REP_URL, ri.url) 
     150        self.assertEquals(VALID_DIF_DATA_FORMAT, ri.dataFormat) 
     151        self.assertEquals(VALID_SET_SPEC_1, ri.setSpec) 
     152        self.assertEquals(VALID_MODIFICATION_DATE, ri.modificationDate) 
     153        self.assertEquals('', ri.harvestTime) 
     154        self.assertEquals(False, ri.splitBySet) 
     155 
     156 
     157    def testInvalidGetProviderInfo(self): 
     158        ri = self.client.getRepositoryInfo(PROVIDER_INFO_1, VALID_REP_NAME_1) 
     159        self.assertEquals(None, ri) 
     160 
     161 
    143162    def testGetProviderInfoForUser(self): 
    144163        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_1) 
     
    176195        for pi in pis: 
    177196            self.assertTrue(pi.name in ALL_VALID_PROVIDER_NAMES) 
     197 
     198 
    178199         
    179200    def tearDown(self): 
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/tests/dal/testproviderinfodaowithfileclient.py

    r5226 r5238  
    5858 
    5959 
     60    def testGetRepositoryInfo(self): 
     61        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_2) 
     62        self.files.append(fileName) 
     63 
     64        ri = self.dao.getRepositoryInfo(PROVIDER_INFO_2.name, VALID_REP_NAME_1) 
     65        self.assertEquals(VALID_REP_NAME_1, ri.name) 
     66        self.assertEquals(VALID_REP_URL, ri.url) 
     67        self.assertEquals(VALID_DIF_DATA_FORMAT, ri.dataFormat) 
     68        self.assertEquals(VALID_SET_SPEC_1, ri.setSpec) 
     69        self.assertEquals(VALID_MODIFICATION_DATE, ri.modificationDate) 
     70        self.assertEquals('', ri.harvestTime) 
     71        self.assertEquals(False, ri.splitBySet) 
     72 
     73 
     74    def testInvalidGetProviderInfo(self): 
     75        ri = self.dao.getRepositoryInfo(PROVIDER_INFO_1, VALID_REP_NAME_1) 
     76        self.assertEquals(None, ri) 
     77 
     78 
    6079    def testGetProviderInfoForUser(self): 
    6180        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_1) 
     
    95114         
    96115 
    97  
    98  
    99116    def tearDown(self): 
    100117         
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/tests/model/testproviderinfo.py

    r5226 r5238  
    5353        xml = xml.replace(' ', '') 
    5454        xml = xml.replace('\n', '') 
     55        xml = xml.replace('\r', '') 
    5556        origXML = PROV_INFO_XML_STRING.replace(' ', '') 
    5657        origXML = origXML.replace('\t', '') 
    5758        origXML = origXML.replace('\n', '') 
     59        origXML = origXML.replace('\r', '') 
    5860        self.assertEquals(origXML, xml) 
    5961         
     
    6264        self.assertEquals(3, len(self.pi.repositoryInfos)) 
    6365        self.assertEquals(VALID_PROVIDER_NAME_2, self.pi.name) 
     66 
     67 
     68    def testGetRepositoryInfoByName(self): 
     69        ri = PROVIDER_INFO_2.getRepositoryInfoByName(VALID_REP_NAME_1) 
     70        self.assertEquals(VALID_REP_NAME_1, ri.name) 
     71        self.assertEquals(VALID_REP_URL, ri.url) 
     72        self.assertEquals(VALID_DIF_DATA_FORMAT, ri.dataFormat) 
     73        self.assertEquals(VALID_SET_SPEC_1, ri.setSpec) 
     74        self.assertEquals(VALID_MODIFICATION_DATE, ri.modificationDate) 
     75        self.assertEquals('', ri.harvestTime) 
     76        self.assertEquals(False, ri.splitBySet) 
     77         
     78 
     79    def testInvalidGetRepositoryInfoByName(self): 
     80        self.assertRaises(ValueError, PROVIDER_INFO_1.getRepositoryInfoByName, VALID_REP_NAME_1) 
     81         
     82         
  • TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/tests/model/testproviderinfocollection.py

    r5226 r5238  
    6464        xml = xml.replace(' ', '') 
    6565        xml = xml.replace('\n', '') 
     66        xml = xml.replace('\r', '') 
    6667        origXML = PROV_INFO_COLLECTION_XML_STRING.replace(' ', '') 
    6768        origXML = origXML.replace('\t', '') 
    6869        origXML = origXML.replace('\n', '') 
     70        origXML = origXML.replace('\r', '') 
    6971        self.assertEquals(origXML, xml) 
    7072 
     
    102104    def testRemoveProviderInfo(self): 
    103105        self.pic.setData(VALID_HARVEST_DIR, VALID_PROVIDER_INFOS) 
    104         self.pic.removeProviderInfo(PROVIDER_INFO_1) 
     106        self.pic.removeProviderInfo(VALID_PROVIDER_NAME_1) 
    105107        self.assertEquals('1', self.pic.version) 
    106108        self.assertEquals(DUMMY_PIC_FILENAME, self.pic.fileName) 
     
    110112    def testInvalidRemoveProviderInfo(self): 
    111113        self.pic.setData(VALID_HARVEST_DIR, VALID_PROVIDER_INFOS) 
    112         self.pic.removeProviderInfo(PROVIDER_INFO_1) 
     114        self.pic.removeProviderInfo(VALID_PROVIDER_NAME_1) 
    113115        self.assertEquals('1', self.pic.version) 
    114116        self.assertEquals(DUMMY_PIC_FILENAME, self.pic.fileName) 
    115117        self.assertEquals(2, len(self.pic.providerInfos)) 
    116         self.pic.removeProviderInfo(PROVIDER_INFO_1) 
     118        self.pic.removeProviderInfo(VALID_PROVIDER_NAME_1) 
    117119        self.assertEquals('1', self.pic.version) 
    118120        self.assertEquals(DUMMY_PIC_FILENAME, self.pic.fileName) 
     
    137139        pis = PROVIDER_INFO_COLLECTION.getProviderInfoForUser(INVALID_USER) 
    138140        self.assertEquals([], pis) 
     141 
     142 
     143    def testGetProviderInfoByName(self): 
     144        pi = PROVIDER_INFO_COLLECTION.getProviderInfoByName(VALID_PROVIDER_NAME_1) 
     145        self.assertEquals(VALID_PROVIDER_NAME_1, pi.name) 
     146        self.assertEquals(len(VALID_REPOSITORY_INFOS_1), len(pi.repositoryInfos)) 
     147        self.assertEquals(VALID_REPOSITORY_INFOS_1, pi.repositoryInfos) 
    139148         
     149 
     150    def testInvalidGetProviderInfoByName(self): 
     151        self.assertRaises(ValueError, PROVIDER_INFO_COLLECTION.getProviderInfoByName, VALID_USER_ID) 
     152 
    140153 
    141154    def __standardTests(self): 
Note: See TracChangeset for help on using the changeset viewer.