-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b48d58f
commit 973c4a7
Showing
25 changed files
with
923 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Python CircleCI 2.0 configuration file | ||
# | ||
# Check https://circleci.com/docs/2.0/language-python/ for more details | ||
# | ||
|
||
version: 2 | ||
workflows: | ||
version: 2 | ||
test: | ||
jobs: | ||
- test-3.6 | ||
- test-2.7 | ||
jobs: | ||
test-3.6: | ||
docker: | ||
# specify the version you desire here | ||
# use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers` | ||
- image: circleci/python:3.6.5 | ||
working_directory: ~/repo | ||
|
||
steps: | ||
- checkout | ||
|
||
# Download and cache dependencies | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "requirements/test.txt" }} | ||
# fallback to using the latest cache if no exact match is found | ||
- v1-dependencies- | ||
|
||
- run: | ||
name: activate virtualenv and install dependencies. | ||
command: | | ||
test -d venv || virtualenv -p python3 ./venv | ||
. venv/bin/activate | ||
pip install -r requirements/test.txt | ||
- save_cache: | ||
paths: | ||
- ./venv | ||
key: v1-dependencies-{{ checksum "requirements/test.txt" }} | ||
|
||
- run: | ||
name: Run tests | ||
command: | | ||
. venv/bin/activate | ||
make run-tests | ||
# Based on answer https://discuss.circleci.com/t/run-tests-on-multiple-versions-of-python/15462 | ||
test-2.7: | ||
docker: | ||
- image: circleci/python:2.7 | ||
working_directory: ~/repo27 | ||
|
||
steps: | ||
- checkout | ||
|
||
# Download and cache dependencies | ||
- restore_cache: | ||
keys: | ||
- v1-27-dependencies-{{ checksum "requirements/test.txt" }} | ||
# fallback to using the latest cache if no exact match is found | ||
- v1-27-dependencies- | ||
|
||
- run: | ||
name: activate virtualenv and install dependencies. | ||
command: | | ||
test -d venv || virtualenv ./venv | ||
. venv/bin/activate | ||
pip install -r requirements/test.txt | ||
- save_cache: | ||
paths: | ||
- ./venv | ||
key: v1-27-dependencies-{{ checksum "requirements/test.txt" }} | ||
|
||
- run: | ||
name: Run tests | ||
command: | | ||
. venv/bin/activate | ||
make run-tests |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Change Log | ||
========== | ||
|
||
.. | ||
All enhancements and patches to eox_hooks will be documented | ||
in this file. It adheres to the structure of http://keepachangelog.com/ , | ||
but in reStructuredText instead of Markdown (for ease of incorporation into | ||
Sphinx documentation and the PyPI description). | ||
This project adheres to Semantic Versioning (http://semver.org/). | ||
.. There should always be an "Unreleased" section for changes pending release. | ||
Unreleased | ||
---------- | ||
|
||
* | ||
|
||
[0.1.0] - 2020-07-08 | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include CHANGELOG.rst | ||
include LICENSE.txt | ||
include README.md | ||
include requirements/base.in | ||
recursive-include eox_hooks *.html *.png *.gif *js *.css *jpg *jpeg *svg *py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
############################################### | ||
# | ||
# EoxHooks commands. | ||
# | ||
############################################### | ||
|
||
# Define PIP_COMPILE_OPTS=-v to get more information during make upgrade. | ||
PIP_COMPILE = pip-compile --rebuild --upgrade $(PIP_COMPILE_OPTS) | ||
|
||
.DEFAULT_GOAL := help | ||
|
||
help: ## display this help message | ||
@echo "Please use \`make <target>' where <target> is one of" | ||
@grep '^[a-zA-Z]' $(MAKEFILE_LIST) | sort | awk -F ':.*?## ' 'NF==2 {printf "\033[36m %-25s\033[0m %s\n", $$1, $$2}' | ||
|
||
clean: ## delete most git-ignored files | ||
find . -name '__pycache__' -exec rm -rf {} + | ||
find . -name '*.pyc' -exec rm -f {} + | ||
find . -name '*.pyo' -exec rm -f {} + | ||
find . -name '*~' -exec rm -f {} + | ||
|
||
requirements: ## install environment requirements | ||
pip install -r requirements/base.txt | ||
|
||
upgrade: export CUSTOM_COMPILE_COMMAND=make upgrade | ||
upgrade: ## update the requirements/*.txt files with the latest packages satisfying requirements/*.in | ||
pip install -qr requirements/pip-tools.txt | ||
# Make sure to compile files after any other files they include! | ||
$(PIP_COMPILE) -o requirements/pip-tools.txt requirements/pip-tools.in | ||
$(PIP_COMPILE) -o requirements/base.txt requirements/base.in | ||
$(PIP_COMPILE) -o requirements/test.txt requirements/test.in | ||
|
||
quality: clean ## check coding style with pycodestyle and pylint | ||
pycodestyle ./eox_hooks | ||
pylint ./eox_hooks --rcfile=./setup.cfg | ||
isort --check-only --recursive --diff ./eox_hooks | ||
|
||
test-python: clean ## Run test suite. | ||
pip install -r requirements/test.txt --exists-action w | ||
coverage run --source ./eox_hooks manage.py test | ||
coverage report -m --fail-under=80 | ||
|
||
run-tests: test-python quality |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
""" | ||
Init module for eox_hooks. | ||
""" | ||
|
||
from __future__ import unicode_literals | ||
|
||
__version__ = '0.1.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
App configuration for eox_hooks. | ||
""" | ||
|
||
from __future__ import unicode_literals | ||
|
||
from django.apps import AppConfig | ||
|
||
|
||
class EoxHooksConfig(AppConfig): | ||
""" | ||
EoxHooks configuration. | ||
""" | ||
name = 'eox_hooks' | ||
verbose_name = 'EoxHooks' | ||
|
||
plugin_app = { | ||
'url_config': { | ||
'lms.djangoapp': { | ||
'namespace': 'eox-hooks', | ||
'regex': r'^eox-hooks/', | ||
'relative_path': 'urls', | ||
}, | ||
'cms.djangoapp': { | ||
'namespace': 'eox-hooks', | ||
'regex': r'^eox-hooks/', | ||
'relative_path': 'urls', | ||
} | ||
}, | ||
'settings_config': { | ||
'lms.djangoapp': { | ||
'common': {'relative_path': 'settings.common'}, | ||
'test': {'relative_path': 'settings.test'}, | ||
'production': {'relative_path': 'settings.production'}, | ||
}, | ||
'cms.djangoapp': { | ||
'common': {'relative_path': 'settings.common'}, | ||
'test': {'relative_path': 'settings.test'}, | ||
'production': {'relative_path': 'settings.production'}, | ||
}, | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
""" | ||
Common Django settings for eox_hooks project. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/1.11/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/1.11/ref/settings/ | ||
""" | ||
|
||
from __future__ import unicode_literals | ||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = 'secret-key' | ||
|
||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = [] | ||
|
||
ROOT_URLCONF = 'eox_hooks.urls' | ||
|
||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/1.11/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
USE_TZ = True | ||
|
||
|
||
def plugin_settings(settings): # pylint: disable=unused-argument | ||
""" | ||
Set of plugin settings used by the Open Edx platform. | ||
More info: https://github.com/edx/edx-platform/blob/master/openedx/core/djangoapps/plugins/README.rst | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
""" | ||
Production Django settings for eox_hooks project. | ||
""" | ||
|
||
from __future__ import unicode_literals | ||
|
||
|
||
def plugin_settings(settings): # pylint: disable=unused-argument | ||
""" | ||
Set of plugin settings used by the Open Edx platform. | ||
More info: https://github.com/edx/edx-platform/blob/master/openedx/core/djangoapps/plugins/README.rst | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
Test Django settings for eox_hooks project. | ||
""" | ||
|
||
from __future__ import unicode_literals | ||
|
||
from .common import * # pylint: disable=wildcard-import | ||
|
||
ALLOWED_HOSTS = ['*'] | ||
|
||
INSTALLED_APPS = [ | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'eox_hooks', | ||
] | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
# This key needs to be defined so that the check_apps_ready passes and the | ||
# AppRegistry is loaded | ||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': 'db.sqlite3', | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
"""This file contains all the test for the general views.py file. | ||
Classes: | ||
EOXInfoTestCase: Test info_view. | ||
""" | ||
from os.path import dirname, realpath | ||
from subprocess import CalledProcessError, check_output | ||
|
||
from django.test import TestCase | ||
from django.urls import reverse | ||
from mock import patch | ||
from rest_framework import status | ||
|
||
import eox_hooks | ||
from eox_hooks import views | ||
|
||
|
||
class EOXInfoTestCase(TestCase): | ||
"""Possible test's scenarios for info_view.""" | ||
|
||
def setUp(self): | ||
"""Setup common conditions for every test case""" | ||
self.url = reverse('eox-info') | ||
self.view_directory = dirname(realpath(views.__file__)) | ||
|
||
def test_view_info_accesible(self): | ||
""" | ||
This method tests the desired behavior of info_view when this | ||
does not raise any exception. | ||
Expected behavior: | ||
- Return expected content. | ||
- Status code 200. | ||
""" | ||
git_data = check_output( | ||
['git', 'rev-parse', 'HEAD'], | ||
cwd=self.view_directory, | ||
) | ||
expected_result = { | ||
'version': eox_hooks.__version__, | ||
'name': 'eox-hooks', | ||
'git': git_data.decode().rstrip('\r\n'), | ||
} | ||
|
||
response = self.client.get(self.url) | ||
|
||
content = response.json() | ||
self.assertEqual(expected_result, content) | ||
self.assertEqual(status.HTTP_200_OK, response.status_code) | ||
|
||
@patch('eox_hooks.views.check_output') | ||
def test_view_info_response_data(self, check_output_mock): | ||
""" | ||
This method tests the desired behavior of info_view when | ||
raise a CalledProcessError exception. | ||
Expected behavior: | ||
- check_output called once with the right values. | ||
- Return expected content. | ||
- Status code 200. | ||
""" | ||
check_output_mock.side_effect = CalledProcessError( | ||
cmd='test-error', | ||
returncode=0, | ||
) | ||
expected_result = { | ||
'version': eox_hooks.__version__, | ||
'name': 'eox-hooks', | ||
'git': '', | ||
} | ||
|
||
response = self.client.get(self.url) | ||
|
||
content = response.json() | ||
check_output_mock.assert_called_once_with( | ||
['git', 'rev-parse', 'HEAD'], | ||
cwd=self.view_directory, | ||
) | ||
self.assertEqual(expected_result, content) | ||
self.assertEqual(status.HTTP_200_OK, response.status_code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""eox_hooks URL Configuration | ||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
https://docs.djangoproject.com/en/1.11/topics/http/urls/ | ||
Examples: | ||
Function views | ||
1. Add an import: from my_app import views | ||
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') | ||
Class-based views | ||
1. Add an import: from other_app.views import Home | ||
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') | ||
Including another URLconf | ||
1. Import the include() function: from django.conf.urls import url, include | ||
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) | ||
""" | ||
from django.conf.urls import url | ||
|
||
from eox_hooks import views | ||
|
||
urlpatterns = [ | ||
url(r'^eox-info$', views.info_view, name='eox-info'), | ||
] |
Oops, something went wrong.