Skip to content

Commit f0db345

Browse files
committed
Enabled travis-CI ad added some initial tests
1 parent 9e78988 commit f0db345

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

.travis.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
language: python
2+
python:
3+
- "2.6"
4+
- "2.7"
5+
- "3.2"
6+
- "3.3"
7+
- "3.4"
8+
- "3.5"
9+
- "3.5-dev" # 3.5 development branch
10+
- "3.6"
11+
- "3.6-dev" # 3.6 development branch
12+
- "3.7-dev" # 3.7 development branch
13+
- "nightly" # currently points to 3.7-dev
14+
# command to install dependencies
15+
install:
16+
- "pip install -r requirements.txt"
17+
- "pip install -r development.txt"
18+
env:
19+
- PYTHONPATH=backuplambda
20+
# command to run tests
21+
script: nose

development.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
appdirs==1.4.0
2+
boto==2.45.0
3+
boto3==1.4.4
4+
botocore==1.5.7
5+
coverage==4.3.4
6+
docutils==0.13.1
7+
futures==3.0.5
8+
httpretty==0.8.10
9+
Jinja2==2.9.5
10+
jmespath==0.9.1
11+
MarkupSafe==0.23
12+
moto==0.4.31
13+
nose==1.3.7
14+
packaging==16.8
15+
pyparsing==2.1.10
16+
python-dateutil==2.6.0
17+
pytz==2016.10
18+
requests==2.13.0
19+
s3transfer==0.1.10
20+
six==1.10.0
21+
Werkzeug==0.11.15
22+
xmltodict==0.10.2

tests/tests.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import unittest
2+
import boto
3+
import boto3
4+
5+
from moto import mock_ec2, mock_sns
6+
from backuplambda import *
7+
8+
9+
def add_servers(ami_id, count):
10+
conn = boto.connect_ec2('the_key', 'the_secret')
11+
for index in range(count):
12+
instance = conn.run_instances(ami_id)
13+
instance.instances[0].add_tag('Snapshot', 'True')
14+
15+
16+
def add_volume(tag_name, tag_value, region_name):
17+
18+
ec2_boto = boto3.client('ec2', region_name=region_name)
19+
20+
ec2_boto.create_volume(Size=200, AvailabilityZone=region_name+"a")
21+
22+
vols = ec2_boto.describe_volumes()
23+
24+
resource_id = vols["Volumes"][0]["VolumeId"]
25+
ec2_boto.create_tags(Resources=[resource_id],
26+
Tags=[{"Key": tag_name, "Value": tag_value}])
27+
28+
29+
class EC2BackupManagerTest(unittest.TestCase):
30+
31+
@mock_ec2
32+
def test_init(self):
33+
add_volume("Snapshot", "True", "ap-southeast-1")
34+
add_volume("Name", "Anotherone", "ap-southeast-1")
35+
36+
mgr = EC2BackupManager(ec2_region_name="ap-southeast-1",
37+
period="day",
38+
tag_name="Snapshot",
39+
tag_value="True",
40+
date_suffix="dd",
41+
keep_count="2")
42+
43+
volumes = mgr.get_backable_resources()
44+
45+
assert len(volumes) == 1
46+
47+
48+
class LambdaHandlerTest(unittest.TestCase):
49+
50+
@mock_ec2
51+
@mock_sns
52+
def test_ec2_one_volume(self):
53+
54+
region_name = "ap-southeast-2"
55+
56+
add_volume("MakeSnapshot", "True", region_name)
57+
add_volume("Name", "Anotherone", region_name)
58+
59+
sns_boto = boto3.client('sns', region_name=region_name)
60+
61+
response = sns_boto.create_topic(Name="datopic")
62+
arn = response["TopicArn"]
63+
64+
event = {
65+
"period_label": "day",
66+
"period_format": "%a%H",
67+
68+
"ec2_region_name": region_name,
69+
# "rds_region_name": region_name,
70+
71+
"tag_name": "MakeSnapshot",
72+
"tag_value": "True",
73+
74+
"arn": arn,
75+
76+
"keep_count": 12
77+
}
78+
79+
result = lambda_handler(event)
80+
81+
print result

0 commit comments

Comments
 (0)