def test_migration_duplicate_unit(self, mock_modules, mock_dist,
                                      mock_association, mock_controller,
                                      mock_repo, mock_open):
        module_foo = Module(name='kung-foo', version='0.1.2', author='kung')
        module_bar = Module(name='foo', version='0.1.2', author='kung')
        module_bar.first = Mock()
        mock_modules.filter.side_effect = ([module_foo], module_bar)
        module_foo.save = Mock()
        module_foo.save.side_effect = NotUniqueError()
        repo_association = model.RepositoryContentUnit(
            repo_id='test_repo', unit_type_id='puppet_module', unit_id='bar')
        test_repo = model.Repository(repo_id='test_repo')
        mock_repo.get_repo_or_missing_resource.return_value = test_repo
        mock_association.filter.return_value = [repo_association]

        migration.migrate()

        module_foo.save.assert_called_once_with()
        mock_association.filter.assert_called_once_with(unit_id=module_foo.id)
        mock_modules.filter.assert_called_with(name='foo')
        mock_controller.disassociate_units.assert_called_once_with(
            repo_association, [module_foo])
        mock_repo.get_repo_or_missing_resource.assert_called_once_with(
            'test_repo')
        mock_controller.rebuild_content_unit_counts.assert_called_once_with(
            test_repo)
예제 #2
0
    def test_foo(self, _plugin_api, _get_db, _objects, _repo_controller):
        _plugin_api.get_unit_model_by_id.return_value = models.PackageGroup
        collection = _get_db.return_value.__getitem__.return_value
        collection.save.side_effect = NotUniqueError()

        existing_unit = _objects.filter.return_value.first.return_value

        repo_id = 'test-upload-unit'
        repo = mock.Mock(spec=Repository)
        repo.id = repo_id
        repo.working_dir = os.path.join(self.root_dir, 'working', repo_id)

        transfer_repo = mock.Mock(repo_obj=repo)

        importer = YumImporter()

        conduit = mock_conduits.import_unit_conduit(repo.working_dir)
        config = mock_conduits.plugin_call_config(copy_children=False)
        unit_key = dict(repo_id=repo_id, package_group_id="foo")
        pkgs = ['a', 'b']
        now = 1234567890.123
        unit_metadata = dict(mandatory_package_names=pkgs, _last_updated=now)
        type_id = "package_group"

        file_path = None
        importer.upload_unit(transfer_repo, type_id, unit_key, unit_metadata,
                             file_path, conduit, config)

        _repo_controller.associate_single_unit.assert_called_once_with(
            repo, existing_unit)
        self.assertEquals(pkgs, existing_unit.mandatory_package_names)
예제 #3
0
파일: models.py 프로젝트: srault95/mongrey
 def _clean_api_key(self):
     if self.api_key:
         exist = User.objects(api_key=self.api_key,
                              username__ne=self.username).first()
         if exist:
             message = _(
                 u"Conflict with api_key[%s]. Already exist") % value
             raise NotUniqueError(message)
예제 #4
0
    def test_download_succeeded_entry_not_unique(self, mock_deferred_download):
        """Assert NotUniqueError exceptions are ignored."""
        # Setup
        mock_deferred_download.return_value.save.side_effect = NotUniqueError()

        # Test
        self.listener.download_succeeded(None)
        mock_deferred_download.return_value.save.assert_called_once_with()
예제 #5
0
파일: test_scheduler.py 프로젝트: ulif/pulp
    def test_heartbeat_lock_exception(self, mock_tick, mock_celerybeatlock, mock_worker_watcher):

        mock_celerybeatlock.objects.return_value.update.return_value = 0
        mock_celerybeatlock.return_value.save.side_effect = NotUniqueError()

        sched_instance = scheduler.Scheduler()
        sched_instance.tick()

        self.assertFalse(mock_tick.called)
예제 #6
0
 def test_duplicate_user(self, mock_f, mock_model):
     """
     Test handling of Mongoengine's NotUniqueError.
     """
     mock_user = mock_model.return_value
     mock_user.save.side_effect = NotUniqueError()
     try:
         user_controller.create_user('new_user')
     except pulp_exceptions.DuplicateResource, e:
         pass
예제 #7
0
파일: test_server.py 프로젝트: ulif/pulp
    def test_insert_deferred(self, model):
        entry = Mock(unit_id=123, unit_type_id='xx')
        model.return_value.save.side_effect = NotUniqueError()

        # test
        streamer = Streamer(Mock())
        streamer._insert_deferred(entry)

        # validation
        model.assert_called_once_with(unit_id=entry.unit_id, unit_type_id=entry.unit_type_id)
        model.return_value.save.assert_called_once_with()
예제 #8
0
 def _create_new_variant_set(self):
     variant_set_name = os.path.basename(self.f)
     if VariantSet.objects(name=variant_set_name,
                           reference_set=self.reference_set):
         if not self.force:
             raise NotUniqueError(
                 "VariantSet %s already exists. Rerun with -f to recreate."
                 % variant_set_name)
         else:
             self._remove_variant_set(variant_set_name)
     self.vcf_variant_set = VariantSet.create_and_save(
         name=variant_set_name, reference_set=self.reference_set)
예제 #9
0
    def test_download_succeeded_entry_not_unique(self, mock_deferred_download):
        """Assert NotUniqueError exceptions are ignored."""
        # Setup
        mock_request = Mock()
        mock_request.getHeader.return_value = None
        mock_catalog_entry = Mock()
        mock_deferred_download.return_value.save.side_effect = NotUniqueError()
        mock_data = {
            'catalog_entry': mock_catalog_entry,
            'client_request': mock_request
        }
        mock_report = Mock(data=mock_data)
        listener = StreamerListener(Mock(), Mock())

        # Test
        listener.download_succeeded(mock_report)
        mock_deferred_download.return_value.save.assert_called_once_with()
예제 #10
0
    def test_save_duplicate_image(self, mock_dir, mock_associate, mock_load):
        # setup
        mock_dir.return_value = self.working_dir
        mock_load.return_value = {'Size': 2, 'Parent': 'xyz789'}
        os.makedirs(os.path.join(self.working_dir, 'abc123'))
        path = os.path.join(self.working_dir, 'abc123/json')
        open(path, 'w').close()
        self.item.save = mock.MagicMock()
        self.item.save.side_effect = NotUniqueError()
        self.item.safe_import_content = mock.MagicMock()
        self.item.__class__.objects = mock.MagicMock()

        # test
        self.step.process_main(self.item)

        # verify
        self.item.save.assert_called_once_with()
        self.assertFalse(self.item.safe_import_content.called)
        self.assertTrue(mock_associate.called)
예제 #11
0
    def sub_get(self, link):
        response = urlopen(link).read()
        soup = BeautifulSoup(response)
        review_link = soup.find_all('div', {'class': 'quote'})
        base_url = "https://www.tripadvisor.in"
        # reviews=[]
        for j in review_link:
            # print ("New Review Link")
            rl = j.find("a", href=True)
            print("review_link", rl)
            review_res = urlopen(base_url + rl['href']).read()
            if review_res != None:
                soup2 = BeautifulSoup(review_res)
                # print (soup2)
                rating = soup2.find(
                    'img', {'class': 'sprite-rating_s_fill'})['alt'][0]
                # review= soup2.find('p',{'property':'reviewBody'}).text +"\n"+"#rating: "+ rating
                review = soup2.find('p', {'property': 'reviewBody'}).text
                print("*********")
                review_identifier = review[0:100]
                sentiment = Senti(review).sent()
                # print("chunk done")
                # print(rating)
                try:
                    save = Reviews(survey_id=self.sid,
                                   provider=self.p,
                                   review=review,
                                   review_identifier=review_identifier,
                                   rating=rating,
                                   sentiment=sentiment).save()
                except NotUniqueError:
                    print("NotUniqueError")
                    raise NotUniqueError(
                        "A non unique error found. Skipping review collection")
                except Exception as e:
                    print("An exception occured ignoring ", e)

                # print ("Saved")
                # reviews.append(review)
            else:
                print("Empty Review")
