Commit ee6cd31d by Fred Smith Committed by GitHub

Merge pull request #52 from edx/derf/Dockerize_tests

Dockerize tests
parents d769550d a51c0af4
...@@ -8,3 +8,6 @@ coverage/ ...@@ -8,3 +8,6 @@ coverage/
# Sqlite Database # Sqlite Database
*.db *.db
#vim
*.swp
language: python language: python
python: 2.7
sudo: false
install: python:
- scripts/travis/install.sh - "3.5"
- scripts/travis/setup.sh
- pip install -r requirements/test.txt services:
- git fetch origin master:refs/remotes/origin/master # https://github.com/edx/diff-cover#troubleshooting - docker
- pip install coveralls
sudo: required
before_install:
- make travis_up
script: script:
- make validate - make travis_test
after_success: after_success:
- coveralls - pip install -U codecov
- docker exec notes /edx/app/notes/notes/.travis/run_coverage.sh
env: - codecov
- ESVER=-
- ESVER=0.90.11
- ESVER=1.4.2
version: "2"
services:
db:
image: mysql:5.6
container_name: db
command: mysqld --character-set-server=utf8 --collation-server=utf8_general_ci
environment:
MYSQL_ROOT_PASSWORD: ""
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
MYSQL_USER: "notes001"
MYSQL_PASSWORD: "secret"
MYSQL_DATABASE: "edx_notes_api"
es:
image: edxops/elasticsearch:0.9.13
container_name: es
notes:
# Uncomment this line to use the official course-discovery base image
image: edxops/notes:latest
# Uncomment the next two lines to build from a local configuration repo
# build: ../configuration/docker/build/discovery/
container_name: edx_notes_api
volumes:
- ..:/edx/app/edx_notes_api/edx_notes_api
command: tail -f /dev/null
depends_on:
- "db"
- "es"
environment:
CONN_MAX_AGE: 60
DB_ENGINE: "django.db.backends.mysql"
DB_HOST: "db"
DB_NAME: "edx_notes_api"
DB_PASSWORD: "secret"
DB_PORT: "3306"
DB_USER: "notes001"
ENABLE_DJANGO_TOOLBAR: 1
ELASTICSEARCH_URL: "http://es:9200"
.PHONY: travis_down travis_start travis_stop travis_test travis_up
travis_up: ## Create containers used to run tests on Travis CI
docker-compose -f .travis/docker-compose-travis.yml up -d
travis_start: ## Start containers stopped by `travis_stop`
docker-compose -f .travis/docker-compose-travis.yml start
travis_test: ## Run tests on Docker containers, as on Travis CI
docker exec -it edx_notes_api env TERM=$(TERM) /edx/app/edx_notes_api/edx_notes_api/.travis/run_tests.sh
travis_stop: ## Stop running containers created by `travis_up` without removing them
docker-compose -f .travis/docker-compose-travis.yml stop
travis_down: ## Stop and remove containers and other resources created by `travis_up`
docker-compose -f .travis/docker-compose-travis.yml down
#!/bin/bash -xe
. /edx/app/edx_notes_api/venvs/edx_notes_api/bin/activate
cd /edx/app/edx_notes_api/edx_notes_api
make validate
PACKAGES = notesserver notesapi PACKAGES = notesserver notesapi
.PHONY: requirements .PHONY: requirements
validate: test.requirements test coverage include .travis/docker.mk
ifeq ($(ESVER),-) validate: test.requirements test
test_settings = notesserver.settings.test_es_disabled
else
test_settings = notesserver.settings.test
endif
test: clean test: clean
./manage.py test --settings=$(test_settings) --with-coverage --with-ignore-docstrings \ ./manage.py test --settings=notesserver.settings.test --with-coverage --with-ignore-docstrings \
--exclude-dir=notesserver/settings --cover-inclusive --cover-branches \ --exclude-dir=notesserver/settings --cover-inclusive --cover-branches \
--cover-html --cover-html-dir=build/coverage/html/ \ --cover-html --cover-html-dir=build/coverage/html/ \
--cover-xml --cover-xml-file=build/coverage/coverage.xml --verbosity=2 \ --cover-xml --cover-xml-file=build/coverage/coverage.xml --verbosity=2 \
......
...@@ -654,7 +654,7 @@ class AnnotationSearchViewTests(BaseAnnotationViewTests): ...@@ -654,7 +654,7 @@ class AnnotationSearchViewTests(BaseAnnotationViewTests):
def test_search(self): def test_search(self):
""" """
Tests for search method. Tests for search method with case insensitivity for text param.
""" """
self._create_annotation(text=u'First one', tags=[]) self._create_annotation(text=u'First one', tags=[])
self._create_annotation(text=u'Second note', tags=[u'tag1', u'tag2']) self._create_annotation(text=u'Second note', tags=[u'tag1', u'tag2'])
...@@ -669,16 +669,17 @@ class AnnotationSearchViewTests(BaseAnnotationViewTests): ...@@ -669,16 +669,17 @@ class AnnotationSearchViewTests(BaseAnnotationViewTests):
self.assertEqual(last_note, note) self.assertEqual(last_note, note)
self.assertEqual(results['total'], 3) self.assertEqual(results['total'], 3)
def search_and_verify(searchText, expectedText, expectedTags): def search_and_verify(search_text, expected_text, expected_tags):
""" Test the results from a specific text search operation """ """ Test the results from a specific text search operation """
results = self._get_search_results(text=searchText) results = self._get_search_results(text=search_text)
self.assertEqual(results['total'], 1) self.assertEqual(results['total'], 1)
self.assertEqual(len(results['rows']), 1) self.assertEqual(len(results['rows']), 1)
self.assertEqual(results['rows'][0]['text'], expectedText) self.assertEqual(results['rows'][0]['text'], expected_text)
self.assertEqual(results['rows'][0]['tags'], expectedTags) self.assertEqual(results['rows'][0]['tags'], expected_tags)
search_and_verify("First", "First one", []) search_and_verify(search_text="First", expected_text="First one", expected_tags=[])
search_and_verify("Second", "Second note", ["tag1", "tag2"]) search_and_verify(search_text="first", expected_text="First one", expected_tags=[])
search_and_verify(search_text="Second", expected_text="Second note", expected_tags=["tag1", "tag2"])
@ddt.data(True, False) @ddt.data(True, False)
def test_usage_id_search(self, is_es_disabled): def test_usage_id_search(self, is_es_disabled):
...@@ -859,12 +860,11 @@ class AnnotationSearchViewTests(BaseAnnotationViewTests): ...@@ -859,12 +860,11 @@ class AnnotationSearchViewTests(BaseAnnotationViewTests):
self.assertEqual(self._get_search_results(text=u"something")['total'], 1) self.assertEqual(self._get_search_results(text=u"something")['total'], 1)
self.assertEqual(self._get_search_results(text=u"totally different")['total'], 1) self.assertEqual(self._get_search_results(text=u"totally different")['total'], 1)
def test_search_course(self): def test_search_by_course_id(self):
""" """
Tests searching with course_id provided Tests searching with course_id provided
""" """
self._create_annotation(text=u'First one', course_id="u'edX/DemoX/Demo_Course'") self._create_annotation(text=u'First one', course_id="u'edX/DemoX/Demo_Course'")
self._create_annotation(text=u'Not shown', course_id="u'edx/demox/demo_course'") # wrong case
self._create_annotation(text=u'Second note', course_id="u'edX/DemoX/Demo_Course'") self._create_annotation(text=u'Second note', course_id="u'edX/DemoX/Demo_Course'")
self._create_annotation(text=u'Third note', course_id="b") self._create_annotation(text=u'Third note', course_id="b")
self._create_annotation(text=u'Fourth note', course_id="c") self._create_annotation(text=u'Fourth note', course_id="c")
......
...@@ -2,8 +2,13 @@ from .common import * ...@@ -2,8 +2,13 @@ from .common import *
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': os.environ.get('DB_ENGINE', 'django.db.backends.sqlite3'),
'NAME': 'default.db', 'NAME': os.environ.get('DB_NAME', 'default.db'),
'USER': os.environ.get('DB_USER', ''),
'PASSWORD': os.environ.get('DB_PASSWORD', ''),
'HOST': os.environ.get('DB_HOST', ''),
'PORT': os.environ.get('DB_PORT', ''),
'CONN_MAX_AGE': int(os.environ.get('CONN_MAX_AGE', 0))
} }
} }
...@@ -14,7 +19,7 @@ INSTALLED_APPS += ('django_nose',) ...@@ -14,7 +19,7 @@ INSTALLED_APPS += ('django_nose',)
HAYSTACK_CONNECTIONS = { HAYSTACK_CONNECTIONS = {
'default': { 'default': {
'ENGINE': 'notesserver.highlight.ElasticsearchSearchEngine', 'ENGINE': 'notesserver.highlight.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/', 'URL': os.environ.get('ELASTICSEARCH_URL', 'http://localhost:9200/'),
'INDEX_NAME': 'notes_index_test', 'INDEX_NAME': 'notes_index_test',
}, },
} }
......
#!/bin/bash
# Installs Elasticsearch
#
# Requires ESVER environment variable to be set.
set -e
if [[ $ESVER == "-" ]];
then
exit 0
fi
echo "Installing ElasticSearch $ESVER" >&2
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-$ESVER.tar.gz
tar xzvf elasticsearch-$ESVER.tar.gz
#!/bin/bash
# Runs Elasticsearch
#
# Requires ESVER environment variable to be set.
# cwd is the git repository root.
set -e
if [[ $ESVER == "-" ]];
then
exit 0
fi
echo "Starting ElasticSearch $ESVER" >&2
pushd elasticsearch-$ESVER
# Elasticsearch 0.90 daemonizes automatically, but 1.0+ requires
# a -d argument.
if [[ $ESVER == 0* ]];
then
./bin/elasticsearch
else
echo "launching with -d option." >&2
./bin/elasticsearch -d
pip install elasticsearch==1.3.0
fi
popd
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment