Skip to content

Commit

Permalink
update case lib to use moto instead of live calls
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkrug committed Jun 2, 2017
1 parent fc33c86 commit f80989a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ before_install:
- "flake8 tests"
install:
- "pip install -r requirements.txt"
- "pytest tests/"
- "python setup.py build"
- "python setup.py install"
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ requests
structlog
pytz
logutils
moto
pytest-moto
mock
margaritashotgun>=0.4.0
23 changes: 19 additions & 4 deletions tests/test_case_lib.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import pytest
from moto import mock_s3, mock_ec2

import boto3
import os
import sys
Expand All @@ -10,12 +12,23 @@


class TestCaseLib():

@classmethod
def setup_class(klass):
# setup bucket to test providing an s3 bucket to Case class
klass.m = mock_s3()

klass.m.start()

klass.e = mock_ec2()
klass.e.start()

klass.created_buckets = []
klass.s3_resource = boto3.resource('s3')
klass.s3_resource = boto3.resource(
service_name='s3',
region_name='us-west-2'
#endpoint_url='http://localhost:5000',
)

klass.existing_bucket_name = "case-lib-test-{0}".format(
''.join(random.choice(string.ascii_lowercase +
string.digits) for _ in range(10))
Expand Down Expand Up @@ -93,7 +106,6 @@ def test_object_init(self):
assert case_with_cidr.case_bucket is not None
assert case_with_cidr.examiner_cidr_range == '8.8.8.8/32'


def test_prep_aws_connections(self):
self.generic_case.prep_aws_connections()

Expand All @@ -114,19 +126,22 @@ def test_rename_log_file(self):
assert result is True

def test_copy_logs_to_s3(self):
# pass
self.generic_case.copy_logs_to_s3(base_dir=self.log_base)

uploaded_files = []
case_bucket = self.s3_resource.Bucket(self.generic_case.case_bucket)
for obj in case_bucket.objects.all():
uploaded_files.append(obj.key)
uploaded_files.append(obj.key)

test_log_key = self.renamed_test_log.split("/")[-1]
test_jpg_key = self.test_jpg.split("/")[-1]
assert test_log_key in uploaded_files
assert test_jpg_key in uploaded_files


@classmethod

def teardown_class(klass):
for bucket_name in klass.created_buckets:
#cleanup all objects in created buckets
Expand Down

0 comments on commit f80989a

Please sign in to comment.