Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e9c012

Browse files
committed
- Improve the testing of the Python Cookbook
- Create a recipe to test virtualenv - Created test_virtualenv.rb It will create a virtualenv directory and destroy one. + Test scenario will verify that bin/activate exists and the virtualenv that is to be destroyed; is. - Create a recipe to exert virtualenv and the pip provider - Created test_exert.rb It will install boto and psutils + Test scenario will verify that bin/activate exists and python can import boto and print *boto.Version* - Create a test scenario for the source recipe + Test scenario will verify that /opt/bin/python exists and returns 2.7.1 Original tests were made by Sean Porter <[email protected]> and exert and other test scenarios were enhanced (and created) by Scott M. Likens <[email protected]> Signed-off-by: Scott M. Likens <[email protected]>
1 parent a32c146 commit 2e9c012

File tree

9 files changed

+145
-1
lines changed

9 files changed

+145
-1
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< HEAD
12
.vagrant
23
Berksfile.lock
34
*~
@@ -14,3 +15,9 @@ bin/*
1415
.bundle/*
1516
.kitchen/
1617
.kitchen.local.yml
18+
=======
19+
.bundle/
20+
.kitchen/
21+
.kitchen.local.yml
22+
*.lock
23+
>>>>>>> - Improve the testing of the Python Cookbook

.kitchen.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,11 @@ suites:
4242
run_list:
4343
- recipe[python]
4444
attributes: {python: {install_method: "source"}}
45+
- name: exert
46+
run_list:
47+
- recipe[python]
48+
- recipe[python::test_exert]
49+
- name: virtualenv
50+
run_list:
51+
- recipe[python]
52+
- recipe[python::test_virtualenv]

Berksfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ metadata
55
group :integration do
66
cookbook "apt"
77
cookbook "yum"
8-
end
8+
cookbook "build-essential"
9+
end

Gemfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'rake'
4+
gem 'rspec'
5+
gem 'foodcritic'
6+
gem 'berkshelf'
7+
gem 'thor-foodcritic'
8+
gem 'vagrant-wrapper'
9+
10+
group :integration do
11+
gem 'test-kitchen', :git => "git://github.com/opscode/test-kitchen.git"
12+
gem 'kitchen-vagrant', :git => "git://github.com/opscode/kitchen-vagrant.git"
13+
gem 'kitchen-ec2', :git => "git://github.com/opscode/kitchen-ec2.git"
14+
gem 'kitchen-lxc', :git => "https://github.com/portertech/kitchen-lxc.git", :tag => 'v0.0.1.beta2'
15+
end

recipes/test_exert.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#
2+
# Author:: Scott M. Likens <[email protected]>
3+
# Cookbook Name:: python
4+
# Recipe:: test_exert
5+
#
6+
# Copyright 2013, MoPub, Inc.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
21+
python_virtualenv "#{Chef::Config[:file_cache_path]}/virtualenv" do
22+
interpreter "python"
23+
owner "root"
24+
group "root"
25+
action :create
26+
end
27+
28+
python_pip "boto" do
29+
action :install
30+
virtualenv "#{Chef::Config[:file_cache_path]}/virtualenv"
31+
end
32+
33+
python_pip "psutil" do
34+
action :install
35+
end
36+

recipes/test_virtualenv.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
# Author:: Sean Porter <[email protected]>
3+
# Cookbook Name:: python
4+
# Recipe:: test_virtualenv
5+
#
6+
# Copyright 2013, Heavy Water Operations, LLC.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
21+
python_virtualenv "/tmp/virtualenv" do
22+
interpreter "python"
23+
owner "root"
24+
group "root"
25+
action :create
26+
end
27+
28+
python_virtualenv "isolated python environment" do
29+
path "/tmp/tobedestroyed"
30+
interpreter "python"
31+
action :create
32+
end
33+
34+
python_virtualenv "deleting the isolated python environment" do
35+
path "/tmp/tobedestroyed"
36+
action :delete
37+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bats
2+
3+
@test "virtualenv test environment should exist" {
4+
[ -f "/tmp/kitchen-chef-solo/cache/virtualenv/bin/activate" ]
5+
}
6+
7+
@test "virtualenv test environment should be owned by root" {
8+
ls -l /tmp/kitchen-chef-solo/cache/virtualenv | grep "root root"
9+
}
10+
11+
@test "virtualenv test environment should have boto working" {
12+
/tmp/kitchen-chef-solo/cache/virtualenv/bin/python -c 'import boto; boto.Version'
13+
}
14+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bats
2+
3+
@test "python bin should exist" {
4+
[ -x "/opt/bin/python" ]
5+
}
6+
7+
@test "python should be version 2.7.1" {
8+
/opt/bin/python -c 'import sys; print sys.version' | grep '2.7.1'
9+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bats
2+
3+
@test "virtualenv test environment should exist" {
4+
[ -f "/tmp/virtualenv/bin/activate" ]
5+
}
6+
7+
@test "virtualenv test environment should be owned by root" {
8+
ls -l /tmp/virtualenv | grep "root root"
9+
}
10+
11+
@test "virtualenv test environment should have a working python" {
12+
/tmp/virtualenv/bin/python -c 'import sys; print sys.version'
13+
}
14+
15+
@test "virtualenv resource should be able to delete an environment" {
16+
[ ! -d "/tmp/tobedestroyed" ]
17+
}

0 commit comments

Comments
 (0)