def testExceptions(self): """ Test S3Duplicate exceptions for nonexistent fields """ assertRaises = self.assertRaises # Dummy item for testing item = S3ImportItem(self.job) item.table = current.db.dedup_test # Test invalid primary deduplicate = S3Duplicate(primary=("nonexistent", )) item.id = None item.method = item.METHOD.CREATE item.data = Storage(name="Test0") with assertRaises(SyntaxError): deduplicate(item) # Test invalid secondary deduplicate = S3Duplicate(secondary=("nonexistent", )) item.id = None item.method = item.METHOD.CREATE item.data = Storage(name="Test0") with assertRaises(SyntaxError): deduplicate(item) # Test invalid type with assertRaises(TypeError): deduplicate = S3Duplicate(primary=lambda: None) with assertRaises(TypeError): deduplicate = S3Duplicate(secondary=17)
def cms_post_duplicate(item): name = item.data.get("name") if name in ("SiteDocumentsIntro", ): S3Duplicate(noupdate=True)(item) else: item.skip = True
def cms_post_duplicate(item): name = item.data.get("name") if name in ("Subject ClaimNotification", "Message ClaimNotification", "Subject InvoiceSettled", "Message InvoiceSettled", ): S3Duplicate(noupdate=True)(item) else: item.skip = True
def testMatch(self): """ Test match with primary/secondary field """ assertEqual = self.assertEqual deduplicate = S3Duplicate( primary=("name", ), secondary=("secondary", ), ) # Dummy item for testing item = S3ImportItem(self.job) item.table = current.db.dedup_test ids = self.ids # Test primary match item.id = None item.method = item.METHOD.CREATE item.data = Storage(name="Test0") deduplicate(item) assertEqual(item.id, ids["TEST0"]) assertEqual(item.method, item.METHOD.UPDATE) # Test primary match + secondary match item.id = None item.method = item.METHOD.CREATE item.data = Storage(name="Test2", secondary="secondaryX") deduplicate(item) assertEqual(item.id, ids["TEST2"]) assertEqual(item.method, item.METHOD.UPDATE) # Test primary match + secondary mismatch item.id = None item.method = item.METHOD.CREATE item.data = Storage(name="test4", secondary="secondaryX") deduplicate(item) assertEqual(item.id, None) assertEqual(item.method, item.METHOD.CREATE) # Test primary mismatch item.id = None item.method = item.METHOD.CREATE item.data = Storage(name="Test") deduplicate(item) assertEqual(item.id, None) assertEqual(item.method, item.METHOD.CREATE)
def cms_post_duplicate(item): name = item.data.get("name") if name in ( "Subject FacilityApproved - Disabled", "Message FacilityApproved", "Subject FacilityReview - Disabled", "Message FacilityReview", "FacilityMPAVRequirements", "FacilityHygienePlanRequirements", "FacilityLayoutRequirements", ): S3Duplicate(noupdate=True)(item) else: item.skip = True
def testDefaults(self): """ Test default behavior """ assertEqual = self.assertEqual deduplicate = S3Duplicate() # Dummy item for testing item = S3ImportItem(self.job) item.table = current.db.dedup_test ids = self.ids # Test primary match item.id = None item.method = item.METHOD.CREATE item.data = Storage(name="Test0") deduplicate(item) assertEqual(item.id, ids["TEST0"]) assertEqual(item.method, item.METHOD.UPDATE) # Test primary match + secondary mismatch item.id = None item.method = item.METHOD.CREATE item.data = Storage(name="test4", secondary="secondaryX") deduplicate(item) assertEqual(item.id, ids["TEST4"]) assertEqual(item.method, item.METHOD.UPDATE) # Test primary mismatch item.id = None item.method = item.METHOD.CREATE item.data = Storage(name="Test") deduplicate(item) assertEqual(item.id, None) assertEqual(item.method, item.METHOD.CREATE)
def cms_post_duplicate(item): name = item.data.get("name") if name in ("BearerDoBIntro", "GroupDoBIntro"): S3Duplicate(noupdate=True)(item) else: item.skip = True
#ttable = s3db.org_organisation_type IMPORT_XSLT_FOLDER = os.path.join(request.folder, "static", "formats", "s3csv") TEMPLATE_FOLDER = os.path.join(request.folder, "modules", "templates", "RLPPTM") # ----------------------------------------------------------------------------- # Upgrade organisation types # if not failed: info("Upgrade Organisation Types") # Match existing by name s3db.configure( "org_organisation_type", deduplicate=S3Duplicate(), ) # Import new templates stylesheet = os.path.join(IMPORT_XSLT_FOLDER, "org", "organisation_type.xsl") filename = os.path.join(TEMPLATE_FOLDER, "org_organisation_type.csv") # Import, fail on any errors try: with open(filename, "r") as File: resource = s3db.resource("org_organisation_type") resource.import_xml(File, format="csv", stylesheet=stylesheet) except: infoln("...failed") infoln(sys.exc_info()[1])
query = (attable.name == "Zu RP geschickt") success = db(query).update(name="Sent to RP") if success: infoln("...done") else: infoln("...not found, please rename manually") # ----------------------------------------------------------------------------- if not failed: info("Upgrade map feature layers") # Deduplicate styles s3db.configure( "gis_style", deduplicate=S3Duplicate( primary=("layer_id", ), secondary=("config_id", ), ), ) # File and Stylesheet Paths stylesheet = os.path.join(IMPORT_XSLT_FOLDER, "gis", "layer_feature.xsl") filename = os.path.join(TEMPLATE_FOLDER, "gis_layer_feature.csv") # Import, fail on any errors try: with open(filename, "r") as File: resource = s3db.resource("gis_layer_feature") resource.import_xml(File, format="csv", stylesheet=stylesheet) except: infoln("...failed") infoln(sys.exc_info()[1])