def run_test(source, destination_path, content_type, expected_data):

            destination = ClientMigration.MigrationDestinationHTPA(
                self, destination_path, content_type)

            job = ClientMigration.MigrationJob(self, 'test', source,
                                               destination)

            job.Run()

            hta = HydrusTagArchive.HydrusTagPairArchive(destination_path)

            result = list(hta.IteratePairs())

            self.assertEqual(set(result), set(expected_data))

            hta.Close()
    def _test_pairs_list_to_list(self, content_type):

        (current, pending, to_be_pended,
         deleted) = pair_types_to_pools[content_type]

        data = list(current)

        self.assertTrue(len(data) > 0)

        source = ClientMigration.MigrationSourceList(self, data)
        destination = ClientMigration.MigrationDestinationListPairs(self)

        job = ClientMigration.MigrationJob(self, 'test', source, destination)

        job.Run()

        self.assertEqual(destination.GetDataReceived(), data)
        def run_test(source, destination_path, desired_hash_type,
                     expected_data):

            destination = ClientMigration.MigrationDestinationHTA(
                self, destination_path, desired_hash_type)

            job = ClientMigration.MigrationJob(self, 'test', source,
                                               destination)

            job.Run()

            hta = HydrusTagArchive.HydrusTagArchive(destination_path)

            result = list(hta.IterateMappings())

            self.assertEqual(dict(result), dict(expected_data))

            hta.Close()
 def run_test( source, tag_service_key, content_action, expected_data ):
     
     destination = ClientMigration.MigrationDestinationTagServicePairs( self, tag_service_key, content_action, content_type )
     
     job = ClientMigration.MigrationJob( self, 'test', source, destination )
     
     job.Run()
     
     if content_type == HC.CONTENT_TYPE_TAG_PARENTS:
         
         statuses_to_pairs = self.Read( 'tag_parents', tag_service_key )
         
     elif content_type == HC.CONTENT_TYPE_TAG_SIBLINGS:
         
         statuses_to_pairs = self.Read( 'tag_siblings', tag_service_key )
         
     
     if content_action == HC.CONTENT_UPDATE_ADD:
         
         should_be_in = set( statuses_to_pairs[ HC.CONTENT_STATUS_CURRENT ] )
         should_not_be_in = set( statuses_to_pairs[ HC.CONTENT_STATUS_DELETED ] )
         
     elif content_action == HC.CONTENT_UPDATE_DELETE:
         
         should_be_in = set( statuses_to_pairs[ HC.CONTENT_STATUS_DELETED ] )
         should_not_be_in = set( statuses_to_pairs[ HC.CONTENT_STATUS_CURRENT ] )
         
     elif content_action == HC.CONTENT_UPDATE_PEND:
         
         should_be_in = set( statuses_to_pairs[ HC.CONTENT_STATUS_PENDING ] )
         should_not_be_in = set()
         
     elif content_action == HC.CONTENT_UPDATE_PETITION:
         
         should_be_in = set( statuses_to_pairs[ HC.CONTENT_STATUS_PETITIONED ] )
         should_not_be_in = set()
         
     
     for pair in expected_data:
         
         self.assertIn( pair, should_be_in )
         self.assertNotIn( pair, should_not_be_in )
        def run_test(source, tag_service_key, content_action, expected_data):

            destination = ClientMigration.MigrationDestinationTagServiceMappings(
                self, tag_service_key, content_action)

            job = ClientMigration.MigrationJob(self, 'test', source,
                                               destination)

            job.Run()

            self._db._weakref_media_result_cache = ClientMediaResultCache.MediaResultCache(
            )

            hashes_to_media_results = {
                media_result.GetHash(): media_result
                for media_result in self.Read(
                    'media_results', list(self._hashes_to_current_tags.keys()))
            }

            for (hash, tags) in expected_data:

                media_result = hashes_to_media_results[hash]

                t_m = media_result.GetTagsManager()

                if content_action == HC.CONTENT_UPDATE_ADD:

                    current_tags = t_m.GetCurrent(
                        tag_service_key, ClientTags.TAG_DISPLAY_STORAGE)

                    for tag in tags:

                        self.assertIn(tag, current_tags)

                elif content_action == HC.CONTENT_UPDATE_DELETE:

                    current_tags = t_m.GetCurrent(
                        tag_service_key, ClientTags.TAG_DISPLAY_STORAGE)
                    deleted_tags = t_m.GetDeleted(
                        tag_service_key, ClientTags.TAG_DISPLAY_STORAGE)

                    for tag in tags:

                        self.assertNotIn(tag, current_tags)
                        self.assertIn(tag, deleted_tags)

                elif content_action == HC.CONTENT_UPDATE_CLEAR_DELETE_RECORD:

                    deleted_tags = t_m.GetDeleted(
                        tag_service_key, ClientTags.TAG_DISPLAY_STORAGE)

                    for tag in tags:

                        self.assertNotIn(tag, deleted_tags)

                elif content_action == HC.CONTENT_UPDATE_PEND:

                    pending_tags = t_m.GetPending(
                        tag_service_key, ClientTags.TAG_DISPLAY_STORAGE)

                    for tag in tags:

                        self.assertIn(tag, pending_tags)

                elif content_action == HC.CONTENT_UPDATE_PETITION:

                    petitioned_tags = t_m.GetPetitioned(
                        tag_service_key, ClientTags.TAG_DISPLAY_STORAGE)

                    for tag in tags:

                        self.assertIn(tag, petitioned_tags)