예제 #12
0
def createTestDB():
    db_connect()
    beamline = "fmx"
    createBeamline(beamline, "17id1")
    #        createBeamline("amx", "17id2")
    #        createBeamline("john", "99id1")
    owner = 'john'

    # containers
    for i in range(1, 5):  # 1 indexed, discontinuity for testing
        containerName = 'Puck_{0}'.format(i)
        createContainer(containerName, 16, owner, kind='16_pin_puck')

    for i in range(1, 5):  # discontinuity for testing
        containerName = 'dewar_{0}'.format(i)
        createContainer(containerName, 100, owner,
                        kind='shipping_dewar')  # I don't know dewar capacity

    # named containers
    primary_dewar_name = 'primaryDewar'

    createContainer("primaryDewar", 24, owner, kind='24_puck_robot_dewar')
    createContainer("primaryDewarAMX", 24, owner, kind='24_puck_robot_dewar')
    createContainer("primaryDewarFMX", 24, owner, kind='24_puck_robot_dewar')

    for i in range(1, 5):  # discontinuity for testing
        containerName = 'Puck_{0}'.format(i)
        insertIntoContainer(primary_dewar_name, owner, i,
                            getContainerIDbyName(containerName, 'john'))

    # samples
    type_name = 'pin'
    for i in range(1, 4):  # discontinuity for testing
        containerName = 'Puck_{0}'.format(i)
        for j in range(1, 5):
            sampleName = 'samp_{0}_{1}'.format(i, j)

            try:
                sampID = createSample(sampleName,
                                      owner,
                                      kind='24_puck_robot_dewar',
                                      sample_type=type_name)

            except NotUniqueError:
                raise NotUniqueError('{0}'.format(sampleName))

            if not insertIntoContainer(containerName, owner, j, sampID):
                print('name {0}, pos {1}, sampid {2}'.format(
                    containerName, j, sampID))

    #setBeamlineConfigParam(beamline, 'mountedSample', {'puckPos': 0, 'pinPos': 0, 'sampleID': -99}) #mountedSample has no val... why??
    beamlineInfo(beamline, 'mountedSample', {
        'puckPos': 0,
        'pinPos': 0,
        'sampleID': '-99'
    })
    beamlineInfo(beamline, 'rasterScoreFlag', {'index': 0})
    setBeamlineConfigParam(
        beamline, 'dewarPlateMap', {
            '0': [180, -180],
            '1': [135, 225],
            '2': [90, -270],
            '3': [45, -315],
            '4': [0, 360],
            '5': [315, -45],
            '6': [270, 90],
            '7': [225, -135]
        })
    setBeamlineConfigParam(beamline, 'dewarPlateName', 'dewarPlateJohn')
    setBeamlineConfigParam(
        beamline, 'lowMagCamURL',
        'http://xf17id1c-ioc2.cs.nsls2.local:8007/C2.MJPG.mjpg')
    setBeamlineConfigParam(
        beamline, 'highMagCamURL',
        'http://xf17id1c-ioc2.cs.nsls2.local:8008/C2.MJPG.mjpg')
    setBeamlineConfigParam(
        beamline, 'highMagZoomCamURL',
        'http://xf17id1c-ioc2.cs.nsls2.local:8008/C1.MJPG.mjpg')
    setBeamlineConfigParam(
        beamline, 'lowMagZoomCamURL',
        'http://xf17id1c-ioc2.cs.nsls2.local:8007/C3.MJPG.mjpg')
    setBeamlineConfigParam(beamline, 'lowMagFOVx', '1450')
    setBeamlineConfigParam(beamline, 'lowMagFOVy', '1160')
    setBeamlineConfigParam(beamline, 'highMagFOVx', '380')
    setBeamlineConfigParam(beamline, 'highMagFOVy', '300')
    setBeamlineConfigParam(beamline, 'lowMagPixX', '640')
    setBeamlineConfigParam(beamline, 'lowMagPixY', '512')
    setBeamlineConfigParam(beamline, 'highMagPixX', '640')
    setBeamlineConfigParam(beamline, 'highMagPixY', '512')
    setBeamlineConfigParam(beamline, 'screenPixX', '640')
    setBeamlineConfigParam(beamline, 'screenPixY', '512')
    setBeamlineConfigParam(beamline, 'beamlineComm', 'XF:17IDC-ES:FMX{Comm}')
    setBeamlineConfigParam(beamline, 'gonioPvPrefix', 'XF:17IDC-ES:FMX')
    setBeamlineConfigParam(beamline, 'detector_id', 'EIGER-16')
    setBeamlineConfigParam(beamline, 'detRadius', '116.0')
    setBeamlineConfigParam(beamline, 'detector_type', 'pixel_array')
    setBeamlineConfigParam(beamline, 'imgsrv_port', '14007')
    setBeamlineConfigParam(beamline, 'imgsrv_host', 'x25-h.nsls.bnl.gov')
    setBeamlineConfigParam(beamline, 'has_edna', '1')
    setBeamlineConfigParam(beamline, 'has_beamline', '0')
    setBeamlineConfigParam(beamline, 'detector_offline', '0')
    setBeamlineConfigParam(beamline, 'has_xtalview', '1')
    setBeamlineConfigParam(beamline, 'camera_offset', '0.0')
    setBeamlineConfigParam(
        beamline, 'xtal_url_small',
        'http://xf17id1c-ioc2.cs.nsls2.local:8008/C2.MJPG.jpg')
    setBeamlineConfigParam(
        beamline, 'xtal_url',
        'http://xf17id1c-ioc2.cs.nsls2.local:8007/C2.MJPG.jpg')
    setBeamlineConfigParam(beamline, 'mono_mot_code', 'mon')
    setBeamlineConfigParam(beamline, 'screen_default_protocol', 'Screen')
    setBeamlineConfigParam(beamline, 'screen_default_phist', '0.0')
    setBeamlineConfigParam(beamline, 'screen_default_phi_end', '0.2')
    setBeamlineConfigParam(beamline, 'screen_default_width', '0.2')
    setBeamlineConfigParam(beamline, 'screen_default_dist', '137.0')
    setBeamlineConfigParam(beamline, 'screen_default_time', '0.02')
    setBeamlineConfigParam(beamline, 'screen_default_reso', '2.0')
    setBeamlineConfigParam(beamline, 'screen_default_wave', '1.0')
    setBeamlineConfigParam(beamline, 'screen_default_energy', '13.0')
    setBeamlineConfigParam(beamline, 'screen_default_beamWidth', '30')
    setBeamlineConfigParam(beamline, 'screen_default_beamHeight', '30')
    setBeamlineConfigParam(beamline, 'stdTrans', '0.1')
    setBeamlineConfigParam(beamline, 'beamstop_x_pvname', 'beamStopX')
    setBeamlineConfigParam(beamline, 'beamstop_y_pvname', 'beamStopY')

    #used only from GUI below?
    setBeamlineConfigParam(beamline, 'scannerType', 'Normal')
    setBeamlineConfigParam(beamline, 'attenType', 'RI')
    setBeamlineConfigParam(beamline, 'omegaMonitorPV', 'VAL')
    setBeamlineConfigParam(beamline, 'mountEnabled', '1')