def test_sync_no_schemata(self): """ Tests synchronizing no data from self (posts all MD5s) """ manager = XFormManager() # load data schema_1 = create_xsd_and_populate("pf_followup.xsd", path = DATA_DIR) schema_2 = create_xsd_and_populate("pf_new_reg.xsd", path = DATA_DIR) schema_3 = create_xsd_and_populate("pf_ref_completed.xsd", path = DATA_DIR) # get sync file from self schemata_file = 'schemata.tar' generate_schemata(serverhost, 'brian', 'test', download=True, to=schemata_file) # test that the received schemata file is empty self._assert_tar_count_equals(schemata_file, 0) starting_schemata_count = FormDefModel.objects.all().count() load_schemata(schemata_file, "127.0.0.1:8000") try: # verify that no new schemata were loaded self.assertEqual( starting_schemata_count, FormDefModel.objects.all().count()) finally: # clean up manager.remove_schema(schema_1.id, remove_submissions = True) manager.remove_schema(schema_2.id, remove_submissions = True) manager.remove_schema(schema_3.id, remove_submissions = True)
def test_sync_all_schemata(self): """ Tests synchronizing all schemata from self (no xmlns posted) """ manager = XFormManager() # load data schema_1 = create_xsd_and_populate("pf_followup.xsd", path = DATA_DIR) schema_2 = create_xsd_and_populate("pf_new_reg.xsd", path = DATA_DIR) schema_3 = create_xsd_and_populate("pf_ref_completed.xsd", path = DATA_DIR) starting_schemata_count = FormDefModel.objects.all().count() # get sync file from self schemata_file = "schemata.tar" generate_schemata(serverhost, 'brian', 'test', latest=False, download=True, to=schemata_file) manager.remove_schema(schema_1.id, remove_submissions = True) manager.remove_schema(schema_2.id, remove_submissions = True) manager.remove_schema(schema_3.id, remove_submissions = True) # load data from sync file load_schemata(schemata_file, "127.0.0.1:8000") try: # verify that the submissions etc. count are correct self.assertEqual( starting_schemata_count, FormDefModel.objects.all().count()) finally: # clean up self._delete_schema_from_filename("pf_followup.xsd", path = DATA_DIR) self._delete_schema_from_filename("pf_new_reg.xsd", path = DATA_DIR) self._delete_schema_from_filename("pf_ref_completed.xsd", path = DATA_DIR)
def test_sync_some_schemata(self): """ Tests synchronizing some schemata from self (posts a few xmlns) """ manager = XFormManager() # populate some files schema_1 = create_xsd_and_populate("pf_followup.xsd", path = DATA_DIR) # get xmlns of populated schemas xmlns_buffer = rest_util.get_field_as_bz2(FormDefModel, 'target_namespace') # populate a few more schema schema_2 = create_xsd_and_populate("pf_new_reg.xsd", path = DATA_DIR) schema_3 = create_xsd_and_populate("pf_ref_completed.xsd", path = DATA_DIR) starting_schemata_count = FormDefModel.objects.all().count() # get the difference between the first schema and current state schemata_file = "schemata.tar" self._POST_XMLNS(xmlns_buffer, schemata_file) # delete the ones just populated (d,e,f) manager.remove_schema(schema_2.id, remove_submissions = True) manager.remove_schema(schema_3.id, remove_submissions = True) # load data from sync file (d,e,f) load_schemata(schemata_file, "127.0.0.1:8000") try: # verify that the schematas etc. count are correct (d,e,f) self.assertEqual( starting_schemata_count, FormDefModel.objects.all().count()) self._assert_schema_registered("pf_followup.xsd", DATA_DIR) self._assert_schema_registered("pf_new_reg.xsd", DATA_DIR) self._assert_schema_registered("pf_ref_completed.xsd", DATA_DIR) finally: # clean up manager = XFormManager() manager.remove_schema(schema_1.id, remove_submissions = True) self._delete_schema_from_filename("pf_new_reg.xsd", path = DATA_DIR) self._delete_schema_from_filename("pf_ref_completed.xsd", path = DATA_DIR)