diff --git a/config/invenio.conf b/config/invenio.conf index ac365c821..c796f7c1e 100644 --- a/config/invenio.conf +++ b/config/invenio.conf @@ -1,905 +1,905 @@ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ################################################### ## About 'invenio.conf' and 'invenio-local.conf' ## ################################################### ## The 'invenio.conf' file contains the vanilla default configuration ## parameters of a CDS Invenio installation, as coming from the ## distribution. The file should be self-explanatory. Once installed ## in its usual location (usually /opt/cds-invenio/etc), you could in ## principle go ahead and change the values according to your local ## needs. ## ## However, you can also create a file named 'invenio-local.conf' in ## the same directory where 'invenio.conf' lives and put there only ## the localizations you need to have different from the default ones. ## For example: ## ## $ cat /opt/cds-invenio/etc/invenio-local.conf ## [Invenio] ## CFG_SITE_URL = http://your.site.com ## CFG_SITE_SECURE_URL = https://your.site.com ## CFG_SITE_ADMIN_EMAIL = john.doe@your.site.com ## CFG_SITE_SUPPORT_EMAIL = john.doe@your.site.com ## ## The Invenio system will then read both the default invenio.conf ## file and your customized invenio-local.conf file and it will ## override any default options with the ones you have set in your ## local file. This cascading of configuration parameters will ease ## you future upgrades. [Invenio] ################################### ## Part 1: Essential parameters ## ################################### ## This part defines essential CDS Invenio internal parameters that ## everybody should override, like the name of the server or the email ## address of the local CDS Invenio administrator. ## CFG_DATABASE_* - specify which MySQL server to use, the name of the ## database to use, and the database access credentials. CFG_DATABASE_HOST = localhost CFG_DATABASE_PORT = 3306 CFG_DATABASE_NAME = cdsinvenio CFG_DATABASE_USER = cdsinvenio CFG_DATABASE_PASS = my123p$ss ## CFG_SITE_URL - specify URL under which your installation will be ## visible. For example, use "http://your.site.com". Do not leave ## trailing slash. CFG_SITE_URL = http://localhost ## CFG_SITE_SECURE_URL - specify secure URL under which your ## installation secure pages such as login or registration will be ## visible. For example, use "https://your.site.com". Do not leave ## trailing slash. If you don't plan on using HTTPS, then you may ## leave this empty. CFG_SITE_SECURE_URL = https://localhost ## CFG_SITE_NAME -- the visible name of your CDS Invenio installation. CFG_SITE_NAME = Atlantis Institute of Fictive Science ## CFG_SITE_NAME_INTL -- the international versions of CFG_SITE_NAME ## in various languages. (See also CFG_SITE_LANGS below.) CFG_SITE_NAME_INTL_en = Atlantis Institute of Fictive Science CFG_SITE_NAME_INTL_fr = Atlantis Institut des Sciences Fictives CFG_SITE_NAME_INTL_de = Atlantis Institut der fiktiven Wissenschaft CFG_SITE_NAME_INTL_es = Atlantis Instituto de la Ciencia Fictive CFG_SITE_NAME_INTL_ca = Institut Atlantis de Ciència Fictícia CFG_SITE_NAME_INTL_pt = Instituto Atlantis de Ciência Fictícia CFG_SITE_NAME_INTL_it = Atlantis Istituto di Scienza Fittizia CFG_SITE_NAME_INTL_ru = Атлантис Институт фиктивных Наук CFG_SITE_NAME_INTL_sk = Atlantis Inštitút Fiktívnych Vied CFG_SITE_NAME_INTL_cs = Atlantis Institut Fiktivních Věd CFG_SITE_NAME_INTL_no = Atlantis Institutt for Fiktiv Vitenskap CFG_SITE_NAME_INTL_sv = Atlantis Institut för Fiktiv Vetenskap CFG_SITE_NAME_INTL_el = Ινστιτούτο Φανταστικών Επιστημών Ατλαντίδος CFG_SITE_NAME_INTL_uk = Інститут вигаданих наук в Атлантісі CFG_SITE_NAME_INTL_ja = Fictive 科学のAtlantis の協会 CFG_SITE_NAME_INTL_pl = Instytut Fikcyjnej Nauki Atlantis CFG_SITE_NAME_INTL_bg = Институт за фиктивни науки Атлантис CFG_SITE_NAME_INTL_hr = Institut Fiktivnih Znanosti Atlantis CFG_SITE_NAME_INTL_zh_CN = 阿特兰提斯虚拟科学学院 CFG_SITE_NAME_INTL_zh_TW = 阿特蘭提斯虛擬科學學院 CFG_SITE_NAME_INTL_hu = Kitalált Tudományok Atlantiszi Intézete CFG_SITE_NAME_INTL_af = Atlantis Instituut van Fiktiewe Wetenskap CFG_SITE_NAME_INTL_gl = Instituto Atlantis de Ciencia Fictive ## CFG_SITE_LANG -- the default language of the interface: CFG_SITE_LANG = en ## CFG_SITE_LANGS -- list of all languages the user interface should ## be available in, separated by commas. The order specified below ## will be respected on the interface pages. A good default would be ## to use the alphabetical order. Currently supported languages ## include Afrikaans, Bulgarian, Catalan, Czech, German, Greek, ## English, Spanish, French, Croatian, Hungarian, Galician, Italian, ## Japanese, Norwegian, Polish, Portuguese, Russian, Slovak, Swedish, ## Ukrainian, Chinese (China), Chinese (Taiwan), so that the current ## eventual maximum you can currently select is ## "af,bg,ca,cs,de,el,en,es,fr,hr,gl,it,hu,ja,no,pl,pt,ru,sk,sv,uk,zh_CN,zh_TW". CFG_SITE_LANGS = af,bg,ca,cs,de,el,en,es,fr,hr,gl,it,hu,ja,no,pl,pt,ru,sk,sv,uk,zh_CN,zh_TW ## CFG_SITE_SUPPORT_EMAIL -- the email address of the support team for ## this installation: CFG_SITE_SUPPORT_EMAIL = cds.support@cern.ch ## CFG_SITE_ADMIN_EMAIL -- the email address of the 'superuser' for ## this installation. Enter your email address below and login with ## this address when using CDS Invenio administration modules. You ## will then be automatically recognized as superuser of the system. CFG_SITE_ADMIN_EMAIL = cds.support@cern.ch ## CFG_SITE_EMERGENCY_PHONE_NUMBERS -- list of mobile phone numbers to ## which an sms should be sent in case of emergency (e.g. bibsched queue ## has been stopped because of an error). ## Note that in order to use this function, if CFG_CERN_SITE is set to 0, ## the function send_sms in errorlib should be reimplemented. CFG_SITE_EMERGENCY_PHONE_NUMBERS = ## CFG_CERN_SITE -- do we want to enable CERN-specific code? ## Put "1" for "yes" and "0" for "no". CFG_CERN_SITE = 0 ## CFG_INSPIRE_SITE -- do we want to enable INSPIRE-specific code? ## Put "1" for "yes" and "0" for "no". CFG_INSPIRE_SITE = 0 ## CFG_DEVEL_SITE -- is this a development site? If it is, you might ## prefer that it doesn't do certain things. For example, you might ## not want WebSubmit to send certain emails or trigger certain ## processes on a development site. ## Put "1" for "yes" (this is a development site) or "0" for "no" ## (this isn't a development site.) CFG_DEVEL_SITE = 0 ################################ ## Part 2: Web page style ## ################################ ## The variables affecting the page style. The most important one is ## the 'template skin' you would like to use and the obfuscation mode ## for your email addresses. Please refer to the WebStyle Admin Guide ## for more explanation. The other variables are listed here mostly ## for backwards compatibility purposes only. ## CFG_WEBSTYLE_TEMPLATE_SKIN -- what template skin do you want to ## use? CFG_WEBSTYLE_TEMPLATE_SKIN = default ## CFG_WEBSTYLE_EMAIL_ADDRESSES_OBFUSCATION_MODE. How do we "protect" ## email addresses from undesired automated email harvesters? This ## setting will not affect 'support' and 'admin' emails. ## NOTE: there is no ultimate solution to protect against email ## harvesting. All have drawbacks and can more or less be ## circumvented. Choose you preferred mode ([t] means "transparent" ## for the user): ## -1: hide all emails. ## [t] 0 : no protection, email returned as is. ## foo@example.com => foo@example.com ## 1 : basic email munging: replaces @ by [at] and . by [dot] ## foo@example.com => foo [at] example [dot] com ## [t] 2 : transparent name mangling: characters are replaced by ## equivalent HTML entities. ## foo@example.com => foo@example.com ## [t] 3 : javascript insertion. Requires Javascript enabled on client ## side. ## 4 : replaces @ and . characters by gif equivalents. ## foo@example.com => foo<img src="at.gif" alt=" [at] ">example<img src="dot.gif" alt=" [dot] ">com CFG_WEBSTYLE_EMAIL_ADDRESSES_OBFUSCATION_MODE = 2 ## (deprecated) CFG_WEBSTYLE_CDSPAGEBOXLEFTTOP -- eventual global HTML ## left top box: CFG_WEBSTYLE_CDSPAGEBOXLEFTTOP = ## (deprecated) CFG_WEBSTYLE_CDSPAGEBOXLEFTBOTTOM -- eventual global ## HTML left bottom box: CFG_WEBSTYLE_CDSPAGEBOXLEFTBOTTOM = ## (deprecated) CFG_WEBSTYLE_CDSPAGEBOXRIGHTTOP -- eventual global ## HTML right top box: CFG_WEBSTYLE_CDSPAGEBOXRIGHTTOP = ## (deprecated) CFG_WEBSTYLE_CDSPAGEBOXRIGHTBOTTOM -- eventual global ## HTML right bottom box: CFG_WEBSTYLE_CDSPAGEBOXRIGHTBOTTOM = ################################## ## Part 3: WebSearch parameters ## ################################## ## This section contains some configuration parameters for WebSearch ## module. Please note that WebSearch is mostly configured on ## run-time via its WebSearch Admin web interface. The parameters ## below are the ones that you do not probably want to modify very ## often during the runtime. (Note that you may modify them ## afterwards too, though.) ## CFG_WEBSEARCH_SEARCH_CACHE_SIZE -- how many queries we want to ## cache in memory per one Apache httpd process? This cache is used ## mainly for "next/previous page" functionality, but it caches also ## "popular" user queries if more than one user happen to search for ## the same thing. Note that large numbers may lead to great memory ## consumption. We recommend a value not greater than 100. CFG_WEBSEARCH_SEARCH_CACHE_SIZE = 100 ## CFG_WEBSEARCH_FIELDS_CONVERT -- if you migrate from an older ## system, you may want to map field codes of your old system (such as ## 'ti') to CDS Invenio/MySQL ("title"). Use Python dictionary syntax ## for the translation table, e.g. {'wau':'author', 'wti':'title'}. ## Usually you don't want to do that, and you would use empty dict {}. CFG_WEBSEARCH_FIELDS_CONVERT = {} ## CFG_WEBSEARCH_LIGHTSEARCH_PATTERN_BOX_WIDTH -- width of the ## search pattern window in the light search interface, in ## characters. CFG_WEBSEARCH_LIGHTSEARCH_PATTERN_BOX_WIDTH = 60 CFG_WEBSEARCH_LIGHTSEARCH_PATTERN_BOX_WIDTH = 60 ## CFG_WEBSEARCH_SIMPLESEARCH_PATTERN_BOX_WIDTH -- width of the search ## pattern window in the simple search interface, in characters. CFG_WEBSEARCH_SIMPLESEARCH_PATTERN_BOX_WIDTH = 40 ## CFG_WEBSEARCH_ADVANCEDSEARCH_PATTERN_BOX_WIDTH -- width of the ## search pattern window in the advanced search interface, in ## characters. CFG_WEBSEARCH_ADVANCEDSEARCH_PATTERN_BOX_WIDTH = 30 ## CFG_WEBSEARCH_NB_RECORDS_TO_SORT -- how many records do we still ## want to sort? For higher numbers we print only a warning and won't ## perform any sorting other than default 'latest records first', as ## sorting would be very time consuming then. We recommend a value of ## not more than a couple of thousands. CFG_WEBSEARCH_NB_RECORDS_TO_SORT = 1000 ## CFG_WEBSEARCH_CALL_BIBFORMAT -- if a record is being displayed but ## it was not preformatted in the "HTML brief" format, do we want to ## call BibFormatting on the fly? Put "1" for "yes" and "0" for "no". ## Note that "1" will display the record exactly as if it were fully ## preformatted, but it may be slow due to on-the-fly processing; "0" ## will display a default format very fast, but it may not have all ## the fields as in the fully preformatted HTML brief format. Note ## also that this option is active only for old (PHP) formats; the new ## (Python) formats are called on the fly by default anyway, since ## they are much faster. When usure, please set "0" here. CFG_WEBSEARCH_CALL_BIBFORMAT = 0 ## CFG_WEBSEARCH_USE_ALEPH_SYSNOS -- do we want to make old SYSNOs ## visible rather than MySQL's record IDs? You may use this if you ## migrate from a different e-doc system, and you store your old ## system numbers into 970__a. Put "1" for "yes" and "0" for ## "no". Usually you don't want to do that, though. CFG_WEBSEARCH_USE_ALEPH_SYSNOS = 0 ## CFG_WEBSEARCH_I18N_LATEST_ADDITIONS -- Put "1" if you want the ## "Latest Additions" in the web collection pages to show ## internationalized records. Useful only if your brief BibFormat ## templates contains internationalized strings. Otherwise put "0" in ## order not to slow down the creation of latest additions by WebColl. CFG_WEBSEARCH_I18N_LATEST_ADDITIONS = 0 ## CFG_WEBSEARCH_INSTANT_BROWSE -- the number of records to display ## under 'Latest Additions' in the web collection pages. CFG_WEBSEARCH_INSTANT_BROWSE = 10 ## CFG_WEBSEARCH_INSTANT_BROWSE_RSS -- the number of records to ## display in the RSS feed. CFG_WEBSEARCH_INSTANT_BROWSE_RSS = 25 ## CFG_WEBSEARCH_RSS_TTL -- number of minutes that indicates how long ## a feed cache is valid. CFG_WEBSEARCH_RSS_TTL = 360 ## CFG_WEBSEARCH_RSS_MAX_CACHED_REQUESTS -- maximum number of request kept ## in cache. If the cache is filled, following request are not cached. CFG_WEBSEARCH_RSS_MAX_CACHED_REQUESTS = 1000 ## CFG_WEBSEARCH_AUTHOR_ET_AL_THRESHOLD -- up to how many author names ## to print explicitely; for more print "et al". Note that this is ## used in default formatting that is seldomly used, as usually ## BibFormat defines all the format. The value below is only used ## when BibFormat fails, for example. CFG_WEBSEARCH_AUTHOR_ET_AL_THRESHOLD = 3 ## CFG_WEBSEARCH_NARROW_SEARCH_SHOW_GRANDSONS -- whether to show or ## not collection grandsons in Narrow Search boxes (sons are shown by ## default, grandsons are configurable here). Use 0 for no and 1 for ## yes. CFG_WEBSEARCH_NARROW_SEARCH_SHOW_GRANDSONS = 1 ## CFG_WEBSEARCH_CREATE_SIMILARLY_NAMED_AUTHORS_LINK_BOX -- shall we ## create help links for Ellis, Nick or Ellis, Nicholas and friends ## when Ellis, N was searched for? Useful if you have one author ## stored in the database under several name formats, namely surname ## comma firstname and surname comma initial cataloging policy. Use 0 ## for no and 1 for yes. CFG_WEBSEARCH_CREATE_SIMILARLY_NAMED_AUTHORS_LINK_BOX = 1 ## CFG_WEBSEARCH_USE_JSMATH_FOR_FORMATS -- jsMath is a JavaScript ## library that renders (La)TeX mathematical formulas in the client ## browser. This parameter must contain a comma-separated list of ## output formats for which to apply the jsMath rendering, for example ## "hb,hd". If the list is empty, jsMath is disabled. CFG_WEBSEARCH_USE_JSMATH_FOR_FORMATS = ## CFG_WEBSEARCH_EXTERNAL_COLLECTION_SEARCH_TIMEOUT -- when searching ## external collections (e.g. SPIRES, CiteSeer, etc), how many seconds ## do we wait for reply before abandonning? CFG_WEBSEARCH_EXTERNAL_COLLECTION_SEARCH_TIMEOUT = 5 ## CFG_WEBSEARCH_EXTERNAL_COLLECTION_SEARCH_MAXRESULTS -- how many ## results do we fetch? CFG_WEBSEARCH_EXTERNAL_COLLECTION_SEARCH_MAXRESULTS = 10 ## CFG_WEBSEARCH_SPLIT_BY_COLLECTION -- do we want to split the search ## results by collection or not? Use 0 for not, 1 for yes. CFG_WEBSEARCH_SPLIT_BY_COLLECTION = 1 ## CFG_WEBSEARCH_MAX_RECORDS_IN_GROUPS -- in order to limit denial of ## service attacks the total number of records per group displayed as a ## result of a search query will be limited to this number. Only the superuser ## queries will not be affected by this limit. CFG_WEBSEARCH_MAX_RECORDS_IN_GROUPS = 200 ####################################### ## Part 4: BibHarvest OAI parameters ## ####################################### ## This part defines parameters for the CDS Invenio OAI gateway. ## Useful if you are running CDS Invenio as OAI data provider. ## CFG_OAI_ID_FIELD -- OAI identifier MARC field: CFG_OAI_ID_FIELD = 909COo ## CFG_OAI_SET_FIELD -- OAI set MARC field: CFG_OAI_SET_FIELD = 909COp ## CFG_OAI_DELETED_POLICY -- OAI deletedrecordspolicy ## (no/transient/persistent). CFG_OAI_DELETED_POLICY = no ## CFG_OAI_ID_PREFIX -- OAI identifier prefix: CFG_OAI_ID_PREFIX = atlantis.cern.ch ## CFG_OAI_SAMPLE_IDENTIFIER -- OAI sample identifier: CFG_OAI_SAMPLE_IDENTIFIER = oai:atlantis.cern.ch:CERN-TH-4036 ## CFG_OAI_IDENTIFY_DESCRIPTION -- description for the OAI Identify verb: CFG_OAI_IDENTIFY_DESCRIPTION = <description> <oai-identifier xmlns="http://www.openarchives.org/OAI/2.0/oai-identifier" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai-identifier http://www.openarchives.org/OAI/2.0/oai-identifier.xsd"> <scheme> oai </scheme> <repositoryIdentifier> atlantis.cern.ch </repositoryIdentifier> <delimiter> : </delimiter> <sampleIdentifier> oai:atlantis.cern.ch:CERN-TH-4036 </sampleIdentifier> </oai-identifier> </description> <description> <eprints xmlns="http://www.openarchives.org/OAI/1.1/eprints" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/1.1/eprints http://www.openarchives.org/OAI/1.1/eprints.xsd"> <content> <URL>http://atlantis.cern.ch/</URL> </content> <metadataPolicy> <text>Free and unlimited use by anybody with obligation to refer to original record</text> </metadataPolicy> <dataPolicy> <text>Full content, i.e. preprints may not be harvested by robots</text> </dataPolicy> <submissionPolicy> <text>Submission restricted. Submitted documents are subject of approval by OAI repository admins.</text> </submissionPolicy> </eprints> </description> ## CFG_OAI_LOAD -- OAI number of records in a response: CFG_OAI_LOAD = 1000 ## CFG_OAI_EXPIRE -- OAI resumptionToken expiration time: CFG_OAI_EXPIRE = 90000 ## CFG_OAI_SLEEP -- service unavailable between two consecutive ## requests for CFG_OAI_SLEEP seconds: CFG_OAI_SLEEP = 10 ################################## ## Part 5: WebSubmit parameters ## ################################## ## This section contains some configuration parameters for WebSubmit ## module. Please note that WebSubmit is mostly configured on ## run-time via its WebSubmit Admin web interface. The parameters ## below are the ones that you do not probably want to modify during ## the runtime. ## CFG_WEBSUBMIT_FILESYSTEM_BIBDOC_GROUP_LIMIT -- the fulltext ## documents are stored under "/opt/cds-invenio/var/data/files/gX/Y" ## directories where X is 0,1,... and Y stands for bibdoc ID. Thusly ## documents Y are grouped into directories X and this variable ## indicates the maximum number of documents Y stored in each ## directory X. This limit is imposed solely for filesystem ## performance reasons in order not to have too many subdirectories in ## a given directory. CFG_WEBSUBMIT_FILESYSTEM_BIBDOC_GROUP_LIMIT = 5000 ## CFG_WEBSUBMIT_ADDITIONAL_KNOWN_FILE_EXTENSIONS -- a comma-separated ## list of document extensions not listed in Python standard mimetype ## library that should be recognized by Invenio. CFG_WEBSUBMIT_ADDITIONAL_KNOWN_FILE_EXTENSIONS = hpg,link,lis,llb,mat,mpp,msg,docx,docm,xlsx,xlsm,xlsb,pptx,pptm,ppsx,ppsm ################################# ## Part 6: BibIndex parameters ## ################################# ## This section contains some configuration parameters for BibIndex ## module. Please note that BibIndex is mostly configured on run-time ## via its BibIndex Admin web interface. The parameters below are the ## ones that you do not probably want to modify very often during the ## runtime. ## CFG_BIBINDEX_FULLTEXT_INDEX_LOCAL_FILES_ONLY -- when fulltext indexing, do ## you want to index locally stored files only, or also external URLs? ## Use "0" to say "no" and "1" to say "yes". CFG_BIBINDEX_FULLTEXT_INDEX_LOCAL_FILES_ONLY = 0 ## CFG_BIBINDEX_REMOVE_STOPWORDS -- when indexing, do we want to remove ## stopwords? Use "0" to say "no" and "1" to say "yes". CFG_BIBINDEX_REMOVE_STOPWORDS = 0 ## CFG_BIBINDEX_CHARS_ALPHANUMERIC_SEPARATORS -- characters considered as ## alphanumeric separators of word-blocks inside words. You probably ## don't want to change this. CFG_BIBINDEX_CHARS_ALPHANUMERIC_SEPARATORS = \!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~ ## CFG_BIBINDEX_CHARS_PUNCTUATION -- characters considered as punctuation ## between word-blocks inside words. You probably don't want to ## change this. CFG_BIBINDEX_CHARS_PUNCTUATION = \.\,\:\;\?\!\" ## CFG_BIBINDEX_REMOVE_HTML_MARKUP -- should we attempt to remove HTML markup ## before indexing? Use 1 if you have HTML markup inside metadata ## (e.g. in abstracts), use 0 otherwise. CFG_BIBINDEX_REMOVE_HTML_MARKUP = 0 ## CFG_BIBINDEX_REMOVE_LATEX_MARKUP -- should we attempt to remove LATEX markup ## before indexing? Use 1 if you have LATEX markup inside metadata ## (e.g. in abstracts), use 0 otherwise. CFG_BIBINDEX_REMOVE_LATEX_MARKUP = 0 ## CFG_BIBINDEX_MIN_WORD_LENGTH -- minimum word length allowed to be added to ## index. The terms smaller then this amount will be discarded. ## Useful to keep the database clean, however you can safely leave ## this value on 0 for up to 1,000,000 documents. CFG_BIBINDEX_MIN_WORD_LENGTH = 0 ## CFG_BIBINDEX_URLOPENER_USERNAME and CFG_BIBINDEX_URLOPENER_PASSWORD -- ## access credentials to access restricted URLs, interesting only if ## you are fulltext-indexing files located on a remote server that is ## only available via username/password. But it's probably better to ## handle this case via IP or some convention; the current scheme is ## mostly there for demo only. CFG_BIBINDEX_URLOPENER_USERNAME = mysuperuser CFG_BIBINDEX_URLOPENER_PASSWORD = mysuperpass ## CFG_INTBITSET_ENABLE_SANITY_CHECKS -- ## Enable sanity checks for integers passed to the intbitset data ## structures. It is good to enable this during debugging ## and to disable this value for speed improvements. CFG_INTBITSET_ENABLE_SANITY_CHECKS = False ####################################### ## Part 7: Access control parameters ## ####################################### ## This section contains some configuration parameters for the access ## control system. Please note that WebAccess is mostly configured on ## run-time via its WebAccess Admin web interface. The parameters ## below are the ones that you do not probably want to modify very ## often during the runtime. (If you do want to modify them during ## runtime, for example te deny access temporarily because of backups, ## you can edit access_control_config.py directly, no need to get back ## here and no need to redo the make process.) ## CFG_ACCESS_CONTROL_LEVEL_SITE -- defines how open this site is. ## Use 0 for normal operation of the site, 1 for read-only site (all ## write operations temporarily closed), 2 for site fully closed, ## 3 for also disabling any database connection. ## Useful for site maintenance. CFG_ACCESS_CONTROL_LEVEL_SITE = 0 ## CFG_ACCESS_CONTROL_LEVEL_GUESTS -- guest users access policy. Use ## 0 to allow guest users, 1 not to allow them (all users must login). CFG_ACCESS_CONTROL_LEVEL_GUESTS = 0 ## CFG_ACCESS_CONTROL_LEVEL_ACCOUNTS -- account registration and ## activation policy. When 0, users can register and accounts are ## automatically activated. When 1, users can register but admin must ## activate the accounts. When 2, users cannot register nor update ## their email address, only admin can register accounts. When 3, ## users cannot register nor update email address nor password, only ## admin can register accounts. When 4, the same as 3 applies, nor ## user cannot change his login method. CFG_ACCESS_CONTROL_LEVEL_ACCOUNTS = 0 ## CFG_ACCESS_CONTROL_LIMIT_REGISTRATION_TO_DOMAIN -- limit account ## registration to certain email addresses? If wanted, give domain ## name below, e.g. "cern.ch". If not wanted, leave it empty. CFG_ACCESS_CONTROL_LIMIT_REGISTRATION_TO_DOMAIN = ## CFG_ACCESS_CONTROL_NOTIFY_ADMIN_ABOUT_NEW_ACCOUNTS -- send a ## notification email to the administrator when a new account is ## created? Use 0 for no, 1 for yes. CFG_ACCESS_CONTROL_NOTIFY_ADMIN_ABOUT_NEW_ACCOUNTS = 0 ## CFG_ACCESS_CONTROL_NOTIFY_USER_ABOUT_NEW_ACCOUNT -- send a ## notification email to the user when a new account is created in order to ## to verify the validity of the provided email address? Use ## 0 for no, 1 for yes. CFG_ACCESS_CONTROL_NOTIFY_USER_ABOUT_NEW_ACCOUNT = 1 ## CFG_ACCESS_CONTROL_NOTIFY_USER_ABOUT_ACTIVATION -- send a ## notification email to the user when a new account is activated? ## Use 0 for no, 1 for yes. CFG_ACCESS_CONTROL_NOTIFY_USER_ABOUT_ACTIVATION = 0 ## CFG_ACCESS_CONTROL_NOTIFY_USER_ABOUT_DELETION -- send a ## notification email to the user when a new account is deleted or ## account demand rejected? Use 0 for no, 1 for yes. CFG_ACCESS_CONTROL_NOTIFY_USER_ABOUT_DELETION = 0 ## CFG_APACHE_PASSWORD_FILE -- the file where Apache user credentials ## are stored. Must be an absolute pathname. If the value does not ## start by a slash, it is considered to be the filename of a file ## located under prefix/var/tmp directory. This is useful for the ## demo site testing purposes. For the production site, if you plan ## to restrict access to some collections based on the Apache user ## authentication mechanism, you should put here an absolute path to ## your Apache password file. CFG_APACHE_PASSWORD_FILE = demo-site-apache-user-passwords ## CFG_APACHE_GROUP_FILE -- the file where Apache user groups are ## defined. See the documentation of the preceding config variable. CFG_APACHE_GROUP_FILE = demo-site-apache-user-groups ################################### ## Part 8: WebSession parameters ## ################################### ## This section contains some configuration parameters for tweaking ## session handling. ## CFG_WEBSESSION_EXPIRY_LIMIT_DEFAULT -- number of days after which a session ## and the corresponding cookie is considered expired. CFG_WEBSESSION_EXPIRY_LIMIT_DEFAULT = 2 ## CFG_WEBSESSION_EXPIRY_LIMIT_REMEMBER -- number of days after which a session ## and the corresponding cookie is considered expired, when the user has ## requested to permanently stay logged in. CFG_WEBSESSION_EXPIRY_LIMIT_REMEMBER = 365 ## CFG_WEBSESSION_RESET_PASSWORD_EXPIRE_IN_DAYS -- when user requested ## a password reset, for how many days is the URL valid? CFG_WEBSESSION_RESET_PASSWORD_EXPIRE_IN_DAYS = 3 ## CFG_WEBSESSION_ADDRESS_ACTIVATION_EXPIRE_IN_DAYS -- when an account ## activation email was sent, for how many days is the URL valid? CFG_WEBSESSION_ADDRESS_ACTIVATION_EXPIRE_IN_DAYS = 3 ## CFG_WEBSESSION_NOT_CONFIRMED_EMAIL_ADDRESS_EXPIRE_IN_DAYS -- when ## user won't confirm his email address and not complete ## registeration, after how many days will it expire? CFG_WEBSESSION_NOT_CONFIRMED_EMAIL_ADDRESS_EXPIRE_IN_DAYS = 10 ## CFG_WEBSESSION_DIFFERENTIATE_BETWEEN_GUESTS -- when set to 1, the session ## system allocates the same uid=0 to all guests users regardless of where they ## come from. 0 allocate a unique uid to each guest. CFG_WEBSESSION_DIFFERENTIATE_BETWEEN_GUESTS = 0 ## CFG_WEBSESSION_IPADDR_CHECK_SKIP_BITS -- to prevent session cookie ## stealing, Invenio checks that the IP address of a connection is the ## same as that of the connection which created the initial session. ## This variable let you decide how many bits should be skipped during ## this check. Set this to 0 in order to enable full IP address ## checking. Set this to 32 in order to disable IP address checking. ## Intermediate values (say 8) let you have some degree of security so ## that you can trust your local network only while helping to solve ## issues related to outside clients that configured their browser to ## use a web proxy for HTTP connection but not for HTTPS, thus ## potentially having two different IP addresses. CFG_WEBSESSION_IPADDR_CHECK_SKIP_BITS = 0 ################################ ## Part 9: BibRank parameters ## ################################ ## This section contains some configuration parameters for the ranking ## system. ## CFG_BIBRANK_SHOW_READING_STATS -- do we want to show reading ## similarity stats? ('People who viewed this page also viewed') CFG_BIBRANK_SHOW_READING_STATS = 1 ## CFG_BIBRANK_SHOW_DOWNLOAD_STATS -- do we want to show the download ## similarity stats? ('People who downloaded this document also ## downloaded') CFG_BIBRANK_SHOW_DOWNLOAD_STATS = 1 ## CFG_BIBRANK_SHOW_DOWNLOAD_GRAPHS -- do we want to show download ## history graph? CFG_BIBRANK_SHOW_DOWNLOAD_GRAPHS = 1 ## CFG_BIBRANK_SHOW_DOWNLOAD_GRAPHS_CLIENT_IP_DISTRIBUTION -- do we ## want to show a graph representing the distribution of client IPs ## downloading given document? CFG_BIBRANK_SHOW_DOWNLOAD_GRAPHS_CLIENT_IP_DISTRIBUTION = 0 ## CFG_BIBRANK_SHOW_CITATION_LINKS -- do we want to show the 'Cited ## by' links? (useful only when you have citations in the metadata) CFG_BIBRANK_SHOW_CITATION_LINKS = 1 ## CFG_BIBRANK_SHOW_CITATION_STATS -- de we want to show citation ## stats? ('Cited by M recors', 'Co-cited with N records') CFG_BIBRANK_SHOW_CITATION_STATS = 1 ## CFG_BIBRANK_SHOW_CITATION_GRAPHS -- do we want to show citation ## history graph? CFG_BIBRANK_SHOW_CITATION_GRAPHS = 1 #################################### ## Part 10: WebComment parameters ## #################################### ## This section contains some configuration parameters for the ## commenting and reviewing facilities. ## CFG_WEBCOMMENT_ALLOW_COMMENTS -- do we want to allow users write ## public comments on records? CFG_WEBCOMMENT_ALLOW_COMMENTS = 1 ## CFG_WEBCOMMENT_ALLOW_REVIEWS -- do we want to allow users write ## public reviews of records? CFG_WEBCOMMENT_ALLOW_REVIEWS = 1 ## CFG_WEBCOMMENT_ALLOW_SHORT_REVIEWS -- do we want to allow short ## reviews, that is just the attribution of stars without submitting ## detailed review text? CFG_WEBCOMMENT_ALLOW_SHORT_REVIEWS = 0 ## CFG_WEBCOMMENT_NB_REPORTS_BEFORE_SEND_EMAIL_TO_ADMIN -- if users ## report a comment to be abusive, how many they have to be before the ## site admin is alerted? CFG_WEBCOMMENT_NB_REPORTS_BEFORE_SEND_EMAIL_TO_ADMIN = 5 ## CFG_WEBCOMMENT_NB_COMMENTS_IN_DETAILED_VIEW -- how many comments do ## we display in the detailed record page upon welcome? CFG_WEBCOMMENT_NB_COMMENTS_IN_DETAILED_VIEW = 1 ## CFG_WEBCOMMENT_NB_REVIEWS_IN_DETAILED_VIEW -- how many reviews do ## we display in the detailed record page upon welcome? CFG_WEBCOMMENT_NB_REVIEWS_IN_DETAILED_VIEW = 1 ## CFG_WEBCOMMENT_ADMIN_NOTIFICATION_LEVEL -- do we notify the site ## admin after every comment? CFG_WEBCOMMENT_ADMIN_NOTIFICATION_LEVEL = 1 ## CFG_WEBCOMMENT_TIMELIMIT_PROCESSING_COMMENTS_IN_SECONDS -- how many ## elapsed seconds do we consider enough when checking for possible ## multiple comment submissions by a user? CFG_WEBCOMMENT_TIMELIMIT_PROCESSING_COMMENTS_IN_SECONDS = 20 ## CFG_WEBCOMMENT_TIMELIMIT_PROCESSING_REVIEWS_IN_SECONDS -- how many ## elapsed seconds do we consider enough when checking for possible ## multiple review submissions by a user? CFG_WEBCOMMENT_TIMELIMIT_PROCESSING_REVIEWS_IN_SECONDS = 20 ## CFG_WEBCOMMENT_USE_RICH_EDITOR -- enable the WYSIWYG ## Javascript-based editor when user edits comments? CFG_WEBCOMMENT_USE_RICH_TEXT_EDITOR = False ################################## ## Part 11: BibSched parameters ## ################################## ## This section contains some configuration parameters for the ## bibliographic task scheduler. ## CFG_BIBSCHED_REFRESHTIME -- how often do we want to refresh ## bibsched monitor? (in seconds) CFG_BIBSCHED_REFRESHTIME = 5 ## CFG_BIBSCHED_LOG_PAGER -- what pager to use to view bibsched task ## logs? CFG_BIBSCHED_LOG_PAGER = /bin/more ## CFG_BIBSCHED_GC_TASKS_OLDER_THAN -- after how many days to perform the ## gargbage collector of BibSched queue (i.e. removing/moving task to archive). CFG_BIBSCHED_GC_TASKS_OLDER_THAN = 30 ## CFG_BIBSCHED_GC_TASKS_TO_REMOVE -- list of BibTask that can be safely ## removed from the BibSched queue once they are DONE. CFG_BIBSCHED_GC_TASKS_TO_REMOVE = bibindex,bibreformat,webcoll,bibrank,inveniogc ## CFG_BIBSCHED_GC_TASKS_TO_ARCHIVE -- list of BibTasks that should be safely ## archived out of the BibSched queue once they are DONE. CFG_BIBSCHED_GC_TASKS_TO_ARCHIVE = bibupload,oaiarchive ## CFG_BIBSCHED_MAX_NUMBER_CONCURRENT_TASKS -- maximum number of BibTasks ## that can run concurrently. ## NOTE: concurrent tasks are still considered as an experimental ## feature. Please keep this value set to 1 on production environments. CFG_BIBSCHED_MAX_NUMBER_CONCURRENT_TASKS = 1 ## CFG_BIBSCHED_PROCESS_USER -- bibsched and bibtask processes must ## usually run under the same identity as the Apache web server ## process in order to share proper file read/write privileges. If ## you want to force some other bibsched/bibtask user, e.g. because ## you are using a local `invenio' user that belongs to your ## `www-data' Apache user group and so shares writing rights with your ## Apache web server process in this way, then please set its username ## identity here. Otherwise we shall check whether your ## bibsched/bibtask processes are run under the same identity as your ## Apache web server process (in which case you can leave the default ## empty value here). CFG_BIBSCHED_PROCESS_USER = ################################### ## Part 12: WebBasket parameters ## ################################### ## CFG_WEBBASKET_MAX_NUMBER_OF_DISPLAYED_BASKETS -- a safety limit for ## a maximum number of displayed baskets CFG_WEBBASKET_MAX_NUMBER_OF_DISPLAYED_BASKETS = 20 ## CFG_WEBBASKET_USE_RICH_TEXT_EDITOR -- enable the WYSIWYG ## Javascript-based editor when user edits comments in WebBasket? CFG_WEBBASKET_USE_RICH_TEXT_EDITOR = False ################################## ## Part 13: WebAlert parameters ## ################################## ## This section contains some configuration parameters for the ## automatic email notification alert system. ## CFG_WEBALERT_ALERT_ENGINE_EMAIL -- the email address from which the ## alert emails will appear to be sent: CFG_WEBALERT_ALERT_ENGINE_EMAIL = cds.alert@cdsdev.cern.ch ## CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL -- how many records ## at most do we send in an outgoing alert email? CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL = 20 ## CFG_WEBALERT_MAX_NUM_OF_CHARS_PER_LINE_IN_ALERT_EMAIL -- number of ## chars per line in an outgoing alert email? CFG_WEBALERT_MAX_NUM_OF_CHARS_PER_LINE_IN_ALERT_EMAIL = 72 ## CFG_WEBALERT_SEND_EMAIL_NUMBER_OF_TRIES -- when sending alert ## emails fails, how many times we retry? CFG_WEBALERT_SEND_EMAIL_NUMBER_OF_TRIES = 3 ## CFG_WEBALERT_SEND_EMAIL_SLEEPTIME_BETWEEN_TRIES -- when sending ## alert emails fails, what is the sleeptime between tries? (in ## seconds) CFG_WEBALERT_SEND_EMAIL_SLEEPTIME_BETWEEN_TRIES = 300 #################################### ## Part 14: WebMessage parameters ## #################################### ## CFG_WEBMESSAGE_MAX_SIZE_OF_MESSAGE -- how large web messages do we ## allow? CFG_WEBMESSAGE_MAX_SIZE_OF_MESSAGE = 20000 ## CFG_WEBMESSAGE_MAX_NB_OF_MESSAGES -- how many messages for a ## regular user do we allow in its inbox? CFG_WEBMESSAGE_MAX_NB_OF_MESSAGES = 30 ## CFG_WEBMESSAGE_DAYS_BEFORE_DELETE_ORPHANS -- how many days before ## we delete orphaned messages? CFG_WEBMESSAGE_DAYS_BEFORE_DELETE_ORPHANS = 60 ################################## ## Part 15: MiscUtil parameters ## ################################## ## CFG_MISCUTIL_SQL_MAX_CACHED_QUERIES -- maximum number of cached SQL ## queries possible. After reaching this number the cache is pruned ## by deleting half of the older queries. CFG_MISCUTIL_SQL_MAX_CACHED_QUERIES = 10000 ## CFG_MISCUTIL_SQL_USE_SQLALCHEMY -- whether to use SQLAlchemy.pool ## in the DB engine of CDS Invenio. It is okay to enable this flag ## even if you have not installed SQLAlchemy. Note that Invenio will ## loose some perfomance if this option is enabled. CFG_MISCUTIL_SQL_USE_SQLALCHEMY = False ## CFG_MISCUTIL_SMTP_HOST -- which server to use as outgoing mail server to ## send outgoing emails generated by the system, for example concerning ## submissions or email notification alerts. CFG_MISCUTIL_SMTP_HOST = localhost ## CFG_MISCUTIL_SMTP_PORT -- which port to use on the outgoing mail server ## defined in the previous step. CFG_MISCUTIL_SMTP_PORT = 25 ################################# ## Part 16: BibEdit parameters ## ################################# ## CFG_BIBEDIT_TIMEOUT -- when a user edits a record, this record is ## locked to prevent other users to edit it at the same time. After ## how many seconds the locked record will be again free for other ## people to edit? CFG_BIBEDIT_TIMEOUT = 3600 ## CFG_BIBEDIT_LOCKLEVEL -- when a user tries to edit a record being edited by ## another user, the lock level determines when it is permitted to do so. ## Level 0 - permits editing if there are no recent edit sessions in tmp directory ## (unsafe, use only if you know what you are doing) ## Level 1 - permits editing if there are no queued bibedit tasks for this record ## (safe with respect to bibedit, but not for other bibupload maintenance jobs) ## Level 2 - permits editing if there are no queued bibupload tasks of any sort ## (safe, but may lock more than necessary if many cataloguers around) ## Level 3 - permits editing if no queued bibupload task concerns given record ## (safe, most precise locking, but slow, ## checks for 001/EXTERNAL_SYSNO_TAG/EXTERNAL_OAIID_TAG) ## The recommended level is 3 (default) or 2 (if you use maintenance jobs often). CFG_BIBEDIT_LOCKLEVEL = 3 ################################### ## Part 17: BibUpload parameters ## ################################### ## CFG_BIBUPLOAD_REFERENCE_TAG -- where do we store references? CFG_BIBUPLOAD_REFERENCE_TAG = 999 ## CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG -- where do we store external ## system numbers? Useful for matching when our records come from an ## external digital library system. CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG = 970__a ## CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG -- where do we store OAI ID tags ## of harvested records? Useful for matching when we harvest stuff ## via OAI that we do not want to reexport via Invenio OAI; so records ## may have only the source OAI ID stored in this tag (kind of like ## external system number too). CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG = 035__a ## CFG_BIBUPLOAD_EXTERNAL_OAIID_PROVENANCE_TAG -- where do we store OAI SRC ## tags of harvested records? Useful for matching when we harvest stuff ## via OAI that we do not want to reexport via Invenio OAI; so records ## may have only the source OAI SRC stored in this tag (kind of like ## external system number too). Note that the field should be the same of ## CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG. CFG_BIBUPLOAD_EXTERNAL_OAIID_PROVENANCE_TAG = 035__9 ## CFG_BIBUPLOAD_STRONG_TAGS -- a comma-separated list of tags that ## are strong enough to resist the replace mode. Useful for tags that ## might be created from an external non-metadata-like source, ## e.g. the information about the number of copies left. CFG_BIBUPLOAD_STRONG_TAGS = 964 ## CFG_BIBUPLOAD_CONTROLLED_PROVENANCE_TAGS -- a comma-separated list ## of tags that contain provenance information that should be checked ## in the bibupload correct mode via matching provenance codes. (Only ## field instances of the same provenance information would be acted ## upon.) Please specify the whole tag info up to subfield codes. -CFG_BIBUPLOAD_CONTROLLED_PROVENANCE_TAGS = 653__9 +CFG_BIBUPLOAD_CONTROLLED_PROVENANCE_TAGS = 6531_9 ## CFG_BIBUPLOAD_FFT_ALLOWED_LOCAL_PATHS -- a comma-separated list of system ## paths from which it is allowed to take fulltextes that will be uploaded via ## FFT (CFG_TMPDIR is included by default). CFG_BIBUPLOAD_FFT_ALLOWED_LOCAL_PATHS = /tmp,/home ########################## ## THAT's ALL, FOLKS! ## ########################## diff --git a/modules/bibupload/lib/bibupload_regression_tests.py b/modules/bibupload/lib/bibupload_regression_tests.py index a8086a118..c3e4c0d71 100644 --- a/modules/bibupload/lib/bibupload_regression_tests.py +++ b/modules/bibupload/lib/bibupload_regression_tests.py @@ -1,3224 +1,3224 @@ # -*- coding: utf-8 -*- ## ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. # pylint: disable-msg=C0301 """Regression tests for the BibUpload.""" __revision__ = "$Id$" import re import unittest import datetime import os import time from urllib2 import urlopen from md5 import md5 from invenio.config import CFG_OAI_ID_FIELD, CFG_PREFIX, CFG_SITE_URL, CFG_TMPDIR, \ CFG_WEBSUBMIT_FILEDIR, \ CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG, \ CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG, \ CFG_BIBUPLOAD_EXTERNAL_OAIID_PROVENANCE_TAG from invenio import bibupload from invenio.search_engine import print_record from invenio.dbquery import run_sql from invenio.dateutils import convert_datestruct_to_datetext from invenio.testutils import make_test_suite, run_test_suite from invenio.bibdocfile import BibRecDocs from invenio.bibtask import task_set_task_param # helper functions: def remove_tag_001_from_xmbuffer(xmbuffer): """Remove tag 001 from MARCXML buffer. Useful for testing two MARCXML buffers without paying attention to recIDs attributed during the bibupload. """ return re.sub(r'<controlfield tag="001">.*</controlfield>', '', xmbuffer) def compare_xmbuffers(xmbuffer1, xmbuffer2): """Compare two XM (XML MARC) buffers by removing whitespaces before testing. """ def remove_blanks_from_xmbuffer(xmbuffer): """Remove \n and blanks from XMBUFFER.""" out = xmbuffer.replace("\n", "") out = out.replace(" ", "") return out # remove whitespace: xmbuffer1 = remove_blanks_from_xmbuffer(xmbuffer1) xmbuffer2 = remove_blanks_from_xmbuffer(xmbuffer2) if xmbuffer1 != xmbuffer2: return "\n=" + xmbuffer1 + "=\n" + '!=' + "\n=" + xmbuffer2 + "=\n" return '' def remove_tag_001_from_hmbuffer(hmbuffer): """Remove tag 001 from HTML MARC buffer. Useful for testing two HTML MARC buffers without paying attention to recIDs attributed during the bibupload. """ return re.sub(r'(^|\n)(<pre>)?[0-9]{9}\s001__\s\d+($|\n)', '', hmbuffer) def compare_hmbuffers(hmbuffer1, hmbuffer2): """Compare two HM (HTML MARC) buffers by removing whitespaces before testing. """ # remove eventual <pre>...</pre> formatting: hmbuffer1 = re.sub(r'^<pre>', '', hmbuffer1) hmbuffer2 = re.sub(r'^<pre>', '', hmbuffer2) hmbuffer1 = re.sub(r'</pre>$', '', hmbuffer1) hmbuffer2 = re.sub(r'</pre>$', '', hmbuffer2) # remove leading recid, leaving only field values: hmbuffer1 = re.sub(r'(^|\n)[0-9]{9}\s', '', hmbuffer1) hmbuffer2 = re.sub(r'(^|\n)[0-9]{9}\s', '', hmbuffer2) # remove leading whitespace: hmbuffer1 = re.sub(r'(^|\n)\s+', '', hmbuffer1) hmbuffer2 = re.sub(r'(^|\n)\s+', '', hmbuffer2) compare_hmbuffers = hmbuffer1 == hmbuffer2 if not compare_hmbuffers: return "\n=" + hmbuffer1 + "=\n" + '!=' + "\n=" + hmbuffer2 + "=\n" return '' def try_url_download(url): """Try to download a given URL""" try: open_url = urlopen(url) open_url.read() except Exception, e: raise StandardError, "Downloading %s is impossible because of %s" \ % (url, str(e)) return True class BibUploadInsertModeTest(unittest.TestCase): """Testing insert mode.""" def setUp(self): # pylint: disable-msg=C0103 """Initialise the MARCXML variable""" self.test = """<record> <datafield tag ="245" ind1=" " ind2=" "> <subfield code="a">something</subfield> </datafield> <datafield tag ="700" ind1=" " ind2=" "> <subfield code="a">Tester, J Y</subfield> <subfield code="u">MIT</subfield> </datafield> <datafield tag ="700" ind1=" " ind2=" "> <subfield code="a">Tester, K J</subfield> <subfield code="u">CERN2</subfield> </datafield> <datafield tag ="700" ind1=" " ind2=" "> <subfield code="a">Tester, G</subfield> <subfield code="u">CERN3</subfield> </datafield> <datafield tag ="111" ind1=" " ind2=" "> <subfield code="a">test11</subfield> <subfield code="c">test31</subfield> </datafield> <datafield tag ="111" ind1=" " ind2=" "> <subfield code="a">test12</subfield> <subfield code="c">test32</subfield> </datafield> <datafield tag ="111" ind1=" " ind2=" "> <subfield code="a">test13</subfield> <subfield code="c">test33</subfield> </datafield> <datafield tag ="111" ind1=" " ind2=" "> <subfield code="b">test21</subfield> <subfield code="d">test41</subfield> </datafield> <datafield tag ="111" ind1=" " ind2=" "> <subfield code="b">test22</subfield> <subfield code="d">test42</subfield> </datafield> <datafield tag ="111" ind1=" " ind2=" "> <subfield code="a">test14</subfield> </datafield> <datafield tag ="111" ind1=" " ind2=" "> <subfield code="e">test51</subfield> </datafield> <datafield tag ="111" ind1=" " ind2=" "> <subfield code="e">test52</subfield> </datafield> <datafield tag ="100" ind1=" " ind2=" "> <subfield code="a">Tester, T</subfield> <subfield code="u">CERN</subfield> </datafield> </record>""" self.test_hm = """ 100__ $$aTester, T$$uCERN 111__ $$atest11$$ctest31 111__ $$atest12$$ctest32 111__ $$atest13$$ctest33 111__ $$btest21$$dtest41 111__ $$btest22$$dtest42 111__ $$atest14 111__ $$etest51 111__ $$etest52 245__ $$asomething 700__ $$aTester, J Y$$uMIT 700__ $$aTester, K J$$uCERN2 700__ $$aTester, G$$uCERN3 """ def test_create_record_id(self): """bibupload - insert mode, trying to create a new record ID in the database""" rec_id = bibupload.create_new_record() self.assertNotEqual(-1, rec_id) def test_no_retrieve_record_id(self): """bibupload - insert mode, detection of record ID in the input file""" # We create create the record out of the xml marc recs = bibupload.xml_marc_to_records(self.test) # We call the function which should retrieve the record id rec_id = bibupload.retrieve_rec_id(recs[0], 'insert') # We compare the value found with None self.assertEqual(None, rec_id) def test_insert_complete_xmlmarc(self): """bibupload - insert mode, trying to insert complete MARCXML file""" # Initialize the global variable task_set_task_param('verbose', 0) # We create create the record out of the xml marc recs = bibupload.xml_marc_to_records(self.test) # We call the main function with the record as a parameter err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # We retrieve the inserted xml inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') # Compare if the two MARCXML are the same self.assertEqual(compare_xmbuffers(remove_tag_001_from_xmbuffer(inserted_xm), self.test), '') self.assertEqual(compare_hmbuffers(remove_tag_001_from_hmbuffer(inserted_hm), self.test_hm), '') class BibUploadAppendModeTest(unittest.TestCase): """Testing append mode.""" def setUp(self): # pylint: disable-msg=C0103 """Initialize the MARCXML variable""" self.test_existing = """<record> <controlfield tag="001">123456789</controlfield> <datafield tag ="100" ind1=" " ind2=" "> <subfield code="a">Tester, T</subfield> <subfield code="u">DESY</subfield> </datafield> </record>""" self.test_to_append = """<record> <controlfield tag="001">123456789</controlfield> <datafield tag ="100" ind1=" " ind2=" "> <subfield code="a">Tester, U</subfield> <subfield code="u">CERN</subfield> </datafield> </record>""" self.test_expected_xm = """<record> <controlfield tag="001">123456789</controlfield> <datafield tag ="100" ind1=" " ind2=" "> <subfield code="a">Tester, T</subfield> <subfield code="u">DESY</subfield> </datafield> <datafield tag ="100" ind1=" " ind2=" "> <subfield code="a">Tester, U</subfield> <subfield code="u">CERN</subfield> </datafield> </record>""" self.test_expected_hm = """ 001__ 123456789 100__ $$aTester, T$$uDESY 100__ $$aTester, U$$uCERN """ # insert test record: test_to_upload = self.test_existing.replace('<controlfield tag="001">123456789</controlfield>', '') recs = bibupload.xml_marc_to_records(test_to_upload) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') self.test_recid = recid # replace test buffers with real recid of inserted test record: self.test_existing = self.test_existing.replace('123456789', str(self.test_recid)) self.test_to_append = self.test_to_append.replace('123456789', str(self.test_recid)) self.test_expected_xm = self.test_expected_xm.replace('123456789', str(self.test_recid)) self.test_expected_hm = self.test_expected_hm.replace('123456789', str(self.test_recid)) def test_retrieve_record_id(self): """bibupload - append mode, the input file should contain a record ID""" task_set_task_param('verbose', 0) # We create create the record out of the xml marc recs = bibupload.xml_marc_to_records(self.test_to_append) # We call the function which should retrieve the record id rec_id = bibupload.retrieve_rec_id(recs[0], 'append') # We compare the value found with None self.assertEqual(str(self.test_recid), rec_id) # clean up after ourselves: bibupload.wipe_out_record_from_all_tables(self.test_recid) return def test_update_modification_record_date(self): """bibupload - append mode, checking the update of the modification date""" # Initialize the global variable task_set_task_param('verbose', 0) # We create create the record out of the xml marc recs = bibupload.xml_marc_to_records(self.test_existing) # We call the function which should retrieve the record id rec_id = bibupload.retrieve_rec_id(recs[0], opt_mode='append') # Retrieve current localtime now = time.localtime() # We update the modification date bibupload.update_bibrec_modif_date(convert_datestruct_to_datetext(now), rec_id) # We retrieve the modification date from the database query = """SELECT DATE_FORMAT(modification_date,'%%Y-%%m-%%d %%H:%%i:%%s') FROM bibrec where id = %s""" res = run_sql(query % rec_id) # We compare the two results self.assertEqual(res[0][0], convert_datestruct_to_datetext(now)) # clean up after ourselves: bibupload.wipe_out_record_from_all_tables(self.test_recid) return def test_append_complete_xml_marc(self): """bibupload - append mode, appending complete MARCXML file""" # Now we append a datafield # We create create the record out of the xml marc recs = bibupload.xml_marc_to_records(self.test_to_append) # We call the main function with the record as a parameter err, recid = bibupload.bibupload(recs[0], opt_mode='append') # We retrieve the inserted xm after_append_xm = print_record(recid, 'xm') after_append_hm = print_record(recid, 'hm') # Compare if the two MARCXML are the same self.assertEqual(compare_xmbuffers(after_append_xm, self.test_expected_xm), '') self.assertEqual(compare_hmbuffers(after_append_hm, self.test_expected_hm), '') # clean up after ourselves: bibupload.wipe_out_record_from_all_tables(self.test_recid) return class BibUploadCorrectModeTest(unittest.TestCase): """ Testing correcting a record containing similar tags (identical tag, different indicators). Currently CDS Invenio replaces only those tags that have matching indicators too, unlike ALEPH500 that does not pay attention to indicators, it corrects all fields with the same tag, regardless of the indicator values. """ def setUp(self): """Initialize the MARCXML test record.""" self.testrec1_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, Jane</subfield> <subfield code="u">Test Institute</subfield> </datafield> <datafield tag="100" ind1="4" ind2="7"> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="100" ind1="4" ind2="8"> <subfield code="a">Cool</subfield> </datafield> <datafield tag="100" ind1="4" ind2="7"> <subfield code="a">Test, Jim</subfield> <subfield code="u">Test Laboratory</subfield> </datafield> </record> """ self.testrec1_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, Jane$$uTest Institute 10047 $$aTest, John$$uTest University 10048 $$aCool 10047 $$aTest, Jim$$uTest Laboratory """ self.testrec1_xm_to_correct = """ <record> <controlfield tag="001">123456789</controlfield> <datafield tag="100" ind1="4" ind2="7"> <subfield code="a">Test, Joseph</subfield> <subfield code="u">Test Academy</subfield> </datafield> <datafield tag="100" ind1="4" ind2="7"> <subfield code="a">Test2, Joseph</subfield> <subfield code="u">Test2 Academy</subfield> </datafield> </record> """ self.testrec1_corrected_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, Jane</subfield> <subfield code="u">Test Institute</subfield> </datafield> <datafield tag="100" ind1="4" ind2="8"> <subfield code="a">Cool</subfield> </datafield> <datafield tag="100" ind1="4" ind2="7"> <subfield code="a">Test, Joseph</subfield> <subfield code="u">Test Academy</subfield> </datafield> <datafield tag="100" ind1="4" ind2="7"> <subfield code="a">Test2, Joseph</subfield> <subfield code="u">Test2 Academy</subfield> </datafield> </record> """ self.testrec1_corrected_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, Jane$$uTest Institute 10048 $$aCool 10047 $$aTest, Joseph$$uTest Academy 10047 $$aTest2, Joseph$$uTest2 Academy """ # insert test record: task_set_task_param('verbose', 0) test_record_xm = self.testrec1_xm.replace('<controlfield tag="001">123456789</controlfield>', '') recs = bibupload.xml_marc_to_records(test_record_xm) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recID: self.testrec1_xm = self.testrec1_xm.replace('123456789', str(recid)) self.testrec1_hm = self.testrec1_hm.replace('123456789', str(recid)) self.testrec1_xm_to_correct = self.testrec1_xm_to_correct.replace('123456789', str(recid)) self.testrec1_corrected_xm = self.testrec1_corrected_xm.replace('123456789', str(recid)) self.testrec1_corrected_hm = self.testrec1_corrected_hm.replace('123456789', str(recid)) # test of the inserted record: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.assertEqual(compare_xmbuffers(inserted_xm, self.testrec1_xm), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.testrec1_hm), '') def test_record_correction(self): """bibupload - correct mode, similar MARCXML tags/indicators""" # correct some tags: recs = bibupload.xml_marc_to_records(self.testrec1_xm_to_correct) err, recid = bibupload.bibupload(recs[0], opt_mode='correct') corrected_xm = print_record(recid, 'xm') corrected_hm = print_record(recid, 'hm') # did it work? self.assertEqual(compare_xmbuffers(corrected_xm, self.testrec1_corrected_xm), '') self.assertEqual(compare_hmbuffers(corrected_hm, self.testrec1_corrected_hm), '') # clean up after ourselves: bibupload.wipe_out_record_from_all_tables(recid) return class BibUploadReplaceModeTest(unittest.TestCase): """Testing replace mode.""" def setUp(self): """Initialize the MARCXML test record.""" self.testrec1_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, Jane</subfield> <subfield code="u">Test Institute</subfield> </datafield> <datafield tag="100" ind1="4" ind2="7"> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="100" ind1="4" ind2="8"> <subfield code="a">Cool</subfield> </datafield> <datafield tag="100" ind1="4" ind2="7"> <subfield code="a">Test, Jim</subfield> <subfield code="u">Test Laboratory</subfield> </datafield> </record> """ self.testrec1_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, Jane$$uTest Institute 10047 $$aTest, John$$uTest University 10048 $$aCool 10047 $$aTest, Jim$$uTest Laboratory """ self.testrec1_xm_to_replace = """ <record> <controlfield tag="001">123456789</controlfield> <datafield tag="100" ind1="4" ind2="7"> <subfield code="a">Test, Joseph</subfield> <subfield code="u">Test Academy</subfield> </datafield> <datafield tag="100" ind1="4" ind2="7"> <subfield code="a">Test2, Joseph</subfield> <subfield code="u">Test2 Academy</subfield> </datafield> </record> """ self.testrec1_replaced_xm = """ <record> <controlfield tag="001">123456789</controlfield> <datafield tag="100" ind1="4" ind2="7"> <subfield code="a">Test, Joseph</subfield> <subfield code="u">Test Academy</subfield> </datafield> <datafield tag="100" ind1="4" ind2="7"> <subfield code="a">Test2, Joseph</subfield> <subfield code="u">Test2 Academy</subfield> </datafield> </record> """ self.testrec1_replaced_hm = """ 001__ 123456789 10047 $$aTest, Joseph$$uTest Academy 10047 $$aTest2, Joseph$$uTest2 Academy """ # insert test record: task_set_task_param('verbose', 0) test_record_xm = self.testrec1_xm.replace('<controlfield tag="001">123456789</controlfield>', '') recs = bibupload.xml_marc_to_records(test_record_xm) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recID: self.testrec1_xm = self.testrec1_xm.replace('123456789', str(recid)) self.testrec1_hm = self.testrec1_hm.replace('123456789', str(recid)) self.testrec1_xm_to_replace = self.testrec1_xm_to_replace.replace('123456789', str(recid)) self.testrec1_replaced_xm = self.testrec1_replaced_xm.replace('123456789', str(recid)) self.testrec1_replaced_hm = self.testrec1_replaced_hm.replace('123456789', str(recid)) # test of the inserted record: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.assertEqual(compare_xmbuffers(inserted_xm, self.testrec1_xm), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.testrec1_hm), '') def test_record_replace(self): """bibupload - replace mode, similar MARCXML tags/indicators""" # replace some tags: recs = bibupload.xml_marc_to_records(self.testrec1_xm_to_replace) err, recid = bibupload.bibupload(recs[0], opt_mode='replace') replaced_xm = print_record(recid, 'xm') replaced_hm = print_record(recid, 'hm') # did it work? self.assertEqual(compare_xmbuffers(replaced_xm, self.testrec1_replaced_xm), '') self.assertEqual(compare_hmbuffers(replaced_hm, self.testrec1_replaced_hm), '') # clean up after ourselves: bibupload.wipe_out_record_from_all_tables(recid) return class BibUploadReferencesModeTest(unittest.TestCase): """Testing references mode.""" def setUp(self): # pylint: disable-msg=C0103 """Initialize the MARCXML variable""" self.test_insert = """<record> <controlfield tag="001">123456789</controlfield> <datafield tag ="100" ind1=" " ind2=" "> <subfield code="a">Tester, T</subfield> <subfield code="u">CERN</subfield> </datafield> </record>""" self.test_reference = """<record> <controlfield tag="001">123456789</controlfield> <datafield tag =\"""" + bibupload.CFG_BIBUPLOAD_REFERENCE_TAG + """\" ind1="C" ind2="5"> <subfield code="m">M. Lüscher and P. Weisz, String excitation energies in SU(N) gauge theories beyond the free-string approximation,</subfield> <subfield code="s">J. High Energy Phys. 07 (2004) 014</subfield> </datafield> </record>""" self.test_reference_expected_xm = """<record> <controlfield tag="001">123456789</controlfield> <datafield tag ="100" ind1=" " ind2=" "> <subfield code="a">Tester, T</subfield> <subfield code="u">CERN</subfield> </datafield> <datafield tag =\"""" + bibupload.CFG_BIBUPLOAD_REFERENCE_TAG + """\" ind1="C" ind2="5"> <subfield code="m">M. Lüscher and P. Weisz, String excitation energies in SU(N) gauge theories beyond the free-string approximation,</subfield> <subfield code="s">J. High Energy Phys. 07 (2004) 014</subfield> </datafield> </record>""" self.test_insert_hm = """ 001__ 123456789 100__ $$aTester, T$$uCERN """ self.test_reference_expected_hm = """ 001__ 123456789 100__ $$aTester, T$$uCERN %(reference_tag)sC5 $$mM. Lüscher and P. Weisz, String excitation energies in SU(N) gauge theories beyond the free-string approximation,$$sJ. High Energy Phys. 07 (2004) 014 """ % {'reference_tag': bibupload.CFG_BIBUPLOAD_REFERENCE_TAG} # insert test record: task_set_task_param('verbose', 0) test_insert = self.test_insert.replace('<controlfield tag="001">123456789</controlfield>', '') recs = bibupload.xml_marc_to_records(test_insert) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recID: self.test_insert = self.test_insert.replace('123456789', str(recid)) self.test_insert_hm = self.test_insert_hm.replace('123456789', str(recid)) self.test_reference = self.test_reference.replace('123456789', str(recid)) self.test_reference_expected_xm = self.test_reference_expected_xm.replace('123456789', str(recid)) self.test_reference_expected_hm = self.test_reference_expected_hm.replace('123456789', str(recid)) # test of the inserted record: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.assertEqual(compare_xmbuffers(inserted_xm, self.test_insert), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.test_insert_hm), '') self.test_recid = recid def test_reference_complete_xml_marc(self): """bibupload - reference mode, inserting references MARCXML file""" # We create create the record out of the xml marc recs = bibupload.xml_marc_to_records(self.test_reference) # We call the main function with the record as a parameter err, recid = bibupload.bibupload(recs[0], opt_mode='reference') # We retrieve the inserted xml reference_xm = print_record(recid, 'xm') reference_hm = print_record(recid, 'hm') # Compare if the two MARCXML are the same self.assertEqual(compare_xmbuffers(reference_xm, self.test_reference_expected_xm), '') self.assertEqual(compare_hmbuffers(reference_hm, self.test_reference_expected_hm), '') # clean up after ourselves: bibupload.wipe_out_record_from_all_tables(self.test_recid) return class BibUploadFMTModeTest(unittest.TestCase): """Testing FMT mode.""" def setUp(self): # pylint: disable-msg=C0103 """Initialize the MARCXML variable""" self.new_xm_with_fmt = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="FMT" ind1=" " ind2=" "> <subfield code="f">HB</subfield> <subfield code="g">Test. Okay.</subfield> <subfield code="d">2008-03-14 15:14:00</subfield> </datafield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Bar, Baz</subfield> <subfield code="u">Foo</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">On the quux and huux</subfield> </datafield> </record> """ self.expected_xm_after_inserting_new_xm_with_fmt = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Bar, Baz</subfield> <subfield code="u">Foo</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">On the quux and huux</subfield> </datafield> </record> """ self.expected_hm_after_inserting_new_xm_with_fmt = """ 001__ 123456789 003__ SzGeCERN 100__ $$aBar, Baz$$uFoo 245__ $$aOn the quux and huux """ self.recid76_xm_before_all_the_tests = print_record(76, 'xm') self.recid76_hm_before_all_the_tests = print_record(76, 'hm') self.recid76_fmts = run_sql("""SELECT last_updated, value, format FROM bibfmt WHERE id_bibrec=76""") self.recid76_xm_with_fmt = """ <record> <controlfield tag="001">76</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="FMT" ind1=" " ind2=" "> <subfield code="f">HB</subfield> <subfield code="g">Test. Here is some format value.</subfield> </datafield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Doe, John</subfield> <subfield code="u">CERN</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">On the foos and bars</subfield> </datafield> </record> """ self.recid76_xm_with_fmt_only_first = """ <record> <controlfield tag="001">76</controlfield> <datafield tag="FMT" ind1=" " ind2=" "> <subfield code="f">HB</subfield> <subfield code="g">Test. Let us see if this gets inserted well.</subfield> </datafield> </record> """ self.recid76_xm_with_fmt_only_second = """ <record> <controlfield tag="001">76</controlfield> <datafield tag="FMT" ind1=" " ind2=" "> <subfield code="f">HB</subfield> <subfield code="g">Test. Yet another test, to be run after the first one.</subfield> </datafield> <datafield tag="FMT" ind1=" " ind2=" "> <subfield code="f">HD</subfield> <subfield code="g">Test. Let's see what will be stored in the detailed format field.</subfield> </datafield> </record> """ def tearDown(self): """Helper function that restores recID 76 MARCXML, using the value saved before all the tests started to execute. (see self.recid76_xm_before_all_the_tests). Does not restore HB and HD formats. """ recs = bibupload.xml_marc_to_records(self.recid76_xm_before_all_the_tests) err, recid = bibupload.bibupload(recs[0], opt_mode='replace') for (last_updated, value, format) in self.recid76_fmts: run_sql("""UPDATE bibfmt SET last_updated=%s, value=%s WHERE id_bibrec=76 AND format=%s""", (last_updated, value, format)) inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.assertEqual(compare_xmbuffers(inserted_xm, self.recid76_xm_before_all_the_tests), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.recid76_hm_before_all_the_tests), '') def test_inserting_new_record_containing_fmt_tag(self): """bibupload - FMT tag, inserting new record containing FMT tag""" recs = bibupload.xml_marc_to_records(self.new_xm_with_fmt) (dummy, new_recid) = bibupload.bibupload(recs[0], opt_mode='insert') xm_after = print_record(new_recid, 'xm') hm_after = print_record(new_recid, 'hm') hb_after = print_record(new_recid, 'hb') self.assertEqual(compare_xmbuffers(xm_after, self.expected_xm_after_inserting_new_xm_with_fmt.replace('123456789', str(new_recid))), '') self.assertEqual(compare_hmbuffers(hm_after, self.expected_hm_after_inserting_new_xm_with_fmt.replace('123456789', str(new_recid))), '') self.assertEqual(run_sql('SELECT last_updated from bibfmt WHERE id_bibrec=%s', (new_recid, ))[0][0], datetime.datetime(2008, 3, 14, 15, 14)) self.failUnless(hb_after.startswith("Test. Okay.")) def test_updating_existing_record_formats_in_format_mode(self): """bibupload - FMT tag, updating existing record via format mode""" xm_before = print_record(76, 'xm') hm_before = print_record(76, 'hm') # insert first format value: recs = bibupload.xml_marc_to_records(self.recid76_xm_with_fmt_only_first) bibupload.bibupload(recs[0], opt_mode='format') xm_after = print_record(76, 'xm') hm_after = print_record(76, 'hm') hb_after = print_record(76, 'hb') self.assertEqual(xm_after, xm_before) self.assertEqual(hm_after, hm_before) self.failUnless(hb_after.startswith("Test. Let us see if this gets inserted well.")) # now insert another format value and recheck: recs = bibupload.xml_marc_to_records(self.recid76_xm_with_fmt_only_second) bibupload.bibupload(recs[0], opt_mode='format') xm_after = print_record(76, 'xm') hm_after = print_record(76, 'hm') hb_after = print_record(76, 'hb') hd_after = print_record(76, 'hd') self.assertEqual(xm_after, xm_before) self.assertEqual(hm_after, hm_before) self.failUnless(hb_after.startswith("Test. Yet another test, to be run after the first one.")) self.failUnless(hd_after.startswith("Test. Let's see what will be stored in the detailed format field.")) def test_updating_existing_record_formats_in_correct_mode(self): """bibupload - FMT tag, updating existing record via correct mode""" xm_before = print_record(76, 'xm') hm_before = print_record(76, 'hm') # insert first format value: recs = bibupload.xml_marc_to_records(self.recid76_xm_with_fmt_only_first) bibupload.bibupload(recs[0], opt_mode='correct') xm_after = print_record(76, 'xm') hm_after = print_record(76, 'hm') hb_after = print_record(76, 'hb') self.assertEqual(xm_after, xm_before) self.assertEqual(hm_after, hm_before) self.failUnless(hb_after.startswith("Test. Let us see if this gets inserted well.")) # now insert another format value and recheck: recs = bibupload.xml_marc_to_records(self.recid76_xm_with_fmt_only_second) bibupload.bibupload(recs[0], opt_mode='correct') xm_after = print_record(76, 'xm') hm_after = print_record(76, 'hm') hb_after = print_record(76, 'hb') hd_after = print_record(76, 'hd') self.assertEqual(xm_after, xm_before) self.assertEqual(hm_after, hm_before) self.failUnless(hb_after.startswith("Test. Yet another test, to be run after the first one.")) self.failUnless(hd_after.startswith("Test. Let's see what will be stored in the detailed format field.")) def test_updating_existing_record_formats_in_replace_mode(self): """bibupload - FMT tag, updating existing record via replace mode""" # insert first format value: recs = bibupload.xml_marc_to_records(self.recid76_xm_with_fmt_only_first) bibupload.bibupload(recs[0], opt_mode='replace') xm_after = print_record(76, 'xm') hm_after = print_record(76, 'hm') hb_after = print_record(76, 'hb') self.assertEqual(compare_xmbuffers(xm_after, '<record><controlfield tag="001">76</controlfield></record>'), '') self.assertEqual(compare_hmbuffers(hm_after, '000000076 001__ 76'), '') self.failUnless(hb_after.startswith("Test. Let us see if this gets inserted well.")) # now insert another format value and recheck: recs = bibupload.xml_marc_to_records(self.recid76_xm_with_fmt_only_second) bibupload.bibupload(recs[0], opt_mode='replace') xm_after = print_record(76, 'xm') hm_after = print_record(76, 'hm') hb_after = print_record(76, 'hb') hd_after = print_record(76, 'hd') self.assertEqual(compare_xmbuffers(xm_after, """ <record> <controlfield tag="001">76</controlfield> </record>"""), '') self.assertEqual(compare_hmbuffers(hm_after, '000000076 001__ 76'), '') self.failUnless(hb_after.startswith("Test. Yet another test, to be run after the first one.")) self.failUnless(hd_after.startswith("Test. Let's see what will be stored in the detailed format field.")) # final insertion and recheck: recs = bibupload.xml_marc_to_records(self.recid76_xm_with_fmt) bibupload.bibupload(recs[0], opt_mode='replace') xm_after = print_record(76, 'xm') hm_after = print_record(76, 'hm') hb_after = print_record(76, 'hb') hd_after = print_record(76, 'hd') self.assertEqual(compare_xmbuffers(xm_after, """ <record> <controlfield tag="001">76</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Doe, John</subfield> <subfield code="u">CERN</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">On the foos and bars</subfield> </datafield> </record> """), '') self.assertEqual(compare_hmbuffers(hm_after, """ 001__ 76 003__ SzGeCERN 100__ $$aDoe, John$$uCERN 245__ $$aOn the foos and bars """), '') self.failUnless(hb_after.startswith("Test. Here is some format value.")) self.failUnless(hd_after.startswith("Test. Let's see what will be stored in the detailed format field.")) class BibUploadRecordsWithSYSNOTest(unittest.TestCase): """Testing uploading of records that have external SYSNO present.""" def setUp(self): # pylint: disable-msg=C0103 """Initialize the MARCXML test records.""" self.verbose = 0 # Note that SYSNO fields are repeated but with different # subfields, this is to test whether bibupload would not # mistakenly pick up wrong values. self.xm_testrec1 = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Bar, Baz</subfield> <subfield code="u">Foo</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">On the quux and huux 1</subfield> </datafield> <datafield tag="%(sysnotag)s" ind1="%(sysnoind1)s" ind2="%(sysnoind2)s"> <subfield code="%(sysnosubfieldcode)s">sysno1</subfield> </datafield> <datafield tag="%(sysnotag)s" ind1="%(sysnoind1)s" ind2="%(sysnoind2)s"> <subfield code="0">sysno2</subfield> </datafield> </record> """ % {'sysnotag': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[0:3], 'sysnoind1': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[3:4] != "_" and \ CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[3:4] or " ", 'sysnoind2': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[4:5] != "_" and \ CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[4:5] or " ", 'sysnosubfieldcode': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[5:6], } self.hm_testrec1 = """ 001__ 123456789 003__ SzGeCERN 100__ $$aBar, Baz$$uFoo 245__ $$aOn the quux and huux 1 %(sysnotag)s%(sysnoind1)s%(sysnoind2)s $$%(sysnosubfieldcode)ssysno1 %(sysnotag)s%(sysnoind1)s%(sysnoind2)s $$0sysno2 """ % {'sysnotag': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[0:3], 'sysnoind1': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[3:4], 'sysnoind2': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[4:5], 'sysnosubfieldcode': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[5:6], } self.xm_testrec1_to_update = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Bar, Baz</subfield> <subfield code="u">Foo</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">On the quux and huux 1 Updated</subfield> </datafield> <datafield tag="%(sysnotag)s" ind1="%(sysnoind1)s" ind2="%(sysnoind2)s"> <subfield code="%(sysnosubfieldcode)s">sysno1</subfield> </datafield> <datafield tag="%(sysnotag)s" ind1="%(sysnoind1)s" ind2="%(sysnoind2)s"> <subfield code="0">sysno2</subfield> </datafield> </record> """ % {'sysnotag': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[0:3], 'sysnoind1': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[3:4] != "_" and \ CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[3:4] or " ", 'sysnoind2': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[4:5] != "_" and \ CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[4:5] or " ", 'sysnosubfieldcode': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[5:6], } self.xm_testrec1_updated = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Bar, Baz</subfield> <subfield code="u">Foo</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">On the quux and huux 1 Updated</subfield> </datafield> <datafield tag="%(sysnotag)s" ind1="%(sysnoind1)s" ind2="%(sysnoind2)s"> <subfield code="%(sysnosubfieldcode)s">sysno1</subfield> </datafield> <datafield tag="%(sysnotag)s" ind1="%(sysnoind1)s" ind2="%(sysnoind2)s"> <subfield code="0">sysno2</subfield> </datafield> </record> """ % {'sysnotag': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[0:3], 'sysnoind1': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[3:4] != "_" and \ CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[3:4] or " ", 'sysnoind2': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[4:5] != "_" and \ CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[4:5] or " ", 'sysnosubfieldcode': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[5:6], } self.hm_testrec1_updated = """ 001__ 123456789 003__ SzGeCERN 100__ $$aBar, Baz$$uFoo 245__ $$aOn the quux and huux 1 Updated %(sysnotag)s%(sysnoind1)s%(sysnoind2)s $$%(sysnosubfieldcode)ssysno1 %(sysnotag)s%(sysnoind1)s%(sysnoind2)s $$0sysno2 """ % {'sysnotag': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[0:3], 'sysnoind1': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[3:4], 'sysnoind2': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[4:5], 'sysnosubfieldcode': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[5:6], } self.xm_testrec2 = """ <record> <controlfield tag="001">987654321</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Bar, Baz</subfield> <subfield code="u">Foo</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">On the quux and huux 2</subfield> </datafield> <datafield tag="%(sysnotag)s" ind1="%(sysnoind1)s" ind2="%(sysnoind2)s"> <subfield code="%(sysnosubfieldcode)s">sysno2</subfield> </datafield> <datafield tag="%(sysnotag)s" ind1="%(sysnoind1)s" ind2="%(sysnoind2)s"> <subfield code="0">sysno1</subfield> </datafield> </record> """ % {'sysnotag': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[0:3], 'sysnoind1': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[3:4] != "_" and \ CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[3:4] or " ", 'sysnoind2': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[4:5] != "_" and \ CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[4:5] or " ", 'sysnosubfieldcode': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[5:6], } self.hm_testrec2 = """ 001__ 987654321 003__ SzGeCERN 100__ $$aBar, Baz$$uFoo 245__ $$aOn the quux and huux 2 %(sysnotag)s%(sysnoind1)s%(sysnoind2)s $$%(sysnosubfieldcode)ssysno2 %(sysnotag)s%(sysnoind1)s%(sysnoind2)s $$0sysno1 """ % {'sysnotag': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[0:3], 'sysnoind1': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[3:4], 'sysnoind2': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[4:5], 'sysnosubfieldcode': CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG[5:6], } def test_insert_the_same_sysno_record(self): """bibupload - SYSNO tag, refuse to insert the same SYSNO record""" # initialize bibupload mode: if self.verbose: print "test_insert_the_same_sysno_record() started" # insert record 1 first time: testrec_to_insert_first = self.xm_testrec1.replace('<controlfield tag="001">123456789</controlfield>', '') recs = bibupload.xml_marc_to_records(testrec_to_insert_first) task_set_task_param('verbose', 0) err1, recid1 = bibupload.bibupload(recs[0], opt_mode='insert') inserted_xm = print_record(recid1, 'xm') inserted_hm = print_record(recid1, 'hm') # use real recID when comparing whether it worked: self.xm_testrec1 = self.xm_testrec1.replace('123456789', str(recid1)) self.hm_testrec1 = self.hm_testrec1.replace('123456789', str(recid1)) self.assertEqual(compare_xmbuffers(inserted_xm, self.xm_testrec1), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.hm_testrec1), '') # insert record 2 first time: testrec_to_insert_first = self.xm_testrec2.replace('<controlfield tag="001">987654321</controlfield>', '') recs = bibupload.xml_marc_to_records(testrec_to_insert_first) task_set_task_param('verbose', 0) err2, recid2 = bibupload.bibupload(recs[0], opt_mode='insert') inserted_xm = print_record(recid2, 'xm') inserted_hm = print_record(recid2, 'hm') # use real recID when comparing whether it worked: self.xm_testrec2 = self.xm_testrec2.replace('987654321', str(recid2)) self.hm_testrec2 = self.hm_testrec2.replace('987654321', str(recid2)) self.assertEqual(compare_xmbuffers(inserted_xm, self.xm_testrec2), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.hm_testrec2), '') # try to insert updated record 1, it should fail: recs = bibupload.xml_marc_to_records(self.xm_testrec1_to_update) task_set_task_param('verbose', 0) err1_updated, recid1_updated = bibupload.bibupload(recs[0], opt_mode='insert') self.assertEqual(-1, recid1_updated) # delete test records bibupload.wipe_out_record_from_all_tables(recid1) bibupload.wipe_out_record_from_all_tables(recid2) bibupload.wipe_out_record_from_all_tables(recid1_updated) if self.verbose: print "test_insert_the_same_sysno_record() finished" def test_insert_or_replace_the_same_sysno_record(self): """bibupload - SYSNO tag, allow to insert or replace the same SYSNO record""" # initialize bibupload mode: task_set_task_param('verbose', self.verbose) if self.verbose: print "test_insert_or_replace_the_same_sysno_record() started" # insert/replace record 1 first time: testrec_to_insert_first = self.xm_testrec1.replace('<controlfield tag="001">123456789</controlfield>', '') recs = bibupload.xml_marc_to_records(testrec_to_insert_first) err1, recid1 = bibupload.bibupload(recs[0], opt_mode='replace_or_insert') inserted_xm = print_record(recid1, 'xm') inserted_hm = print_record(recid1, 'hm') # use real recID in test buffers when comparing whether it worked: self.xm_testrec1 = self.xm_testrec1.replace('123456789', str(recid1)) self.hm_testrec1 = self.hm_testrec1.replace('123456789', str(recid1)) self.assertEqual(compare_xmbuffers(inserted_xm, self.xm_testrec1), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.hm_testrec1), '') # try to insert/replace updated record 1, it should be okay: task_set_task_param('verbose', self.verbose) recs = bibupload.xml_marc_to_records(self.xm_testrec1_to_update) err1_updated, recid1_updated = bibupload.bibupload(recs[0], opt_mode='replace_or_insert') inserted_xm = print_record(recid1_updated, 'xm') inserted_hm = print_record(recid1_updated, 'hm') self.assertEqual(recid1, recid1_updated) # use real recID in test buffers when comparing whether it worked: self.xm_testrec1_updated = self.xm_testrec1_updated.replace('123456789', str(recid1)) self.hm_testrec1_updated = self.hm_testrec1_updated.replace('123456789', str(recid1)) self.assertEqual(compare_xmbuffers(inserted_xm, self.xm_testrec1_updated), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.hm_testrec1_updated), '') # delete test records bibupload.wipe_out_record_from_all_tables(recid1) bibupload.wipe_out_record_from_all_tables(recid1_updated) if self.verbose: print "test_insert_or_replace_the_same_sysno_record() finished" def test_replace_nonexisting_sysno_record(self): """bibupload - SYSNO tag, refuse to replace non-existing SYSNO record""" # initialize bibupload mode: task_set_task_param('verbose', self.verbose) if self.verbose: print "test_replace_nonexisting_sysno_record() started" # insert record 1 first time: testrec_to_insert_first = self.xm_testrec1.replace('<controlfield tag="001">123456789</controlfield>', '') recs = bibupload.xml_marc_to_records(testrec_to_insert_first) err1, recid1 = bibupload.bibupload(recs[0], opt_mode='replace_or_insert') inserted_xm = print_record(recid1, 'xm') inserted_hm = print_record(recid1, 'hm') # use real recID in test buffers when comparing whether it worked: self.xm_testrec1 = self.xm_testrec1.replace('123456789', str(recid1)) self.hm_testrec1 = self.hm_testrec1.replace('123456789', str(recid1)) self.assertEqual(compare_xmbuffers(inserted_xm, self.xm_testrec1), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.hm_testrec1), '') # try to replace record 2 it should fail: testrec_to_insert_first = self.xm_testrec2.replace('<controlfield tag="001">987654321</controlfield>', '') recs = bibupload.xml_marc_to_records(testrec_to_insert_first) err2, recid2 = bibupload.bibupload(recs[0], opt_mode='replace') self.assertEqual(-1, recid2) # delete test records bibupload.wipe_out_record_from_all_tables(recid1) bibupload.wipe_out_record_from_all_tables(recid2) if self.verbose: print "test_replace_nonexisting_sysno_record() finished" class BibUploadRecordsWithEXTOAIIDTest(unittest.TestCase): """Testing uploading of records that have external EXTOAIID present.""" def setUp(self): # pylint: disable-msg=C0103 """Initialize the MARCXML test records.""" self.verbose = 0 # Note that EXTOAIID fields are repeated but with different # subfields, this is to test whether bibupload would not # mistakenly pick up wrong values. self.xm_testrec1 = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="%(extoaiidtag)s" ind1="%(extoaiidind1)s" ind2="%(extoaiidind2)s"> <subfield code="%(extoaiidsubfieldcode)s">extoaiid1</subfield> <subfield code="%(extoaisrcsubfieldcode)s">extoaisrc1</subfield> </datafield> <datafield tag="%(extoaiidtag)s" ind1="%(extoaiidind1)s" ind2="%(extoaiidind2)s"> <subfield code="0">extoaiid2</subfield> </datafield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Bar, Baz</subfield> <subfield code="u">Foo</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">On the quux and huux 1</subfield> </datafield> </record> """ % {'extoaiidtag': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[0:3], 'extoaiidind1': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[3:4] != "_" and \ CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[3:4] or " ", 'extoaiidind2': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[4:5] != "_" and \ CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[4:5] or " ", 'extoaiidsubfieldcode': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[5:6], 'extoaisrcsubfieldcode' : CFG_BIBUPLOAD_EXTERNAL_OAIID_PROVENANCE_TAG[5:6], } self.hm_testrec1 = """ 001__ 123456789 003__ SzGeCERN %(extoaiidtag)s%(extoaiidind1)s%(extoaiidind2)s $$%(extoaisrcsubfieldcode)sextoaisrc1$$%(extoaiidsubfieldcode)sextoaiid1 %(extoaiidtag)s%(extoaiidind1)s%(extoaiidind2)s $$0extoaiid2 100__ $$aBar, Baz$$uFoo 245__ $$aOn the quux and huux 1 """ % {'extoaiidtag': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[0:3], 'extoaiidind1': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[3:4], 'extoaiidind2': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[4:5], 'extoaiidsubfieldcode': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[5:6], 'extoaisrcsubfieldcode' : CFG_BIBUPLOAD_EXTERNAL_OAIID_PROVENANCE_TAG[5:6], } self.xm_testrec1_to_update = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="%(extoaiidtag)s" ind1="%(extoaiidind1)s" ind2="%(extoaiidind2)s"> <subfield code="%(extoaiidsubfieldcode)s">extoaiid1</subfield> <subfield code="%(extoaisrcsubfieldcode)s">extoaisrc1</subfield> </datafield> <datafield tag="%(extoaiidtag)s" ind1="%(extoaiidind1)s" ind2="%(extoaiidind2)s"> <subfield code="0">extoaiid2</subfield> </datafield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Bar, Baz</subfield> <subfield code="u">Foo</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">On the quux and huux 1 Updated</subfield> </datafield> </record> """ % {'extoaiidtag': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[0:3], 'extoaiidind1': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[3:4] != "_" and \ CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[3:4] or " ", 'extoaiidind2': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[4:5] != "_" and \ CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[4:5] or " ", 'extoaiidsubfieldcode': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[5:6], 'extoaisrcsubfieldcode' : CFG_BIBUPLOAD_EXTERNAL_OAIID_PROVENANCE_TAG[5:6], } self.xm_testrec1_updated = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="%(extoaiidtag)s" ind1="%(extoaiidind1)s" ind2="%(extoaiidind2)s"> <subfield code="%(extoaiidsubfieldcode)s">extoaiid1</subfield> <subfield code="%(extoaisrcsubfieldcode)s">extoaisrc1</subfield> </datafield> <datafield tag="%(extoaiidtag)s" ind1="%(extoaiidind1)s" ind2="%(extoaiidind2)s"> <subfield code="0">extoaiid2</subfield> </datafield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Bar, Baz</subfield> <subfield code="u">Foo</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">On the quux and huux 1 Updated</subfield> </datafield> </record> """ % {'extoaiidtag': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[0:3], 'extoaiidind1': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[3:4] != "_" and \ CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[3:4] or " ", 'extoaiidind2': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[4:5] != "_" and \ CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[4:5] or " ", 'extoaiidsubfieldcode': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[5:6], 'extoaisrcsubfieldcode' : CFG_BIBUPLOAD_EXTERNAL_OAIID_PROVENANCE_TAG[5:6], } self.hm_testrec1_updated = """ 001__ 123456789 003__ SzGeCERN %(extoaiidtag)s%(extoaiidind1)s%(extoaiidind2)s $$%(extoaisrcsubfieldcode)sextoaisrc1$$%(extoaiidsubfieldcode)sextoaiid1 %(extoaiidtag)s%(extoaiidind1)s%(extoaiidind2)s $$0extoaiid2 100__ $$aBar, Baz$$uFoo 245__ $$aOn the quux and huux 1 Updated """ % {'extoaiidtag': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[0:3], 'extoaiidind1': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[3:4], 'extoaiidind2': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[4:5], 'extoaiidsubfieldcode': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[5:6], 'extoaisrcsubfieldcode' : CFG_BIBUPLOAD_EXTERNAL_OAIID_PROVENANCE_TAG[5:6], } self.xm_testrec2 = """ <record> <controlfield tag="001">987654321</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="%(extoaiidtag)s" ind1="%(extoaiidind1)s" ind2="%(extoaiidind2)s"> <subfield code="%(extoaiidsubfieldcode)s">extoaiid2</subfield> <subfield code="%(extoaisrcsubfieldcode)s">extoaisrc1</subfield> </datafield> <datafield tag="%(extoaiidtag)s" ind1="%(extoaiidind1)s" ind2="%(extoaiidind2)s"> <subfield code="0">extoaiid1</subfield> </datafield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Bar, Baz</subfield> <subfield code="u">Foo</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">On the quux and huux 2</subfield> </datafield> </record> """ % {'extoaiidtag': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[0:3], 'extoaiidind1': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[3:4] != "_" and \ CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[3:4] or " ", 'extoaiidind2': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[4:5] != "_" and \ CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[4:5] or " ", 'extoaiidsubfieldcode': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[5:6], 'extoaisrcsubfieldcode' : CFG_BIBUPLOAD_EXTERNAL_OAIID_PROVENANCE_TAG[5:6], } self.hm_testrec2 = """ 001__ 987654321 003__ SzGeCERN %(extoaiidtag)s%(extoaiidind1)s%(extoaiidind2)s $$%(extoaisrcsubfieldcode)sextoaisrc1$$%(extoaiidsubfieldcode)sextoaiid2 %(extoaiidtag)s%(extoaiidind1)s%(extoaiidind2)s $$0extoaiid1 100__ $$aBar, Baz$$uFoo 245__ $$aOn the quux and huux 2 """ % {'extoaiidtag': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[0:3], 'extoaiidind1': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[3:4], 'extoaiidind2': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[4:5], 'extoaiidsubfieldcode': CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG[5:6], 'extoaisrcsubfieldcode' : CFG_BIBUPLOAD_EXTERNAL_OAIID_PROVENANCE_TAG[5:6], } def test_insert_the_same_extoaiid_record(self): """bibupload - EXTOAIID tag, refuse to insert the same EXTOAIID record""" # initialize bibupload mode: task_set_task_param('verbose', self.verbose) if self.verbose: print "test_insert_the_same_extoaiid_record() started" # insert record 1 first time: testrec_to_insert_first = self.xm_testrec1.replace('<controlfield tag="001">123456789</controlfield>', '') recs = bibupload.xml_marc_to_records(testrec_to_insert_first) err1, recid1 = bibupload.bibupload(recs[0], opt_mode='insert') inserted_xm = print_record(recid1, 'xm') inserted_hm = print_record(recid1, 'hm') # use real recID when comparing whether it worked: self.xm_testrec1 = self.xm_testrec1.replace('123456789', str(recid1)) self.hm_testrec1 = self.hm_testrec1.replace('123456789', str(recid1)) self.assertEqual(compare_xmbuffers(inserted_xm, self.xm_testrec1), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.hm_testrec1), '') # insert record 2 first time: testrec_to_insert_first = self.xm_testrec2.replace('<controlfield tag="001">987654321</controlfield>', '') recs = bibupload.xml_marc_to_records(testrec_to_insert_first) err2, recid2 = bibupload.bibupload(recs[0], opt_mode='insert') inserted_xm = print_record(recid2, 'xm') inserted_hm = print_record(recid2, 'hm') # use real recID when comparing whether it worked: self.xm_testrec2 = self.xm_testrec2.replace('987654321', str(recid2)) self.hm_testrec2 = self.hm_testrec2.replace('987654321', str(recid2)) self.assertEqual(compare_xmbuffers(inserted_xm, self.xm_testrec2), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.hm_testrec2), '') # try to insert updated record 1, it should fail: recs = bibupload.xml_marc_to_records(self.xm_testrec1_to_update) err1_updated, recid1_updated = bibupload.bibupload(recs[0], opt_mode='insert') self.assertEqual(-1, recid1_updated) # delete test records bibupload.wipe_out_record_from_all_tables(recid1) bibupload.wipe_out_record_from_all_tables(recid2) bibupload.wipe_out_record_from_all_tables(recid1_updated) if self.verbose: print "test_insert_the_same_extoaiid_record() finished" def test_insert_or_replace_the_same_extoaiid_record(self): """bibupload - EXTOAIID tag, allow to insert or replace the same EXTOAIID record""" # initialize bibupload mode: task_set_task_param('verbose', self.verbose) if self.verbose: print "test_insert_or_replace_the_same_extoaiid_record() started" # insert/replace record 1 first time: testrec_to_insert_first = self.xm_testrec1.replace('<controlfield tag="001">123456789</controlfield>', '') recs = bibupload.xml_marc_to_records(testrec_to_insert_first) err1, recid1 = bibupload.bibupload(recs[0], opt_mode='replace_or_insert') inserted_xm = print_record(recid1, 'xm') inserted_hm = print_record(recid1, 'hm') # use real recID in test buffers when comparing whether it worked: self.xm_testrec1 = self.xm_testrec1.replace('123456789', str(recid1)) self.hm_testrec1 = self.hm_testrec1.replace('123456789', str(recid1)) self.assertEqual(compare_xmbuffers(inserted_xm, self.xm_testrec1), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.hm_testrec1), '') # try to insert/replace updated record 1, it should be okay: recs = bibupload.xml_marc_to_records(self.xm_testrec1_to_update) err1_updated, recid1_updated = bibupload.bibupload(recs[0], opt_mode='replace_or_insert') inserted_xm = print_record(recid1_updated, 'xm') inserted_hm = print_record(recid1_updated, 'hm') self.assertEqual(recid1, recid1_updated) # use real recID in test buffers when comparing whether it worked: self.xm_testrec1_updated = self.xm_testrec1_updated.replace('123456789', str(recid1)) self.hm_testrec1_updated = self.hm_testrec1_updated.replace('123456789', str(recid1)) self.assertEqual(compare_xmbuffers(inserted_xm, self.xm_testrec1_updated), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.hm_testrec1_updated), '') # delete test records bibupload.wipe_out_record_from_all_tables(recid1) bibupload.wipe_out_record_from_all_tables(recid1_updated) if self.verbose: print "test_insert_or_replace_the_same_extoaiid_record() finished" def test_replace_nonexisting_extoaiid_record(self): """bibupload - EXTOAIID tag, refuse to replace non-existing EXTOAIID record""" # initialize bibupload mode: task_set_task_param('verbose', self.verbose) if self.verbose: print "test_replace_nonexisting_extoaiid_record() started" # insert record 1 first time: testrec_to_insert_first = self.xm_testrec1.replace('<controlfield tag="001">123456789</controlfield>', '') recs = bibupload.xml_marc_to_records(testrec_to_insert_first) err1, recid1 = bibupload.bibupload(recs[0], opt_mode='replace_or_insert') inserted_xm = print_record(recid1, 'xm') inserted_hm = print_record(recid1, 'hm') # use real recID in test buffers when comparing whether it worked: self.xm_testrec1 = self.xm_testrec1.replace('123456789', str(recid1)) self.hm_testrec1 = self.hm_testrec1.replace('123456789', str(recid1)) self.assertEqual(compare_xmbuffers(inserted_xm, self.xm_testrec1), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.hm_testrec1), '') # try to replace record 2 it should fail: testrec_to_insert_first = self.xm_testrec2.replace('<controlfield tag="001">987654321</controlfield>', '') recs = bibupload.xml_marc_to_records(testrec_to_insert_first) err2, recid2 = bibupload.bibupload(recs[0], opt_mode='replace') self.assertEqual(-1, recid2) # delete test records bibupload.wipe_out_record_from_all_tables(recid1) bibupload.wipe_out_record_from_all_tables(recid2) if self.verbose: print "test_replace_nonexisting_extoaiid_record() finished" class BibUploadRecordsWithOAIIDTest(unittest.TestCase): """Testing uploading of records that have OAI ID present.""" def setUp(self): # pylint: disable-msg=C0103 """Initialize the MARCXML test records.""" self.verbose = 0 # Note that OAI fields are repeated but with different # subfields, this is to test whether bibupload would not # mistakenly pick up wrong values. self.xm_testrec1 = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Bar, Baz</subfield> <subfield code="u">Foo</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">On the quux and huux 1</subfield> </datafield> <datafield tag="%(oaitag)s" ind1="%(oaiind1)s" ind2="%(oaiind2)s"> <subfield code="%(oaisubfieldcode)s">oai:foo:1</subfield> </datafield> <datafield tag="%(oaitag)s" ind1="%(oaiind1)s" ind2="%(oaiind2)s"> <subfield code="0">oai:foo:2</subfield> </datafield> </record> """ % {'oaitag': CFG_OAI_ID_FIELD[0:3], 'oaiind1': CFG_OAI_ID_FIELD[3:4] != "_" and \ CFG_OAI_ID_FIELD[3:4] or " ", 'oaiind2': CFG_OAI_ID_FIELD[4:5] != "_" and \ CFG_OAI_ID_FIELD[4:5] or " ", 'oaisubfieldcode': CFG_OAI_ID_FIELD[5:6], } self.hm_testrec1 = """ 001__ 123456789 003__ SzGeCERN 100__ $$aBar, Baz$$uFoo 245__ $$aOn the quux and huux 1 %(oaitag)s%(oaiind1)s%(oaiind2)s $$%(oaisubfieldcode)soai:foo:1 %(oaitag)s%(oaiind1)s%(oaiind2)s $$0oai:foo:2 """ % {'oaitag': CFG_OAI_ID_FIELD[0:3], 'oaiind1': CFG_OAI_ID_FIELD[3:4], 'oaiind2': CFG_OAI_ID_FIELD[4:5], 'oaisubfieldcode': CFG_OAI_ID_FIELD[5:6], } self.xm_testrec1_to_update = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Bar, Baz</subfield> <subfield code="u">Foo</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">On the quux and huux 1 Updated</subfield> </datafield> <datafield tag="%(oaitag)s" ind1="%(oaiind1)s" ind2="%(oaiind2)s"> <subfield code="%(oaisubfieldcode)s">oai:foo:1</subfield> </datafield> <datafield tag="%(oaitag)s" ind1="%(oaiind1)s" ind2="%(oaiind2)s"> <subfield code="0">oai:foo:2</subfield> </datafield> </record> """ % {'oaitag': CFG_OAI_ID_FIELD[0:3], 'oaiind1': CFG_OAI_ID_FIELD[3:4] != "_" and \ CFG_OAI_ID_FIELD[3:4] or " ", 'oaiind2': CFG_OAI_ID_FIELD[4:5] != "_" and \ CFG_OAI_ID_FIELD[4:5] or " ", 'oaisubfieldcode': CFG_OAI_ID_FIELD[5:6], } self.xm_testrec1_updated = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Bar, Baz</subfield> <subfield code="u">Foo</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">On the quux and huux 1 Updated</subfield> </datafield> <datafield tag="%(oaitag)s" ind1="%(oaiind1)s" ind2="%(oaiind2)s"> <subfield code="%(oaisubfieldcode)s">oai:foo:1</subfield> </datafield> <datafield tag="%(oaitag)s" ind1="%(oaiind1)s" ind2="%(oaiind2)s"> <subfield code="0">oai:foo:2</subfield> </datafield> </record> """ % {'oaitag': CFG_OAI_ID_FIELD[0:3], 'oaiind1': CFG_OAI_ID_FIELD[3:4] != "_" and \ CFG_OAI_ID_FIELD[3:4] or " ", 'oaiind2': CFG_OAI_ID_FIELD[4:5] != "_" and \ CFG_OAI_ID_FIELD[4:5] or " ", 'oaisubfieldcode': CFG_OAI_ID_FIELD[5:6], } self.hm_testrec1_updated = """ 001__ 123456789 003__ SzGeCERN 100__ $$aBar, Baz$$uFoo 245__ $$aOn the quux and huux 1 Updated %(oaitag)s%(oaiind1)s%(oaiind2)s $$%(oaisubfieldcode)soai:foo:1 %(oaitag)s%(oaiind1)s%(oaiind2)s $$0oai:foo:2 """ % {'oaitag': CFG_OAI_ID_FIELD[0:3], 'oaiind1': CFG_OAI_ID_FIELD[3:4], 'oaiind2': CFG_OAI_ID_FIELD[4:5], 'oaisubfieldcode': CFG_OAI_ID_FIELD[5:6], } self.xm_testrec2 = """ <record> <controlfield tag="001">987654321</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Bar, Baz</subfield> <subfield code="u">Foo</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">On the quux and huux 2</subfield> </datafield> <datafield tag="%(oaitag)s" ind1="%(oaiind1)s" ind2="%(oaiind2)s"> <subfield code="%(oaisubfieldcode)s">oai:foo:2</subfield> </datafield> <datafield tag="%(oaitag)s" ind1="%(oaiind1)s" ind2="%(oaiind2)s"> <subfield code="0">oai:foo:1</subfield> </datafield> </record> """ % {'oaitag': CFG_OAI_ID_FIELD[0:3], 'oaiind1': CFG_OAI_ID_FIELD[3:4] != "_" and \ CFG_OAI_ID_FIELD[3:4] or " ", 'oaiind2': CFG_OAI_ID_FIELD[4:5] != "_" and \ CFG_OAI_ID_FIELD[4:5] or " ", 'oaisubfieldcode': CFG_OAI_ID_FIELD[5:6], } self.hm_testrec2 = """ 001__ 987654321 003__ SzGeCERN 100__ $$aBar, Baz$$uFoo 245__ $$aOn the quux and huux 2 %(oaitag)s%(oaiind1)s%(oaiind2)s $$%(oaisubfieldcode)soai:foo:2 %(oaitag)s%(oaiind1)s%(oaiind2)s $$0oai:foo:1 """ % {'oaitag': CFG_OAI_ID_FIELD[0:3], 'oaiind1': CFG_OAI_ID_FIELD[3:4], 'oaiind2': CFG_OAI_ID_FIELD[4:5], 'oaisubfieldcode': CFG_OAI_ID_FIELD[5:6], } def test_insert_the_same_oai_record(self): """bibupload - OAIID tag, refuse to insert the same OAI record""" task_set_task_param('verbose', self.verbose) # insert record 1 first time: testrec_to_insert_first = self.xm_testrec1.replace('<controlfield tag="001">123456789</controlfield>', '') recs = bibupload.xml_marc_to_records(testrec_to_insert_first) err1, recid1 = bibupload.bibupload(recs[0], opt_mode='insert') inserted_xm = print_record(recid1, 'xm') inserted_hm = print_record(recid1, 'hm') # use real recID when comparing whether it worked: self.xm_testrec1 = self.xm_testrec1.replace('123456789', str(recid1)) self.hm_testrec1 = self.hm_testrec1.replace('123456789', str(recid1)) self.assertEqual(compare_xmbuffers(inserted_xm, self.xm_testrec1), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.hm_testrec1), '') # insert record 2 first time: testrec_to_insert_first = self.xm_testrec2.replace('<controlfield tag="001">987654321</controlfield>', '') recs = bibupload.xml_marc_to_records(testrec_to_insert_first) err2, recid2 = bibupload.bibupload(recs[0], opt_mode='insert') inserted_xm = print_record(recid2, 'xm') inserted_hm = print_record(recid2, 'hm') # use real recID when comparing whether it worked: self.xm_testrec2 = self.xm_testrec2.replace('987654321', str(recid2)) self.hm_testrec2 = self.hm_testrec2.replace('987654321', str(recid2)) self.assertEqual(compare_xmbuffers(inserted_xm, self.xm_testrec2), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.hm_testrec2), '') # try to insert updated record 1, it should fail: recs = bibupload.xml_marc_to_records(self.xm_testrec1_to_update) err1_updated, recid1_updated = bibupload.bibupload(recs[0], opt_mode='insert') self.assertEqual(-1, recid1_updated) # delete test records bibupload.wipe_out_record_from_all_tables(recid1) bibupload.wipe_out_record_from_all_tables(recid2) bibupload.wipe_out_record_from_all_tables(recid1_updated) def test_insert_or_replace_the_same_oai_record(self): """bibupload - OAIID tag, allow to insert or replace the same OAI record""" # initialize bibupload mode: task_set_task_param('verbose', self.verbose) # insert/replace record 1 first time: testrec_to_insert_first = self.xm_testrec1.replace('<controlfield tag="001">123456789</controlfield>', '') recs = bibupload.xml_marc_to_records(testrec_to_insert_first) err1, recid1 = bibupload.bibupload(recs[0], opt_mode='replace_or_insert') inserted_xm = print_record(recid1, 'xm') inserted_hm = print_record(recid1, 'hm') # use real recID in test buffers when comparing whether it worked: self.xm_testrec1 = self.xm_testrec1.replace('123456789', str(recid1)) self.hm_testrec1 = self.hm_testrec1.replace('123456789', str(recid1)) self.assertEqual(compare_xmbuffers(inserted_xm, self.xm_testrec1), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.hm_testrec1), '') # try to insert/replace updated record 1, it should be okay: recs = bibupload.xml_marc_to_records(self.xm_testrec1_to_update) err1_updated, recid1_updated = bibupload.bibupload(recs[0], opt_mode='replace_or_insert') inserted_xm = print_record(recid1_updated, 'xm') inserted_hm = print_record(recid1_updated, 'hm') self.assertEqual(recid1, recid1_updated) # use real recID in test buffers when comparing whether it worked: self.xm_testrec1_updated = self.xm_testrec1_updated.replace('123456789', str(recid1)) self.hm_testrec1_updated = self.hm_testrec1_updated.replace('123456789', str(recid1)) self.assertEqual(compare_xmbuffers(inserted_xm, self.xm_testrec1_updated), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.hm_testrec1_updated), '') # delete test records bibupload.wipe_out_record_from_all_tables(recid1) bibupload.wipe_out_record_from_all_tables(recid1_updated) def test_replace_nonexisting_oai_record(self): """bibupload - OAIID tag, refuse to replace non-existing OAI record""" task_set_task_param('verbose', self.verbose) # insert record 1 first time: testrec_to_insert_first = self.xm_testrec1.replace('<controlfield tag="001">123456789</controlfield>', '') recs = bibupload.xml_marc_to_records(testrec_to_insert_first) err1, recid1 = bibupload.bibupload(recs[0], opt_mode='replace_or_insert') inserted_xm = print_record(recid1, 'xm') inserted_hm = print_record(recid1, 'hm') # use real recID in test buffers when comparing whether it worked: self.xm_testrec1 = self.xm_testrec1.replace('123456789', str(recid1)) self.hm_testrec1 = self.hm_testrec1.replace('123456789', str(recid1)) self.assertEqual(compare_xmbuffers(inserted_xm, self.xm_testrec1), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.hm_testrec1), '') # try to replace record 2 it should fail: testrec_to_insert_first = self.xm_testrec2.replace('<controlfield tag="001">987654321</controlfield>', '') recs = bibupload.xml_marc_to_records(testrec_to_insert_first) err2, recid2 = bibupload.bibupload(recs[0], opt_mode='replace') self.assertEqual(-1, recid2) # delete test records bibupload.wipe_out_record_from_all_tables(recid1) bibupload.wipe_out_record_from_all_tables(recid2) class BibUploadIndicatorsTest(unittest.TestCase): """ Testing uploading of a MARCXML record with indicators having either blank space (as per MARC schema) or empty string value (old behaviour). """ def setUp(self): """Initialize the MARCXML test record.""" self.testrec1_xm = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> </record> """ self.testrec1_hm = """ 003__ SzGeCERN 100__ $$aTest, John$$uTest University """ self.testrec2_xm = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1="" ind2=""> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> </record> """ self.testrec2_hm = """ 003__ SzGeCERN 100__ $$aTest, John$$uTest University """ def test_record_with_spaces_in_indicators(self): """bibupload - inserting MARCXML with spaces in indicators""" task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(self.testrec1_xm) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.assertEqual(compare_xmbuffers(remove_tag_001_from_xmbuffer(inserted_xm), self.testrec1_xm), '') self.assertEqual(compare_hmbuffers(remove_tag_001_from_hmbuffer(inserted_hm), self.testrec1_hm), '') bibupload.wipe_out_record_from_all_tables(recid) def test_record_with_no_spaces_in_indicators(self): """bibupload - inserting MARCXML with no spaces in indicators""" task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(self.testrec2_xm) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.assertEqual(compare_xmbuffers(remove_tag_001_from_xmbuffer(inserted_xm), self.testrec2_xm), '') self.assertEqual(compare_hmbuffers(remove_tag_001_from_hmbuffer(inserted_hm), self.testrec2_hm), '') bibupload.wipe_out_record_from_all_tables(recid) class BibUploadUpperLowerCaseTest(unittest.TestCase): """ Testing treatment of similar records with only upper and lower case value differences in the bibxxx table. """ def setUp(self): """Initialize the MARCXML test records.""" self.testrec1_xm = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> </record> """ self.testrec1_hm = """ 003__ SzGeCERN 100__ $$aTest, John$$uTest University """ self.testrec2_xm = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1="" ind2=""> <subfield code="a">TeSt, JoHn</subfield> <subfield code="u">Test UniVeRsity</subfield> </datafield> </record> """ self.testrec2_hm = """ 003__ SzGeCERN 100__ $$aTeSt, JoHn$$uTest UniVeRsity """ def test_record_with_upper_lower_case_letters(self): """bibupload - inserting similar MARCXML records with upper/lower case""" task_set_task_param('verbose', 0) # insert test record #1: recs = bibupload.xml_marc_to_records(self.testrec1_xm) err1, recid1 = bibupload.bibupload(recs[0], opt_mode='insert') recid1_inserted_xm = print_record(recid1, 'xm') recid1_inserted_hm = print_record(recid1, 'hm') # insert test record #2: recs = bibupload.xml_marc_to_records(self.testrec2_xm) err1, recid2 = bibupload.bibupload(recs[0], opt_mode='insert') recid2_inserted_xm = print_record(recid2, 'xm') recid2_inserted_hm = print_record(recid2, 'hm') # let us compare stuff now: self.assertEqual(compare_xmbuffers(remove_tag_001_from_xmbuffer(recid1_inserted_xm), self.testrec1_xm), '') self.assertEqual(compare_hmbuffers(remove_tag_001_from_hmbuffer(recid1_inserted_hm), self.testrec1_hm), '') self.assertEqual(compare_xmbuffers(remove_tag_001_from_xmbuffer(recid2_inserted_xm), self.testrec2_xm), '') self.assertEqual(compare_hmbuffers(remove_tag_001_from_hmbuffer(recid2_inserted_hm), self.testrec2_hm), '') # clean up after ourselves: bibupload.wipe_out_record_from_all_tables(recid1) bibupload.wipe_out_record_from_all_tables(recid2) class BibUploadControlledProvenanceTest(unittest.TestCase): """Testing treatment of tags under controlled provenance in the correct mode.""" def setUp(self): """Initialize the MARCXML test record.""" self.testrec1_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, Jane</subfield> <subfield code="u">Test Institute</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">Test title</subfield> </datafield> - <datafield tag="653" ind1=" " ind2=" "> + <datafield tag="653" ind1="1" ind2=" "> <subfield code="a">blabla</subfield> <subfield code="9">sam</subfield> </datafield> - <datafield tag="653" ind1=" " ind2=" "> + <datafield tag="653" ind1="1" ind2=" "> <subfield code="a">blublu</subfield> <subfield code="9">sim</subfield> </datafield> - <datafield tag="653" ind1=" " ind2=" "> + <datafield tag="653" ind1="1" ind2=" "> <subfield code="a">human</subfield> </datafield> </record> """ self.testrec1_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, Jane$$uTest Institute 245__ $$aTest title - 653__ $$9sam$$ablabla - 653__ $$9sim$$ablublu - 653__ $$ahuman + 6531_ $$9sam$$ablabla + 6531_ $$9sim$$ablublu + 6531_ $$ahuman """ self.testrec1_xm_to_correct = """ <record> <controlfield tag="001">123456789</controlfield> - <datafield tag="653" ind1=" " ind2=" "> + <datafield tag="653" ind1="1" ind2=" "> <subfield code="a">bleble</subfield> <subfield code="9">sim</subfield> </datafield> - <datafield tag="653" ind1=" " ind2=" "> + <datafield tag="653" ind1="1" ind2=" "> <subfield code="a">bloblo</subfield> <subfield code="9">som</subfield> </datafield> </record> """ self.testrec1_corrected_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, Jane</subfield> <subfield code="u">Test Institute</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">Test title</subfield> </datafield> - <datafield tag="653" ind1=" " ind2=" "> + <datafield tag="653" ind1="1" ind2=" "> <subfield code="a">blabla</subfield> <subfield code="9">sam</subfield> </datafield> - <datafield tag="653" ind1=" " ind2=" "> + <datafield tag="653" ind1="1" ind2=" "> <subfield code="a">human</subfield> </datafield> - <datafield tag="653" ind1=" " ind2=" "> + <datafield tag="653" ind1="1" ind2=" "> <subfield code="a">bleble</subfield> <subfield code="9">sim</subfield> </datafield> - <datafield tag="653" ind1=" " ind2=" "> + <datafield tag="653" ind1="1" ind2=" "> <subfield code="a">bloblo</subfield> <subfield code="9">som</subfield> </datafield> </record> """ self.testrec1_corrected_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, Jane$$uTest Institute 245__ $$aTest title - 653__ $$9sam$$ablabla - 653__ $$ahuman - 653__ $$9sim$$ableble - 653__ $$9som$$abloblo + 6531_ $$9sam$$ablabla + 6531_ $$ahuman + 6531_ $$9sim$$ableble + 6531_ $$9som$$abloblo """ # insert test record: task_set_task_param('verbose', 0) test_record_xm = self.testrec1_xm.replace('<controlfield tag="001">123456789</controlfield>', '') recs = bibupload.xml_marc_to_records(test_record_xm) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recID: self.testrec1_xm = self.testrec1_xm.replace('123456789', str(recid)) self.testrec1_hm = self.testrec1_hm.replace('123456789', str(recid)) self.testrec1_xm_to_correct = self.testrec1_xm_to_correct.replace('123456789', str(recid)) self.testrec1_corrected_xm = self.testrec1_corrected_xm.replace('123456789', str(recid)) self.testrec1_corrected_hm = self.testrec1_corrected_hm.replace('123456789', str(recid)) # test of the inserted record: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.assertEqual(compare_xmbuffers(inserted_xm, self.testrec1_xm), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.testrec1_hm), '') def test_controlled_provenance_persistence(self): """bibupload - correct mode, tags with controlled provenance""" # correct metadata tags; will the protected tags be kept? task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(self.testrec1_xm_to_correct) err, recid = bibupload.bibupload(recs[0], opt_mode='correct') corrected_xm = print_record(recid, 'xm') corrected_hm = print_record(recid, 'hm') # did it work? self.assertEqual(compare_xmbuffers(corrected_xm, self.testrec1_corrected_xm), '') self.assertEqual(compare_hmbuffers(corrected_hm, self.testrec1_corrected_hm), '') # clean up after ourselves: bibupload.wipe_out_record_from_all_tables(recid) class BibUploadStrongTagsTest(unittest.TestCase): """Testing treatment of strong tags and the replace mode.""" def setUp(self): """Initialize the MARCXML test record.""" self.testrec1_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, Jane</subfield> <subfield code="u">Test Institute</subfield> </datafield> <datafield tag="245" ind1=" " ind2=" "> <subfield code="a">Test title</subfield> </datafield> <datafield tag="%(strong_tag)s" ind1=" " ind2=" "> <subfield code="a">A value</subfield> <subfield code="b">Another value</subfield> </datafield> </record> """ % {'strong_tag': bibupload.CFG_BIBUPLOAD_STRONG_TAGS[0]} self.testrec1_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, Jane$$uTest Institute 245__ $$aTest title %(strong_tag)s__ $$aA value$$bAnother value """ % {'strong_tag': bibupload.CFG_BIBUPLOAD_STRONG_TAGS[0]} self.testrec1_xm_to_replace = """ <record> <controlfield tag="001">123456789</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, Joseph</subfield> <subfield code="u">Test Academy</subfield> </datafield> </record> """ self.testrec1_replaced_xm = """ <record> <controlfield tag="001">123456789</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, Joseph</subfield> <subfield code="u">Test Academy</subfield> </datafield> <datafield tag="%(strong_tag)s" ind1=" " ind2=" "> <subfield code="a">A value</subfield> <subfield code="b">Another value</subfield> </datafield> </record> """ % {'strong_tag': bibupload.CFG_BIBUPLOAD_STRONG_TAGS[0]} self.testrec1_replaced_hm = """ 001__ 123456789 100__ $$aTest, Joseph$$uTest Academy %(strong_tag)s__ $$aA value$$bAnother value """ % {'strong_tag': bibupload.CFG_BIBUPLOAD_STRONG_TAGS[0]} # insert test record: task_set_task_param('verbose', 0) test_record_xm = self.testrec1_xm.replace('<controlfield tag="001">123456789</controlfield>', '') recs = bibupload.xml_marc_to_records(test_record_xm) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recID: self.testrec1_xm = self.testrec1_xm.replace('123456789', str(recid)) self.testrec1_hm = self.testrec1_hm.replace('123456789', str(recid)) self.testrec1_xm_to_replace = self.testrec1_xm_to_replace.replace('123456789', str(recid)) self.testrec1_replaced_xm = self.testrec1_replaced_xm.replace('123456789', str(recid)) self.testrec1_replaced_hm = self.testrec1_replaced_hm.replace('123456789', str(recid)) # test of the inserted record: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.assertEqual(compare_xmbuffers(inserted_xm, self.testrec1_xm), '') self.assertEqual(compare_hmbuffers(inserted_hm, self.testrec1_hm), '') def test_strong_tags_persistence(self): """bibupload - strong tags, persistence in replace mode""" # replace all metadata tags; will the strong tags be kept? recs = bibupload.xml_marc_to_records(self.testrec1_xm_to_replace) err, recid = bibupload.bibupload(recs[0], opt_mode='replace') replaced_xm = print_record(recid, 'xm') replaced_hm = print_record(recid, 'hm') # did it work? self.assertEqual(compare_xmbuffers(replaced_xm, self.testrec1_replaced_xm), '') self.assertEqual(compare_hmbuffers(replaced_hm, self.testrec1_replaced_hm), '') # clean up after ourselves: bibupload.wipe_out_record_from_all_tables(recid) return class BibUploadFFTModeTest(unittest.TestCase): """ Testing treatment of fulltext file transfer import mode. """ def _test_bibdoc_status(self, recid, docname, status): res = run_sql('SELECT bd.status FROM bibrec_bibdoc as bb JOIN bibdoc as bd ON bb.id_bibdoc = bd.id WHERE bb.id_bibrec = %s AND bd.docname = %s', (recid, docname)) self.failUnless(res) self.assertEqual(status, res[0][0]) def test_writing_rights(self): """bibupload - FFT has writing rights""" self.failUnless(bibupload.writing_rights_p()) def test_simple_fft_insert(self): """bibupload - simple FFT insert""" # define the test case: test_to_upload = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cds.cern.ch/img/cds.gif</subfield> </datafield> </record> """ testrec_expected_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="u">%(siteurl)s/record/123456789/files/cds.gif</subfield> </datafield> </record> """ % {'siteurl': CFG_SITE_URL} testrec_expected_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, John$$uTest University 8564_ $$u%(siteurl)s/record/123456789/files/cds.gif """ % {'siteurl': CFG_SITE_URL} testrec_expected_url = "%(siteurl)s/record/123456789/files/cds.gif" \ % {'siteurl': CFG_SITE_URL} # insert test record: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_upload) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recid of inserted test record: testrec_expected_xm = testrec_expected_xm.replace('123456789', str(recid)) testrec_expected_hm = testrec_expected_hm.replace('123456789', str(recid)) testrec_expected_url = testrec_expected_url.replace('123456789', str(recid)) # compare expected results: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.assertEqual(compare_xmbuffers(inserted_xm, testrec_expected_xm), '') self.assertEqual(compare_hmbuffers(inserted_hm, testrec_expected_hm), '') self.failUnless(try_url_download(testrec_expected_url)) bibupload.wipe_out_record_from_all_tables(recid) def test_exotic_format_fft_append(self): """bibupload - exotic format FFT append""" # define the test case: testfile = os.path.join(CFG_TMPDIR, 'test.ps.Z') open(testfile, 'w').write('TEST') test_to_upload = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> </record> """ testrec_to_append = """ <record> <controlfield tag="001">123456789</controlfield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">%s</subfield> </datafield> </record> """ % testfile testrec_expected_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="u">%(siteurl)s/record/123456789/files/test.ps.Z</subfield> </datafield> </record> """ % {'siteurl': CFG_SITE_URL} testrec_expected_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, John$$uTest University 8564_ $$u%(siteurl)s/record/123456789/files/test.ps.Z """ % {'siteurl': CFG_SITE_URL} testrec_expected_url = "%(siteurl)s/record/123456789/files/test.ps.Z" \ % {'siteurl': CFG_SITE_URL} testrec_expected_url2 = "%(siteurl)s/record/123456789/files/test?format=ps.Z" \ % {'siteurl': CFG_SITE_URL} # insert test record: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_upload) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recid of inserted test record: testrec_to_append = testrec_to_append.replace('123456789', str(recid)) testrec_expected_xm = testrec_expected_xm.replace('123456789', str(recid)) testrec_expected_hm = testrec_expected_hm.replace('123456789', str(recid)) testrec_expected_url = testrec_expected_url.replace('123456789', str(recid)) testrec_expected_url2 = testrec_expected_url.replace('123456789', str(recid)) recs = bibupload.xml_marc_to_records(testrec_to_append) err, recid = bibupload.bibupload(recs[0], opt_mode='append') # compare expected results: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.assertEqual(compare_xmbuffers(inserted_xm, testrec_expected_xm), '') self.assertEqual(compare_hmbuffers(inserted_hm, testrec_expected_hm), '') self.assertEqual(urlopen(testrec_expected_url).read(), 'TEST') self.assertEqual(urlopen(testrec_expected_url2).read(), 'TEST') bibupload.wipe_out_record_from_all_tables(recid) def test_fft_check_md5_through_bibrecdoc_str(self): """bibupload - simple FFT insert, check md5 through BibRecDocs.str()""" # define the test case: test_to_upload = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">%s/img/head.gif</subfield> </datafield> </record> """ % CFG_SITE_URL # insert test record: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_upload) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') original_md5 = md5(urlopen('%s/img/head.gif' % CFG_SITE_URL).read()).hexdigest() bibrec_str = str(BibRecDocs(int(recid))) md5_found = False for row in bibrec_str.split('\n'): if 'checksum' in row: if original_md5 in row: md5_found = True self.failUnless(md5_found) bibupload.wipe_out_record_from_all_tables(recid) def test_detailed_fft_insert(self): """bibupload - detailed FFT insert""" # define the test case: test_to_upload = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cds.cern.ch/img/cds.gif</subfield> <subfield code="t">SuperMain</subfield> <subfield code="d">This is a description</subfield> <subfield code="z">This is a comment</subfield> <subfield code="n">CIDIESSE</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cds.cern.ch/img/cds.gif</subfield> <subfield code="t">SuperMain</subfield> <subfield code="f">.jpeg</subfield> <subfield code="d">This is a description</subfield> <subfield code="z">This is a second comment</subfield> <subfield code="n">CIDIESSE</subfield> </datafield> </record> """ testrec_expected_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="u">%(siteurl)s/record/123456789/files/CIDIESSE.gif</subfield> <subfield code="y">This is a description</subfield> <subfield code="z">This is a comment</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="u">%(siteurl)s/record/123456789/files/CIDIESSE.jpeg</subfield> <subfield code="y">This is a description</subfield> <subfield code="z">This is a second comment</subfield> </datafield> </record> """ % {'siteurl': CFG_SITE_URL} testrec_expected_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, John$$uTest University 8564_ $$u%(siteurl)s/record/123456789/files/CIDIESSE.gif$$yThis is a description$$zThis is a comment 8564_ $$u%(siteurl)s/record/123456789/files/CIDIESSE.jpeg$$yThis is a description$$zThis is a second comment """ % {'siteurl': CFG_SITE_URL} testrec_expected_url1 = "%(siteurl)s/record/123456789/files/CIDIESSE.gif" % {'siteurl': CFG_SITE_URL} testrec_expected_url2 = "%(siteurl)s/record/123456789/files/CIDIESSE.jpeg" % {'siteurl': CFG_SITE_URL} # insert test record: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_upload) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recid of inserted test record: testrec_expected_xm = testrec_expected_xm.replace('123456789', str(recid)) testrec_expected_hm = testrec_expected_hm.replace('123456789', str(recid)) testrec_expected_url1 = testrec_expected_url1.replace('123456789', str(recid)) testrec_expected_url2 = testrec_expected_url1.replace('123456789', str(recid)) # compare expected results: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.assertEqual(compare_xmbuffers(inserted_xm, testrec_expected_xm), '') self.assertEqual(compare_hmbuffers(inserted_hm, testrec_expected_hm), '') self.failUnless(try_url_download(testrec_expected_url1)) self.failUnless(try_url_download(testrec_expected_url2)) bibupload.wipe_out_record_from_all_tables(recid) def test_simple_fft_insert_with_restriction(self): """bibupload - simple FFT insert with restriction""" # define the test case: test_to_upload = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cds.cern.ch/img/cds.gif</subfield> <subfield code="r">thesis</subfield> <subfield code="x">http://cds.cern.ch/img/cds.gif</subfield> </datafield> </record> """ testrec_expected_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="u">%(siteurl)s/record/123456789/files/cds.gif</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="q">%(siteurl)s/record/123456789/files/icon-cds.gif</subfield> <subfield code="x">icon</subfield> </datafield> </record> """ % {'siteurl': CFG_SITE_URL} testrec_expected_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, John$$uTest University 8564_ $$u%(siteurl)s/record/123456789/files/cds.gif 8564_ $$q%(siteurl)s/record/123456789/files/icon-cds.gif$$xicon """ % {'siteurl': CFG_SITE_URL} testrec_expected_url = "%(siteurl)s/record/123456789/files/cds.gif" \ % {'siteurl': CFG_SITE_URL} testrec_expected_icon = "%(siteurl)s/record/123456789/files/icon-cds.gif" \ % {'siteurl': CFG_SITE_URL} # insert test record: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_upload) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recid of inserted test record: testrec_expected_xm = testrec_expected_xm.replace('123456789', str(recid)) testrec_expected_hm = testrec_expected_hm.replace('123456789', str(recid)) testrec_expected_url = testrec_expected_url.replace('123456789', str(recid)) testrec_expected_icon = testrec_expected_icon.replace('123456789', str(recid)) # compare expected results: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.assertEqual(compare_xmbuffers(inserted_xm, testrec_expected_xm), '') self.assertEqual(compare_hmbuffers(inserted_hm, testrec_expected_hm), '') open_url = urlopen(testrec_expected_url) self.failUnless("This file is restricted" in open_url.read()) open_icon = urlopen(testrec_expected_icon) restricted_icon = urlopen("%s/img/restricted.gif" % CFG_SITE_URL) self.failUnless(open_icon.read() == restricted_icon.read()) bibupload.wipe_out_record_from_all_tables(recid) def test_simple_fft_insert_with_icon(self): """bibupload - simple FFT insert with icon""" # define the test case: test_to_upload = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cds.cern.ch/img/cds.gif</subfield> <subfield code="x">http://cds.cern.ch/img/cds.gif</subfield> </datafield> </record> """ testrec_expected_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="u">%(siteurl)s/record/123456789/files/cds.gif</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="q">%(siteurl)s/record/123456789/files/icon-cds.gif</subfield> <subfield code="x">icon</subfield> </datafield> </record> """ % {'siteurl': CFG_SITE_URL} testrec_expected_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, John$$uTest University 8564_ $$u%(siteurl)s/record/123456789/files/cds.gif 8564_ $$q%(siteurl)s/record/123456789/files/icon-cds.gif$$xicon """ % {'siteurl': CFG_SITE_URL} testrec_expected_url = "%(siteurl)s/record/123456789/files/cds.gif" \ % {'siteurl': CFG_SITE_URL} testrec_expected_icon = "%(siteurl)s/record/123456789/files/icon-cds.gif" \ % {'siteurl': CFG_SITE_URL} # insert test record: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_upload) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recid of inserted test record: testrec_expected_xm = testrec_expected_xm.replace('123456789', str(recid)) testrec_expected_hm = testrec_expected_hm.replace('123456789', str(recid)) testrec_expected_url = testrec_expected_url.replace('123456789', str(recid)) testrec_expected_icon = testrec_expected_icon.replace('123456789', str(recid)) # compare expected results: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.assertEqual(compare_xmbuffers(inserted_xm, testrec_expected_xm), '') self.assertEqual(compare_hmbuffers(inserted_hm, testrec_expected_hm), '') self.failUnless(try_url_download(testrec_expected_url)) self.failUnless(try_url_download(testrec_expected_icon)) bibupload.wipe_out_record_from_all_tables(recid) def test_multiple_fft_insert(self): """bibupload - multiple FFT insert""" # define the test case: test_to_upload = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cds.cern.ch/img/cds.gif</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cdsweb.cern.ch/img/head.gif</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://doc.cern.ch/archive/electronic/hep-th/0101/0101001.pdf</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">%(prefix)s/var/tmp/demobibdata.xml</subfield> </datafield> </record> """ % { 'prefix': CFG_PREFIX } testrec_expected_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="u">%(siteurl)s/record/123456789/files/0101001.pdf</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="u">%(siteurl)s/record/123456789/files/cds.gif</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="u">%(siteurl)s/record/123456789/files/demobibdata.xml</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="u">%(siteurl)s/record/123456789/files/head.gif</subfield> </datafield> </record> """ % { 'siteurl': CFG_SITE_URL} testrec_expected_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, John$$uTest University 8564_ $$u%(siteurl)s/record/123456789/files/0101001.pdf 8564_ $$u%(siteurl)s/record/123456789/files/cds.gif 8564_ $$u%(siteurl)s/record/123456789/files/demobibdata.xml 8564_ $$u%(siteurl)s/record/123456789/files/head.gif """ % { 'siteurl': CFG_SITE_URL} # insert test record: testrec_expected_urls = [] for files in ('cds.gif', 'head.gif', '0101001.pdf', 'demobibdata.xml'): testrec_expected_urls.append('%(siteurl)s/record/123456789/files/%(files)s' % {'siteurl' : CFG_SITE_URL, 'files' : files}) task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_upload) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recid of inserted test record: testrec_expected_xm = testrec_expected_xm.replace('123456789', str(recid)) testrec_expected_hm = testrec_expected_hm.replace('123456789', str(recid)) testrec_expected_urls = [] for files in ('cds.gif', 'head.gif', '0101001.pdf', 'demobibdata.xml'): testrec_expected_urls.append('%(siteurl)s/record/%(recid)s/files/%(files)s' % {'siteurl' : CFG_SITE_URL, 'files' : files, 'recid' : recid}) # compare expected results: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') # FIXME: Next test has been commented out since, appearently, the # returned xml can have non predictable row order (but still correct) # Using only html marc output is fine because a value is represented # by a single row, so a row to row comparison can be employed. self.assertEqual(compare_xmbuffers(inserted_xm, testrec_expected_xm), '') self.assertEqual(compare_hmbuffers(inserted_hm, testrec_expected_hm), '') for url in testrec_expected_urls: self.failUnless(try_url_download(url)) self._test_bibdoc_status(recid, 'head', '') self._test_bibdoc_status(recid, '0101001', '') self._test_bibdoc_status(recid, 'cds', '') self._test_bibdoc_status(recid, 'demobibdata', '') bibupload.wipe_out_record_from_all_tables(recid) def test_simple_fft_correct(self): """bibupload - simple FFT correct""" # define the test case: test_to_upload = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cds.cern.ch/img/cds.gif</subfield> </datafield> </record> """ test_to_correct = """ <record> <controlfield tag="001">123456789</controlfield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cds.cern.ch/img/cds.gif</subfield> </datafield> </record> """ testrec_expected_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="u">%(siteurl)s/record/123456789/files/cds.gif</subfield> </datafield> </record> """ % { 'siteurl': CFG_SITE_URL} testrec_expected_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, John$$uTest University 8564_ $$u%(siteurl)s/record/123456789/files/cds.gif """ % { 'siteurl': CFG_SITE_URL} testrec_expected_url = "%(siteurl)s/record/123456789/files/cds.gif" \ % {'siteurl': CFG_SITE_URL} # insert test record: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_upload) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recid of inserted test record: testrec_expected_xm = testrec_expected_xm.replace('123456789', str(recid)) testrec_expected_hm = testrec_expected_hm.replace('123456789', str(recid)) testrec_expected_url = testrec_expected_url.replace('123456789', str(recid)) test_to_correct = test_to_correct.replace('123456789', str(recid)) # correct test record with new FFT: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_correct) bibupload.bibupload(recs[0], opt_mode='correct') # compare expected results: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.failUnless(try_url_download(testrec_expected_url)) self.assertEqual(compare_xmbuffers(inserted_xm, testrec_expected_xm), '') self.assertEqual(compare_hmbuffers(inserted_hm, testrec_expected_hm), '') self._test_bibdoc_status(recid, 'cds', '') #print "\nRecid: " + str(recid) + "\n" #print testrec_expected_hm + "\n" #print print_record(recid, 'hm') + "\n" bibupload.wipe_out_record_from_all_tables(recid) def test_detailed_fft_correct(self): """bibupload - detailed FFT correct""" # define the test case: test_to_upload = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cds.cern.ch/img/cds.gif</subfield> <subfield code="d">Try</subfield> <subfield code="z">Comment</subfield> </datafield> </record> """ test_to_correct = """ <record> <controlfield tag="001">123456789</controlfield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cdsweb.cern.ch/img/head.gif</subfield> <subfield code="n">cds</subfield> <subfield code="m">patata</subfield> <subfield code="d">Next Try</subfield> <subfield code="z">KEEP-OLD-VALUE</subfield> </datafield> </record> """ testrec_expected_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="u">%(siteurl)s/record/123456789/files/patata.gif</subfield> <subfield code="y">Next Try</subfield> <subfield code="z">Comment</subfield> </datafield> </record> """ % { 'siteurl': CFG_SITE_URL} testrec_expected_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, John$$uTest University 8564_ $$u%(siteurl)s/record/123456789/files/patata.gif$$yNext Try$$zComment """ % { 'siteurl': CFG_SITE_URL} testrec_expected_url = "%(siteurl)s/record/123456789/files/patata.gif" \ % {'siteurl': CFG_SITE_URL} # insert test record: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_upload) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recid of inserted test record: testrec_expected_xm = testrec_expected_xm.replace('123456789', str(recid)) testrec_expected_hm = testrec_expected_hm.replace('123456789', str(recid)) testrec_expected_url = testrec_expected_url.replace('123456789', str(recid)) test_to_correct = test_to_correct.replace('123456789', str(recid)) # correct test record with new FFT: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_correct) bibupload.bibupload(recs[0], opt_mode='correct') # compare expected results: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.failUnless(try_url_download(testrec_expected_url)) self.assertEqual(compare_xmbuffers(inserted_xm, testrec_expected_xm), '') self.assertEqual(compare_hmbuffers(inserted_hm, testrec_expected_hm), '') self._test_bibdoc_status(recid, 'patata', '') #print "\nRecid: " + str(recid) + "\n" #print testrec_expected_hm + "\n" #print print_record(recid, 'hm') + "\n" bibupload.wipe_out_record_from_all_tables(recid) def test_no_url_fft_correct(self): """bibupload - no_url FFT correct""" # define the test case: test_to_upload = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cds.cern.ch/img/cds.gif</subfield> <subfield code="d">Try</subfield> <subfield code="z">Comment</subfield> </datafield> </record> """ test_to_correct = """ <record> <controlfield tag="001">123456789</controlfield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="n">cds</subfield> <subfield code="m">patata</subfield> <subfield code="f">.gif</subfield> <subfield code="d">KEEP-OLD-VALUE</subfield> <subfield code="z">Next Comment</subfield> </datafield> </record> """ testrec_expected_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="u">%(siteurl)s/record/123456789/files/patata.gif</subfield> <subfield code="y">Try</subfield> <subfield code="z">Next Comment</subfield> </datafield> </record> """ % { 'siteurl': CFG_SITE_URL} testrec_expected_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, John$$uTest University 8564_ $$u%(siteurl)s/record/123456789/files/patata.gif$$yTry$$zNext Comment """ % { 'siteurl': CFG_SITE_URL} testrec_expected_url = "%(siteurl)s/record/123456789/files/patata.gif" \ % {'siteurl': CFG_SITE_URL} # insert test record: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_upload) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recid of inserted test record: testrec_expected_xm = testrec_expected_xm.replace('123456789', str(recid)) testrec_expected_hm = testrec_expected_hm.replace('123456789', str(recid)) testrec_expected_url = testrec_expected_url.replace('123456789', str(recid)) test_to_correct = test_to_correct.replace('123456789', str(recid)) # correct test record with new FFT: recs = bibupload.xml_marc_to_records(test_to_correct) bibupload.bibupload(recs[0], opt_mode='correct') # compare expected results: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.failUnless(try_url_download(testrec_expected_url)) self.assertEqual(compare_xmbuffers(inserted_xm, testrec_expected_xm), '') self.assertEqual(compare_hmbuffers(inserted_hm, testrec_expected_hm), '') self._test_bibdoc_status(recid, 'patata', '') #print "\nRecid: " + str(recid) + "\n" #print testrec_expected_hm + "\n" #print print_record(recid, 'hm') + "\n" bibupload.wipe_out_record_from_all_tables(recid) def test_new_icon_fft_append(self): """bibupload - new icon FFT append""" # define the test case: test_to_upload = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> </record> """ test_to_correct = """ <record> <controlfield tag="001">123456789</controlfield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="n">cds</subfield> <subfield code="x">http://cds.cern.ch/img/cds.gif</subfield> </datafield> </record> """ testrec_expected_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="q">%(siteurl)s/record/123456789/files/icon-cds.gif</subfield> <subfield code="x">icon</subfield> </datafield> </record> """ % { 'siteurl': CFG_SITE_URL} testrec_expected_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, John$$uTest University 8564_ $$q%(siteurl)s/record/123456789/files/icon-cds.gif$$xicon """ % { 'siteurl': CFG_SITE_URL} testrec_expected_url = "%(siteurl)s/record/123456789/files/icon-cds.gif" \ % {'siteurl': CFG_SITE_URL} # insert test record: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_upload) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recid of inserted test record: testrec_expected_xm = testrec_expected_xm.replace('123456789', str(recid)) testrec_expected_hm = testrec_expected_hm.replace('123456789', str(recid)) testrec_expected_url = testrec_expected_url.replace('123456789', str(recid)) test_to_correct = test_to_correct.replace('123456789', str(recid)) # correct test record with new FFT: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_correct) bibupload.bibupload(recs[0], opt_mode='append') # compare expected results: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.failUnless(try_url_download(testrec_expected_url)) self.assertEqual(compare_xmbuffers(inserted_xm, testrec_expected_xm), '') self.assertEqual(compare_hmbuffers(inserted_hm, testrec_expected_hm), '') self._test_bibdoc_status(recid, 'cds', '') #print "\nRecid: " + str(recid) + "\n" #print testrec_expected_hm + "\n" #print print_record(recid, 'hm') + "\n" bibupload.wipe_out_record_from_all_tables(recid) def test_multiple_fft_correct(self): """bibupload - multiple FFT correct""" # define the test case: test_to_upload = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cds.cern.ch/img/cds.gif</subfield> <subfield code="d">Try</subfield> <subfield code="z">Comment</subfield> <subfield code="r">Restricted</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cds.cern.ch/img/cds.gif</subfield> <subfield code="f">.jpeg</subfield> <subfield code="d">Try jpeg</subfield> <subfield code="z">Comment jpeg</subfield> <subfield code="r">Restricted</subfield> </datafield> </record> """ test_to_correct = """ <record> <controlfield tag="001">123456789</controlfield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cds.cern.ch/img/cds.gif</subfield> <subfield code="m">patata</subfield> <subfield code="f">.gif</subfield> <subfield code="r">New restricted</subfield> </datafield> </record> """ testrec_expected_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="u">%(siteurl)s/record/123456789/files/patata.gif</subfield> </datafield> </record> """ % { 'siteurl': CFG_SITE_URL} testrec_expected_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, John$$uTest University 8564_ $$u%(siteurl)s/record/123456789/files/patata.gif """ % { 'siteurl': CFG_SITE_URL} testrec_expected_url = "%(siteurl)s/record/123456789/files/patata.gif" \ % {'siteurl': CFG_SITE_URL} # insert test record: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_upload) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recid of inserted test record: testrec_expected_xm = testrec_expected_xm.replace('123456789', str(recid)) testrec_expected_hm = testrec_expected_hm.replace('123456789', str(recid)) testrec_expected_url = testrec_expected_url.replace('123456789', str(recid)) test_to_correct = test_to_correct.replace('123456789', str(recid)) # correct test record with new FFT: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_correct) bibupload.bibupload(recs[0], opt_mode='correct') # compare expected results: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.failUnless(try_url_download(testrec_expected_url)) self.assertEqual(compare_xmbuffers(inserted_xm, testrec_expected_xm), '') self.assertEqual(compare_hmbuffers(inserted_hm, testrec_expected_hm), '') self._test_bibdoc_status(recid, 'patata', 'New restricted') #print "\nRecid: " + str(recid) + "\n" #print testrec_expected_hm + "\n" #print print_record(recid, 'hm') + "\n" bibupload.wipe_out_record_from_all_tables(recid) def test_purge_fft_correct(self): """bibupload - purge FFT correct""" # define the test case: test_to_upload = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cds.cern.ch/img/cds.gif</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cdsweb.cern.ch/img/head.gif</subfield> </datafield> </record> """ test_to_correct = """ <record> <controlfield tag="001">123456789</controlfield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cds.cern.ch/img/cds.gif</subfield> </datafield> </record> """ test_to_purge = """ <record> <controlfield tag="001">123456789</controlfield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">http://cds.cern.ch/img/cds.gif</subfield> <subfield code="t">PURGE</subfield> </datafield> </record> """ testrec_expected_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="u">%(siteurl)s/record/123456789/files/cds.gif</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="u">%(siteurl)s/record/123456789/files/head.gif</subfield> </datafield> </record> """ % { 'siteurl': CFG_SITE_URL} testrec_expected_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, John$$uTest University 8564_ $$u%(siteurl)s/record/123456789/files/cds.gif 8564_ $$u%(siteurl)s/record/123456789/files/head.gif """ % { 'siteurl': CFG_SITE_URL} testrec_expected_url = "%(siteurl)s/record/123456789/files/cds.gif" % { 'siteurl': CFG_SITE_URL} # insert test record: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_upload) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recid of inserted test record: testrec_expected_xm = testrec_expected_xm.replace('123456789', str(recid)) testrec_expected_hm = testrec_expected_hm.replace('123456789', str(recid)) testrec_expected_url = testrec_expected_url.replace('123456789', str(recid)) test_to_correct = test_to_correct.replace('123456789', str(recid)) test_to_purge = test_to_purge.replace('123456789', str(recid)) # correct test record with new FFT: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_correct) bibupload.bibupload(recs[0], opt_mode='correct') # purge test record with new FFT: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_purge) bibupload.bibupload(recs[0], opt_mode='correct') # compare expected results: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.failUnless(try_url_download(testrec_expected_url)) self.assertEqual(compare_xmbuffers(inserted_xm, testrec_expected_xm), '') self.assertEqual(compare_hmbuffers(inserted_hm, testrec_expected_hm), '') self._test_bibdoc_status(recid, 'cds', '') self._test_bibdoc_status(recid, 'head', '') #print "\nRecid: " + str(recid) + "\n" #print testrec_expected_hm + "\n" #print print_record(recid, 'hm') + "\n" bibupload.wipe_out_record_from_all_tables(recid) def test_revert_fft_correct(self): """bibupload - revert FFT correct""" # define the test case: test_to_upload = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">%s/img/iconpen.gif</subfield> <subfield code="n">cds</subfield> </datafield> </record> """ % CFG_SITE_URL test_to_correct = """ <record> <controlfield tag="001">123456789</controlfield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">%s/img/head.gif</subfield> <subfield code="n">cds</subfield> </datafield> </record> """ % CFG_SITE_URL test_to_revert = """ <record> <controlfield tag="001">123456789</controlfield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="n">cds</subfield> <subfield code="t">REVERT</subfield> <subfield code="v">1</subfield> </datafield> </record> """ testrec_expected_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="u">%(siteurl)s/record/123456789/files/cds.gif</subfield> </datafield> </record> """ % { 'siteurl': CFG_SITE_URL} testrec_expected_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, John$$uTest University 8564_ $$u%(siteurl)s/record/123456789/files/cds.gif """ % { 'siteurl': CFG_SITE_URL} testrec_expected_url = "%(siteurl)s/record/123456789/files/cds.gif" % { 'siteurl': CFG_SITE_URL} # insert test record: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_upload) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recid of inserted test record: testrec_expected_xm = testrec_expected_xm.replace('123456789', str(recid)) testrec_expected_hm = testrec_expected_hm.replace('123456789', str(recid)) testrec_expected_url = testrec_expected_url.replace('123456789', str(recid)) test_to_correct = test_to_correct.replace('123456789', str(recid)) test_to_revert = test_to_revert.replace('123456789', str(recid)) # correct test record with new FFT: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_correct) bibupload.bibupload(recs[0], opt_mode='correct') # revert test record with new FFT: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_revert) bibupload.bibupload(recs[0], opt_mode='correct') # compare expected results: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.failUnless(try_url_download(testrec_expected_url)) self.assertEqual(compare_xmbuffers(inserted_xm, testrec_expected_xm), '') self.assertEqual(compare_hmbuffers(inserted_hm, testrec_expected_hm), '') self._test_bibdoc_status(recid, 'cds', '') expected_content_version1 = urlopen('%s/img/iconpen.gif' % CFG_SITE_URL).read() expected_content_version2 = urlopen('%s/img/head.gif' % CFG_SITE_URL).read() expected_content_version3 = expected_content_version1 content_version1 = urlopen('%s/record/%s/files/cds.gif?version=1' % (CFG_SITE_URL, recid)).read() content_version2 = urlopen('%s/record/%s/files/cds.gif?version=2' % (CFG_SITE_URL, recid)).read() content_version3 = urlopen('%s/record/%s/files/cds.gif?version=3' % (CFG_SITE_URL, recid)).read() self.assertEqual(expected_content_version1, content_version1) self.assertEqual(expected_content_version2, content_version2) self.assertEqual(expected_content_version3, content_version3) #print "\nRecid: " + str(recid) + "\n" #print testrec_expected_hm + "\n" #print print_record(recid, 'hm') + "\n" bibupload.wipe_out_record_from_all_tables(recid) def test_simple_fft_replace(self): """bibupload - simple FFT replace""" # define the test case: test_to_upload = """ <record> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">%s/img/iconpen.gif</subfield> <subfield code="n">cds</subfield> </datafield> </record> """ % CFG_SITE_URL test_to_replace = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="FFT" ind1=" " ind2=" "> <subfield code="a">%s/img/head.gif</subfield> </datafield> </record> """ % CFG_SITE_URL testrec_expected_xm = """ <record> <controlfield tag="001">123456789</controlfield> <controlfield tag="003">SzGeCERN</controlfield> <datafield tag="100" ind1=" " ind2=" "> <subfield code="a">Test, John</subfield> <subfield code="u">Test University</subfield> </datafield> <datafield tag="856" ind1="4" ind2=" "> <subfield code="u">%(siteurl)s/record/123456789/files/head.gif</subfield> </datafield> </record> """ % { 'siteurl': CFG_SITE_URL} testrec_expected_hm = """ 001__ 123456789 003__ SzGeCERN 100__ $$aTest, John$$uTest University 8564_ $$u%(siteurl)s/record/123456789/files/head.gif """ % { 'siteurl': CFG_SITE_URL} testrec_expected_url = "%(siteurl)s/record/123456789/files/head.gif" % { 'siteurl': CFG_SITE_URL} # insert test record: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_upload) err, recid = bibupload.bibupload(recs[0], opt_mode='insert') # replace test buffers with real recid of inserted test record: testrec_expected_xm = testrec_expected_xm.replace('123456789', str(recid)) testrec_expected_hm = testrec_expected_hm.replace('123456789', str(recid)) testrec_expected_url = testrec_expected_url.replace('123456789', str(recid)) test_to_replace = test_to_replace.replace('123456789', str(recid)) # replace test record with new FFT: task_set_task_param('verbose', 0) recs = bibupload.xml_marc_to_records(test_to_replace) bibupload.bibupload(recs[0], opt_mode='replace') # compare expected results: inserted_xm = print_record(recid, 'xm') inserted_hm = print_record(recid, 'hm') self.failUnless(try_url_download(testrec_expected_url)) self.assertEqual(compare_xmbuffers(inserted_xm, testrec_expected_xm), '') self.assertEqual(compare_hmbuffers(inserted_hm, testrec_expected_hm), '') expected_content_version = urlopen('%s/img/head.gif' % CFG_SITE_URL).read() content_version = urlopen('%s/record/%s/files/head.gif' % (CFG_SITE_URL, recid)).read() self.assertEqual(expected_content_version, content_version) #print "\nRecid: " + str(recid) + "\n" #print testrec_expected_hm + "\n" #print print_record(recid, 'hm') + "\n" bibupload.wipe_out_record_from_all_tables(recid) TEST_SUITE = make_test_suite(BibUploadInsertModeTest, BibUploadAppendModeTest, BibUploadCorrectModeTest, BibUploadReplaceModeTest, BibUploadReferencesModeTest, BibUploadRecordsWithSYSNOTest, BibUploadRecordsWithEXTOAIIDTest, BibUploadRecordsWithOAIIDTest, BibUploadFMTModeTest, BibUploadIndicatorsTest, BibUploadUpperLowerCaseTest, BibUploadControlledProvenanceTest, BibUploadStrongTagsTest, BibUploadFFTModeTest) #TEST_SUITE = make_test_suite(BibUploadStrongTagsTest,) if __name__ == "__main__": run_test_suite(TEST_SUITE, warn_user=True)