예제 #1
0
  def test_import_projects_exception(self):
    self.mock(gitiles_import, 'import_project', mock.Mock())
    gitiles_import.import_project.side_effect = Exception
    self.mock(projects, 'get_refs', mock.Mock(return_value=[]))

    self.mock(projects, 'get_projects', mock.Mock())
    projects.get_projects.return_value = [
      service_config_pb2.Project(
          id='chromium',
          config_location=service_config_pb2.ConfigSetLocation(
            url='https://localhost/chromium/src/',
            storage_type=service_config_pb2.ConfigSetLocation.GITILES,
          ),
      ),
      service_config_pb2.Project(
          id='will-fail',
          config_location=service_config_pb2.ConfigSetLocation(
            url='https://localhost/chromium/src/',
            storage_type=service_config_pb2.ConfigSetLocation.GITILES,
          ),
      )
    ]

    gitiles_import.import_projects()
    self.assertEqual(gitiles_import.import_project.call_count, 2)
예제 #2
0
    def test__project_and_ref_config_sets(self):
        self.mock(gitiles_import, '_import_config_set', mock.Mock())
        self.mock(projects, 'get_projects', mock.Mock())
        self.mock(projects, 'get_refs', mock.Mock())
        projects.get_projects.return_value = [
            service_config_pb2.Project(
                id='chromium',
                config_location=service_config_pb2.ConfigSetLocation(
                    url='https://localhost/chromium/src/',
                    storage_type=service_config_pb2.ConfigSetLocation.GITILES,
                )),
        ]
        RefType = project_config_pb2.RefsCfg.Ref
        projects.get_refs.return_value = {
            'chromium': [
                RefType(name='refs/heads/master'),
                RefType(name='refs/heads/release42',
                        config_path='/my-configs'),
            ],
        }

        self.assertEqual(gitiles_import._project_and_ref_config_sets(), [
            'projects/chromium',
            'projects/chromium/refs/heads/master',
            'projects/chromium/refs/heads/release42',
        ])
    def test_import_ref(self):
        self.mock(gitiles_import, '_import_config_set', mock.Mock())
        self.mock(projects, 'get_project', mock.Mock())
        self.mock(projects, 'get_refs', mock.Mock())
        projects.get_project.return_value = service_config_pb2.Project(
            id='chromium',
            config_location=service_config_pb2.ConfigSetLocation(
                url='https://localhost/chromium/src/',
                storage_type=service_config_pb2.ConfigSetLocation.GITILES,
            ),
        )
        projects.get_refs.return_value = {
            'chromium': [
                project_config_pb2.RefsCfg.Ref(name='refs/heads/release42',
                                               config_path='/my-configs'),
            ],
        }

        gitiles_import.import_ref('chromium', 'refs/heads/release42')

        gitiles_import._import_config_set.assert_called_once_with(
            'projects/chromium/refs/heads/release42',
            gitiles.Location(
                hostname='localhost',
                project='chromium/src',
                treeish='refs/heads/release42',
                path='/my-configs',
            ),
        )
예제 #4
0
 def test_import_ref_not_found(self):
   self.mock(projects, 'get_project', mock.Mock())
   projects.get_project.return_value = service_config_pb2.Project(
       id='chromium',
       config_location=service_config_pb2.ConfigSetLocation(
           url='https://localhost/chromium/src/',
           storage_type=service_config_pb2.ConfigSetLocation.GITILES,
       ),
   )
   self.mock(projects, 'get_ref', mock.Mock(return_value=None))
   with self.assertRaises(gitiles_import.NotFoundError):
     gitiles_import.import_ref('chromium', 'refs/heads/release42')
예제 #5
0
  def test_import_projects_and_refs(self):
    self.mock(gitiles_import, 'import_config_set', mock.Mock())
    self.mock(projects, 'get_projects', mock.Mock())
    self.mock(projects, 'get_refs', mock.Mock())
    projects.get_projects.return_value = [
      service_config_pb2.Project(
          id='chromium',
          config_location=service_config_pb2.ConfigSetLocation(
            url='https://localhost/chromium/src/',
            storage_type=service_config_pb2.ConfigSetLocation.GITILES,
          )
      ),
      service_config_pb2.Project(
          id='bad_location',
          config_location=service_config_pb2.ConfigSetLocation(
            url='https://localhost/',
            storage_type=service_config_pb2.ConfigSetLocation.GITILES,
          ),
      ),
      service_config_pb2.Project(
          id='non-gitiles',
      ),
    ]
    RefType = project_config_pb2.RefsCfg.Ref
    projects.get_refs.return_value = [
      RefType(name='refs/heads/master'),
      RefType(name='refs/heads/release42', config_path='/my-configs'),
    ]

    gitiles_import.import_projects()

    self.assertEqual(gitiles_import.import_config_set.call_count, 3)
    gitiles_import.import_config_set.assert_any_call(
        'projects/chromium', 'https://localhost/chromium/src/+/refs/heads/luci')
    gitiles_import.import_config_set.assert_any_call(
        'projects/chromium/refs/heads/master',
        'https://localhost/chromium/src/+/refs/heads/master/luci')
    gitiles_import.import_config_set.assert_any_call(
        'projects/chromium/refs/heads/release42',
        'https://localhost/chromium/src/+/refs/heads/release42/my-configs')
예제 #6
0
  def test_import_project(self):
    self.mock(gitiles_import, '_import_config_set', mock.Mock())
    self.mock(projects, 'get_project', mock.Mock())
    projects.get_project.return_value = service_config_pb2.Project(
        id='chromium',
        config_location=service_config_pb2.ConfigSetLocation(
            url='https://localhost/chromium/src/',
            storage_type=service_config_pb2.ConfigSetLocation.GITILES,
        ),
    )

    gitiles_import.import_project('chromium')

    gitiles_import._import_config_set.assert_called_once_with(
        'projects/chromium', 'https://localhost/chromium/src/+/refs/heads/luci')
예제 #7
0
 def test_get_projects(self):
     storage.get_latest_async.return_value.set_result('''
   projects {
     id: "chromium"
     config_location {
       storage_type: GITILES
       url: "http://localhost"
     }
   }
 ''')
     expected = service_config_pb2.ProjectsCfg(projects=[
         service_config_pb2.Project(
             id='chromium',
             config_location=service_config_pb2.ConfigSetLocation(
                 storage_type=service_config_pb2.ConfigSetLocation.GITILES,
                 url='http://localhost')),
     ], )
     self.assertEqual(projects.get_projects(), expected.projects)
    def test_import_project_ref_not_resolved(self):
        self.mock(projects, 'get_project', mock.Mock())
        projects.get_project.return_value = service_config_pb2.Project(
            id='chromium',
            config_location=service_config_pb2.ConfigSetLocation(
                url='https://localhost/chromium/src/',
                storage_type=service_config_pb2.ConfigSetLocation.GITILES,
            ),
        )

        self.mock(gitiles.Location, 'parse_resolve',
                  mock.Mock(side_effect=gitiles.TreeishResolutionError()))

        storage.ConfigSet(id='projects/chromium',
                          location='https://example.com').put()

        gitiles_import.import_project('chromium')
        self.assertIsNone(storage.ConfigSet.get_by_id('projects/chromium'))