def test_raw_post_update(self, session, recorder, monkeypatch): pecan.conf.repos_root = '/tmp/root' url = '/repos/foobar/master/head/windows/999/' p = Project('foobar') repo = Repo( p, "master", "windows", "999", sha1="head", ) session.commit() repo.get(1) # create a raw type repo result = session.app.post_json( url, params={ 'type': 'raw', 'needs_update': False, }, ) assert result.json['type'] == 'raw' # check that update just marks it 'ready' immediately fake_post_status = recorder() monkeypatch.setattr(asynch, 'post_status', fake_post_status) result = session.app.post(url + 'update/') assert fake_post_status.recorder_calls[0]['args'][0] == 'ready'
def test_binary_file_deleted_removes_repo(self, session, tmpdir, url_post, url_delete): # if a repo has no binaries related to it after binary deletion, it is deleted as well pecan.conf.binary_root = str(tmpdir) session.app.post(url_post, params={'force': 1}, upload_files=[('file', 'ceph-9.0.0-0.el6.x86_64.rpm', b_('hello tharrrr'))]) repo = Repo.get(1) assert repo result = session.app.delete(url_delete) assert result.status_int == 204 repo = Repo.get(1) assert not repo
def test_binary_file_deleted_removes_repo(self, session, tmpdir): # if a repo has no binaries related to it after binary deletion, it is deleted as well pecan.conf.binary_root = str(tmpdir) session.app.post( '/binaries/ceph/giant/ceph/el6/x86_64/', params={'force': 1}, upload_files=[('file', 'ceph-9.0.0-0.el6.x86_64.rpm', 'hello tharrrr')] ) repo = Repo.get(1) assert repo result = session.app.delete('/binaries/ceph/giant/ceph/el6/x86_64/ceph-9.0.0-0.el6.x86_64.rpm/') assert result.status_int == 204 repo = Repo.get(1) assert not repo
def test_update(self, session, tmpdir, url): p = Project('foobar') repo = Repo( p, "firefly", "ubuntu", "trusty", sha1="head", ) repo.path = "some_path" session.commit() repo.get(1) repo.needs_update = False session.commit() result = session.app.post_json(url, params={}) assert result.json['needs_update'] is True assert result.json['is_queued'] is False
def test_update(self, session, tmpdir): p = Project('foobar') repo = Repo( p, "firefly", "ubuntu", "trusty", ) repo.path = "some_path" session.commit() repo.get(1) repo.needs_update = False session.commit() result = session.app.post_json( "/repos/foobar/firefly/ubuntu/trusty/update", params={} ) assert result.json['needs_update'] is True
def test_binary_file_deleted_repo_exists(self, session, tmpdir): # if a repo has binaries related to it after binary deletion, it will still exist pecan.conf.binary_root = str(tmpdir) session.app.post('/binaries/ceph/giant/head/ceph/el6/x86_64/', params={'force': 1}, upload_files=[('file', 'ceph-9.0.0-0.el6.x86_64.rpm', b_('hello tharrrr'))]) session.app.post('/binaries/ceph/giant/head/ceph/el6/x86_64/', params={'force': 1}, upload_files=[('file', 'ceph-9.1.0-0.el6.x86_64.rpm', b_('hello tharrrr'))]) repo = Repo.get(1) assert repo result = session.app.delete( '/binaries/ceph/giant/head/ceph/el6/x86_64/ceph-9.0.0-0.el6.x86_64.rpm/' ) assert result.status_int == 204 repo = Repo.get(1) assert repo.needs_update
def test_rpm_is_inferred(self, session): binary = Binary( 'ceph-1.0.rpm', self.p, distro='centos', distro_version='7', arch='x86_64', ) session.commit() repo = Repo.get(1) assert repo.infer_type() == 'rpm'
def test_update(self, session, tmpdir, url): p = Project('foobar') repo = Repo( p, "firefly", "ubuntu", "trusty", sha1="head", ) repo.path = "some_path" session.commit() repo.get(1) repo.needs_update = False session.commit() result = session.app.post_json( url, params={} ) assert result.json['needs_update'] is True assert result.json['is_queued'] is False
def test_deb_is_inferred(self, session): binary = Binary( 'ceph-1.0.deb', self.p, distro='ubuntu', distro_version='trusty', arch='x86_64', ) session.commit() repo = Repo.get(1) assert repo.infer_type() == 'deb'
def test_x86_64(self, session): Binary( 'ceph-1.0.rpm', self.p, distro='centos', distro_version='7', arch='x86_64', ) session.commit() repo = Repo.get(1) assert repo.archs == ['x86_64']
def test_deb_is_inferred(self, session): Binary( 'ceph-1.0.deb', self.p, distro='ubuntu', distro_version='trusty', arch='x86_64', ) session.commit() repo = Repo.get(1) assert repo.infer_type() == 'deb'
def test_rpm_is_inferred(self, session): Binary( 'ceph-1.0.rpm', self.p, distro='centos', distro_version='7', arch='x86_64', ) session.commit() repo = Repo.get(1) assert repo.infer_type() == 'rpm'
def test_full_metric_name(self, session): Repo( self.p, ref="master", distro='ubuntu', distro_version='trusty', arch='aarch64', ) session.commit() result = Repo.get(1).metric_name assert result == "repos.ceph.ubuntu.trusty"
def test_update_triggers_a_change_in_modified(self, session): initial_repo = Repo( self.p, ref='firefly', distro='centos', distro_version='7', ) initial_timestamp = initial_repo.modified.time() session.commit() repo = Repo.get(1) repo.distro = 'rhel' session.commit() assert initial_timestamp < repo.modified.time()
def test_binary_sets_repo_type(self, session): repo = Repo(self.p, 'hammer', 'centos', '7') session.commit() Binary( 'ceph-1.0.rpm', self.p, ref='hammer', distro='centos', distro_version='7', arch='x86_64', ) session.commit() repo = Repo.get(1) assert repo.type == 'rpm'
def test_binary_sets_repo_type(self, session): repo = Repo(self.p, 'hammer', 'centos', '7') session.commit() binary = Binary( 'ceph-1.0.rpm', self.p, ref='hammer', distro='centos', distro_version='7', arch='x86_64', ) session.commit() repo = Repo.get(1) assert repo.type == 'rpm'
def test_create(self, session, url): p = Project('foobar') repo = Repo( p, "firefly", "ubuntu", "trusty", sha1="head", ) repo.path = "some_path" session.commit() repo.get(1) repo.needs_update = False session.commit() # create a raw type repo result = session.app.post_json( url, params={'type': 'raw'}, ) assert result.json['type'] == 'raw' # adding an rpm doesn't change the type Binary( 'binary.rpm', p, repo, ref='firefly', sha1='head', flavor='default', distro='ubuntu', distro_version='trusty', arch='arm64', ) session.commit() result = session.app.get(url) assert result.json['type'] == 'raw'
def test_multiple_archs(self, session): Binary( 'ceph-1.0.deb', self.p, distro='ubuntu', distro_version='trusty', arch='aarch64', ) Binary( 'ceph-1.0.deb', self.p, distro='ubuntu', distro_version='trusty', arch='x86_64', ) session.commit() repo = Repo.get(1) assert sorted(repo.archs) == sorted(['aarch64', 'x86_64'])
def test_add_extra_metadata(self, session, url): p = Project('foobar') repo = Repo( p, "firefly", "ubuntu", "trusty", sha1="head", ) repo.path = "some_path" session.commit() repo_id = repo.id data = {'version': '0.94.8', 'distros': ['precise']} session.app.post_json( url, params=data, ) updated_repo = Repo.get(repo_id) assert updated_repo.extra == {"version": "0.94.8", 'distros': ['precise']}
def test_recreate_and_requeue(self, session, tmpdir, url): path = str(tmpdir) p = Project('foobar') repo = Repo( p, "firefly", "ubuntu", "trusty", sha1="head", ) repo.path = path session.commit() repo = Repo.get(1) repo.is_queued = True session.commit() result = session.app.post_json(url) assert os.path.exists(path) is False assert result.json['needs_update'] is True assert result.json['is_queued'] is False
def test_update_invalid_fields(self, session): p = Project('foobar') repo = Repo( p, "firefly", "ubuntu", "trusty", ) repo.path = "some_path" session.commit() repo_id = repo.id data = {"bogus": "7", "distro": "centos"} result = session.app.post_json( "/repos/foobar/firefly/ubuntu/trusty/", params=data, expect_errors=True, ) assert result.status_int == 400 updated_repo = Repo.get(repo_id) assert updated_repo.distro == "ubuntu"
def test_update_single_field(self, session): p = Project('foobar') repo = Repo( p, "firefly", "ubuntu", "trusty", ) repo.path = "some_path" session.commit() repo_id = repo.id data = {"distro_version": "precise"} result = session.app.post_json( "/repos/foobar/firefly/ubuntu/trusty/", params=data, ) assert result.status_int == 200 updated_repo = Repo.get(repo_id) assert updated_repo.distro_version == "precise" assert result.json['distro_version'] == "precise"
def test_update_invalid_fields(self, session, url): p = Project('foobar') repo = Repo( p, "firefly", "ubuntu", "trusty", sha1="head", ) repo.path = "some_path" session.commit() repo_id = repo.id data = {"bogus": "7", "distro": "centos"} result = session.app.post_json( url, params=data, expect_errors=True, ) assert result.status_int == 400 updated_repo = Repo.get(repo_id) assert updated_repo.distro == "ubuntu"
def test_update_single_field(self, session, url): p = Project('foobar') repo = Repo( p, "firefly", "ubuntu", "trusty", sha1="head", ) repo.path = "some_path" session.commit() repo_id = repo.id data = {"distro_version": "precise"} result = session.app.post_json( url, params=data, ) assert result.status_int == 200 updated_repo = Repo.get(repo_id) assert updated_repo.distro_version == "precise" assert result.json['distro_version'] == "precise"
def test_add_extra_metadata(self, session, url): p = Project('foobar') repo = Repo( p, "firefly", "ubuntu", "trusty", sha1="head", ) repo.path = "some_path" session.commit() repo_id = repo.id data = {'version': '0.94.8', 'distros': ['precise']} session.app.post_json( url, params=data, ) updated_repo = Repo.get(repo_id) assert updated_repo.extra == { "version": "0.94.8", 'distros': ['precise'] }
def test_update_multiple_fields(self, session, url): p = Project('foobar') repo = Repo( p, "firefly", "ubuntu", "trusty", sha1="head", ) repo.path = "some_path" session.commit() repo_id = repo.id data = {"distro_version": "7", "distro": "centos"} result = session.app.post_json( url, params=data, ) assert result.status_int == 200 updated_repo = Repo.get(repo_id) assert updated_repo.distro_version == "7" assert updated_repo.distro == "centos" assert result.json['distro_version'] == "7" assert result.json['distro'] == "centos"