Skip to content

Commit

Permalink
Merge pull request #118 from glogiotatidis/servicetests
Browse files Browse the repository at this point in the history
Add service tests.
  • Loading branch information
glogiotatidis committed Aug 7, 2015
2 parents a3516ec + 1ce89ab commit 85e7e21
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 8 deletions.
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
sudo: false
language: python
python:
- '2.6'
- '2.6'
before_script:
- mysql -e 'create database snippets character set utf8;'
- mysql -e 'create database snippets character set utf8;'
before_install:
- git submodule update --init --recursive
- pip install flake8 requests
- flake8 snippets --exit-zero | python bin/comment-on-pr.py
- git submodule update --init --recursive
- pip install flake8 requests
- flake8 snippets --exit-zero | python bin/comment-on-pr.py
install:
- pip install -r requirements/compiled.txt
- pip install -r requirements/dev.txt
- pip install -r requirements/compiled.txt
- pip install -r requirements/dev.txt
script:
- python manage.py test
- python manage.py test snippets
env:
global:
- TRAVIS_BOT_GITHUB_TOKEN=032783628529705aa6c4a3c79610b0fa593fed21
2 changes: 2 additions & 0 deletions service_tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests
pytest
9 changes: 9 additions & 0 deletions service_tests/runtests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

TDIR=`mktemp -d`
virtualenv $TDIR
. $TDIR/bin/activate

cd service_tests
pip install -r requirements.txt
py.test
67 changes: 67 additions & 0 deletions service_tests/test_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python
import os
import time
from urlparse import urljoin

import pytest
import requests


BASE_URL = os.environ.get('BASE_URL', 'https://snippets.mozilla.com')


@pytest.fixture(scope='module')
def snippets_request():
url = urljoin(
BASE_URL,
'/4/Firefox/32.0.3/20140923175406/Darwin_Universal-gcc3/test-bot-{time}/release/Darwin%2013.3.0/default/default/')
url = url.format(time=time.time())
response = requests.get(url, allow_redirects=False)
return response


@pytest.fixture(scope='module')
def bundle_request(snippets_request):
response = requests.get(snippets_request.headers['location'], allow_redirects=False)
return response


@pytest.fixture(scope='module')
def stats_request():
url = 'https://snippets-stats.mozilla.org/foo.html'
response = requests.get(url, allow_redirects=False)
return response


def test_bundle_redirect(snippets_request):
bundle_url = urljoin(BASE_URL, '/media/bundles/bundle_')
assert snippets_request.status_code == 302
assert snippets_request.headers.get('location').startswith(bundle_url)


def test_snippets_cors_headers(snippets_request, bundle_request):
for req in [snippets_request, bundle_request]:
assert req.headers.get('access-control-allow-origin') == '*'


def test_caching(snippets_request, bundle_request):
for req in [snippets_request, bundle_request]:
assert req.headers.get('x-cache-info', 'caching')
# Allow time for cache to save.
time.sleep(1)
new_req = requests.get(req.url, allow_redirects=False)
assert req.headers.get('x-cache-info', 'cached')


def test_snippets_stats_cors_headers(stats_request):
# See bug 965278
assert stats_request.headers.get('access-control-allow-origin') == 'null'


def test_snippets_stats(stats_request):
assert stats_request.status_code == 200


def test_bundle_contents(bundle_request):
assert bundle_request.content.startswith('<div class="snippet_set" id="snippet_set"')
assert bundle_request.content.endswith('</script></div>')

0 comments on commit 85e7e21

Please sign in to comment.