Beispiel #1
0
 def tearDown(self):
     # clean up, in case some other tests left some straggling
     # form data.  Do this in setup and teardown because we want
     # to start with a clean slate and leave a clean slate.
     su = StorageUtility()
     su.clear()
     Submission.objects.all().delete()
     Attachment.objects.all().delete()
Beispiel #2
0
 def setUp(self):
     su = StorageUtility()
     su.clear()
     user, domain, project, build = setup_build_objects(jar_file_name="Test.jar")
     self.domain = domain
     self.user = user
     self.project = project
     self.build = build
Beispiel #3
0
def clear_data():
    """Clear most of the data in the system: schemas,
       submissions, and attachments.  Useful in the 
       setup and/or teardown methods of tests.
    """
    su = StorageUtility()
    su.clear()
    Submission.objects.all().delete()
    Attachment.objects.all().delete()
Beispiel #4
0
    def _testErrors(self, schema_file, instance_file, id):
        su = SU()
        xfm = XFM()
        xsd_file_name = os.path.join(os.path.dirname(__file__),schema_file)
        xml_file_name = os.path.join(os.path.dirname(__file__),instance_file)

        schema = xfm._add_schema_from_file(xsd_file_name)
        formdef = su.get_formdef_from_schema_file(xsd_file_name)
        data_tree = su._get_data_tree_from_file(xml_file_name)
        populator = XFormDBTablePopulator( formdef, schema )
        queries = populator.populate( data_tree )
        xfm.remove_schema(schema.id)
        return populator.errors
def reset_schema():
    from xformmanager.storageutility import StorageUtility

    su = StorageUtility()
    su.clear(remove_submissions=True)
def run():
    print "starting migration"
    from receiver.models import Submission, Attachment
    from xformmanager.models import FormDefModel, ElementDefModel, Metadata
    # this part of the script walks through all the registered
    # form definitions and deletes them.
    
    from xformmanager.storageutility import StorageUtility
    from graphing import dbhelper
    
    
    
    # let's do some sanity checks to make sure everything is working 
    # as planned.
    print "checking original database format"
    all_formdefs = FormDefModel.objects.all()
    all_tablenames = []
    all_elements = ElementDefModel.objects.all()
    print "found %s existing forms, %s elements" % (len(all_formdefs), len(all_elements))
    
    # first walk through all the expected tables and make sure they exist
    _check_data_tables(all_formdefs, all_tablenames)
    # this is temporarily commented out because the child tables are still acting
    # a bit funky.
    #_check_element_tables(all_elements)
    
    print "all tables exist pre-migration"
    
    # alright, let's clear them all now
    print "clearing xformmanager application"
    su = StorageUtility()
    su.clear(False)
        
    print "checking deletion of tables xformmanager tables"
    # now let's check make sure the forms and tables are gone
    form_count = len(FormDefModel.objects.all())
    if form_count != 0: 
        raise Exception("Not all forms were deleted!  %s remain." % (table, form))
    elem_count = len(ElementDefModel.objects.all())
    if elem_count != 0: 
        raise Exception("Not all elements were deleted!  %s remain." % (table, form))
    for tablename in all_tablenames:
        if _exists(tablename):
             raise Exception("Expected table %s to be deleted but it wasn't!" % (tablename))
    
    print "xformmanager cleanup verified"
    
    print "Migrating tables..."
    _perform_table_migration()
    print "Table migration verified"
    
    # now sync db.  we have to do this before submissions and attachments
    # are deleted because the new models expect foreign keys back to them 
    print "syncdb"
    _syncdb()
    print "done syncdb"
    
    all_submissions = Submission.objects.all()
    all_attachments = Attachment.objects.all()
    print "Cleaning up %s submissions and %s attachments" % (len(all_submissions), len(all_attachments))
    all_submissions.delete()
    all_attachments.delete()
    
    
    
    submission_count = len(Submission.objects.all())
    attachment_count = len(Attachment.objects.all())
    if submission_count != 0:
        raise Exception("Tried to delete all submissions but %s remained" % submission_count)
    if attachment_count != 0:
        raise Exception("Tried to delete all submissions but %s remained" % attachment_count)
    
    print "Submission cleanup verified"
Beispiel #7
0
 def tearDown(self):
     # clean up, in case some other tests left some straggling
     # form data.  Do this in setup and teardown because we want
     # to start with a clean slate and leave a clean slate.
     su = StorageUtility()
     su.clear()