Skip to content

Commit

Permalink
initial seaworthy things
Browse files Browse the repository at this point in the history
  • Loading branch information
erikh360 committed Dec 8, 2017
1 parent c7a8bd0 commit 415293c
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 6 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.git
.gitignore
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ve/
.cache/
seaworthy/__pycache__/
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
services:
- docker
language: python
python: "3.6"

env:
global:
Expand All @@ -11,7 +12,10 @@ env:
- VARIANT=
- VARIANT=alpine

install: [] # Don't do a pip install (default for Travis Python environment)
before_install:
- pip install -U pip
install:
- pip install -r seaworthy/requirements.txt

before_script:
- version="$(sed -nE 's/^junebug==([0-9\.]+)/\1/p' requirements.txt)"
Expand All @@ -21,11 +25,7 @@ before_script:
- docker pull "$image_tag" || true
script:
- travis_retry docker build --pull --cache-from "$image_tag" --file "$dockerfile" --tag "$image_tag" .
- JUNEBUG_IMAGE="$image_tag" docker-compose up --no-build -d && sleep 5
# The simplest possible test - Junebug returns 200/OK when we ask for channels
- curl -f --user guest:password http://localhost:8080/jb/channels/
- curl -f http://localhost:8080/jb/health
- JUNEBUG_IMAGE="$image_tag" docker-compose down
- (cd seaworthy; pytest -v test.py)
after_script:
- docker images

Expand Down
40 changes: 40 additions & 0 deletions seaworthy/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from seaworthy.containers.redis import RedisContainer
from seaworthy.containers.rabbitmq import RabbitMQContainer
from seaworthy.definitions import ContainerDefinition
from seaworthy.pytest.fixtures import resource_fixture


class JunebugContainer(ContainerDefinition):
IMAGE = 'praekeltfoundation/junebug'
WAIT_PATTERNS = (
'Junebug is listening on',
)

def __init__(self, name, create_kwargs):
super().__init__(name, self.IMAGE, self.WAIT_PATTERNS,
create_kwargs=create_kwargs)

redis_fixture = resource_fixture(RedisContainer(), 'redis')
rabbitmq_fixture = resource_fixture(RabbitMQContainer(), 'rabbitmq')

container = JunebugContainer('junebug', create_kwargs={
'ports': {
"80/tcp": None
},
'environment': {
'AUTH_USERNAME': 'guest',
'AUTH_PASSWORD': 'password',
'AMQP_HOST': 'rabbitmq',
'AMQP_VHOST': '/junebug',
'REDIS_HOST': 'redis',
}})

junebug_fixture = container.pytest_fixture(
'junebug_container', dependencies=('redis', 'rabbitmq'))

# Allow all the fixtures to be imported like `from fixtures import *`
__all__ = [
"redis_fixture",
"rabbitmq_fixture",
"junebug_fixture",
]
23 changes: 23 additions & 0 deletions seaworthy/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pytest

# from seaworthy.logs import output_lines

from fixtures import * # noqa: F401,F403


class TestJunebugContainer:

def test_with_authentication(self, junebug_container):
client = junebug_container.http_client()
response = client.get("/jb/channels/", auth=('guest', 'password'))
assert response.status_code == 200

def test_without_authentication(self, junebug_container):
client = junebug_container.http_client()
response = client.get("/jb/channels/")
assert response.status_code == 401

def test_health(self, junebug_container):
client = junebug_container.http_client()
response = client.get("/jb/health")
assert response.status_code == 200

0 comments on commit 415293c

Please sign in to comment.