Skip to content

Commit

Permalink
Test the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vCra committed May 1, 2019
1 parent 6283128 commit 9c6ffea
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 133 deletions.
11 changes: 3 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ python:
- "3.7"

addons:
postgresql: "9.4"
chrome: stable
apt:
packages:
Expand All @@ -16,19 +15,15 @@ install:
- pip install -r requirements.txt

before_script:
- psql -c 'create database programdom_test;' -U postgres

- docker-compose -f supporting.yml up -d
- ln --symbolic /usr/lib/chromium-browser/chromedriver "${HOME}/bin/chromedriver"

- ./manage.py runworker judgebridge

- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build

script:
- coverage run -m pytest
- pytest --cov=programdom --cov-report xml:coverage.xml tests/

after_script:
- coverage xml
- ./cc-test-reporter after-build --id b99c3291b5f5f531ea098cdb806a1f0e9e7a45bcc59858dd18962ec3029300b9 --exit-code $TRAVIS_TEST_RESULT
- docker-compose -f supporting.yml down
75 changes: 74 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1 +1,74 @@
todo programdom readme
Programdom
===========

.. image:: https://travis-ci.com/vCra/Programdom.svg?token=fL2aJPJ1Aobzg5cofH7d&branch=master
:target: https://travis-ci.com/vCra/Programdom

.. image:: https://api.codeclimate.com/v1/badges/22c1c4868a13d298bea2/maintainability
:target: https://codeclimate.com/repos/5cb1f27f7ed2ee131c001905/maintainability
:alt: Maintainability

.. image:: https://api.codeclimate.com/v1/badges/22c1c4868a13d298bea2/test_coverage
:target: https://codeclimate.com/repos/5cb1f27f7ed2ee131c001905/test_coverage
:alt: Test Coverage

.. image:: https://img.shields.io/github/license/vCra/Programdom.svg
:target: https://github.com/vCra/Programdom/blob/master/LICENSE


Programdom is an application that lets lecturers test their students understanding of coding concepts. How does it work?
- A Lecturer creates a coding problem, with some skeleton code and test cases.
- The lecturer adds a problem to a workshop that they can present
- Students join the workshop via a code, and attempt to solve the problem, by changing the code
- Students get given feedback on what tests pass and fail
- Lectuers see results live as they are submitted

Under the hood, we are using Judge0 in order to evaluate each submission.

Usage
-----

If you want to run Programdom locally, then great! All you need to do is the following:

1. Ensure you have docker and docker-compose installed and usable

2. Run ``docker-compose -f prod.yml up``

3. Wait for the image to build, and then access the instance at localhost:80

In order to actually use the system, they are some "first steps" that should be run

1. Create a super user - ``docker-compose -f prod.yml run python manage.py createsuperuser`` - answer the prompts for
your username and password

2. Import default programming languages. While languages can be created manually in Django Admin (accessible at ``/admin``), it's
normally easier to import the default ones. Run ``docker-compose -f prod.yml run python manage.py``


Usage in production
-------------------

In production, a few changes will need to be made.

1. Add your SSL keys to the nginx config file, which is in ``compose/nginx.conf``. At the same time, change
``server_name`` to the hostname of your server.

2. Create a Security Key - This can be done by changing the ``SECRET_KEY`` property in ``.envs/.prod/.django``

3. Create a secure username and password for postgres in ``.envs/.prod/.postgres``

4. Create a new secret and access key for minio in ``.envs/.prod/.minio``

5. Uncomment all of the security lines in ``config/settings/production.py``



Licence
-------

This software is released under the MIT License

Authors
-------

`programdom` was written by `Aaron Walker <[email protected]>`_.
2 changes: 1 addition & 1 deletion config/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# ------------------------------------------------------------------------------

DATABASES = {
'default': env.db('DATABASE_URL', 'postgresql://postgres@localhost:5432/programdom_test'),
'default': env.db('DATABASE_URL', 'postgresql://postgres:postgrespassword@localhost:5432/programdom_test'),
}

CHANNEL_LAYERS = {
Expand Down
1 change: 1 addition & 0 deletions gulpfile.prod.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
////////////////////////////////
//Setup//
// This gulp file should be used in production, as it does not watch files, or start browser-sync
////////////////////////////////

// Plugins
Expand Down
6 changes: 0 additions & 6 deletions locale/README.rst

This file was deleted.

46 changes: 27 additions & 19 deletions local.yml → prod.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'

volumes:
local_postgres_data: {}
prod_postgres_data: {}
static_files: {}
buckets: {}

Expand All @@ -18,64 +18,70 @@ services:
volumes:
- static_files:/static
env_file:
- ./.envs/.local/.django
- ./.envs/.local/.postgres
- ./.envs/.local/.redis
- ./.envs/.local/.minio
- .envs/.prod/.django
- .envs/.prod/.postgres
- .envs/.prod/.redis
- .envs/.prod/.minio
expose:
- "8000"
command: /start
restart: on-failure

bridge:
build:
context: .
dockerfile: ./compose/local/django/Dockerfile
env_file:
- ./.envs/.local/.django
- ./.envs/.local/.postgres
- ./.envs/.local/.redis
- ./.envs/.local/.minio
- .envs/.prod/.django
- .envs/.prod/.postgres
- .envs/.prod/.redis
- .envs/.prod/.minio
depends_on:
- redis
- postgres
- judgezero
command: python manage.py runworker judgebridge
restart: on-failure

postgres:
image:
postgres:11-alpine
volumes:
- local_postgres_data:/var/lib/postgresql/data
- prod_postgres_data:/var/lib/postgresql/data
expose:
- "5432"
env_file:
- .envs/.local/.postgres
- .envs/.prod/.postgres
restart: on-failure

judgezero:
image: judge0/api
expose:
- "3000"
env_file:
- .envs/.local/.judge0
- .envs/.local/.redis
- .envs/.local/.postgres
- .envs/.prod/.judge0
- .envs/.prod/.redis
- .envs/.prod/.postgres
restart: on-failure

worker:
image: judge0/api
env_file:
- .envs/.local/.judge0
- .envs/.local/.redis
- .envs/.local/.postgres
- .envs/.prod/.judge0
- .envs/.prod/.redis
- .envs/.prod/.postgres
command: bash -c "while true; do rails resque:work; done"
privileged: true
restart: always
restart: on-failure



redis:
image:
redis:5-alpine
expose:
- "6379"
restart: on-failure

rev-proxy:
image: nginx
Expand All @@ -86,6 +92,7 @@ services:
- ./compose/nginx.conf:/etc/nginx/nginx.conf
ports:
- 80:80
restart: on-failure

minio:
image: minio/minio:RELEASE.2019-04-23T23-50-36Z
Expand All @@ -94,5 +101,6 @@ services:
expose:
- "9000"
env_file:
- .envs/.local/.minio
- .envs/.prod/.minio
command: server /data
restart: on-failure
55 changes: 0 additions & 55 deletions production.yml

This file was deleted.

7 changes: 7 additions & 0 deletions programdom/middleware/login_required.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@


class LoginRequiredMiddleware:
"""
Middlewear to ensure that the current "user" is allowed to complete the current request
The system currently checks if the user is authenticated or if they have a "current_workshop_id"
Unauthenticated/unauthorised users are sent to the login page
"""
def __init__(self, get_response):
self.get_response = get_response
self.login_url = settings.LOGIN_URL
Expand Down
3 changes: 0 additions & 3 deletions programdom/templates/programdom/pages/problem.html

This file was deleted.

48 changes: 24 additions & 24 deletions programdom/templates/programdom/problem/problem_detail_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h4 class="card-title">Problem Details</h4>
<h4 class="card-title">Problem Tests</h4>
</div>
<div class="col">
<a class="btn btn-success float-right" href="{% url "problem_test_new" object.id %}">New Test
<a class="btn btn-success float-right save-code" href="{% url "problem_test_new" object.id %}">New Test
<i class="fa fa-plus ml-1"></i></a>
</div>
</div>
Expand Down Expand Up @@ -63,7 +63,7 @@ <h4 class="card-title">Problem Tests</h4>
<div class="col-md-9">
<div class="container-fluid">
<div id="editor">{{ object.skeleton }}</div>
<button class="btn btn-success mt-2 float-right" id="btn-save-code">Save Code <i class="fa fa-save ml-1"></i></button>
<button class="btn btn-success mt-2 float-right save-code">Save Code <i class="fa fa-save ml-1"></i></button>
</div>
</div>
</div>
Expand All @@ -79,36 +79,36 @@ <h4 class="card-title">Problem Tests</h4>

<script>
var editor = ace.edit("editor");
ace.config.set('basePath', "https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.3/");

editor.session.setMode("ace/mode/{{ object.language.mode }}");
</script>
{% csrf_token %}
<script type="text/javascript">
// using jQuery
var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();
</script>
<script>

var save_code = function(e){
$.ajax({
url: '{% url "api:problem-list" %}{{ problem.id }}/',
dataType: 'text',
type: 'patch',
contentType: 'application/x-www-form-urlencoded',
data: {
"skeleton": editor.getValue()
},
success: function( data, textStatus, jQxhr ){
toastr.success("Problem Code Updated");
},
error: function( jqXhr, textStatus, errorThrown ){
toastr.error("Unable to update Code");
}
});
};

$(".save-code").click(save_code);
$("#submit-id-submit").click(save_code);

$("#btn-save-code").click(function(){


$.ajax({
url: '{% url "api:problem-list" %}{{ problem.id }}/',
dataType: 'text',
type: 'patch',
contentType: 'application/x-www-form-urlencoded',
data: {
"skeleton": editor.getValue()
},
success: function( data, textStatus, jQxhr ){
toastr.success("Problem Code Updated");
},
error: function( jqXhr, textStatus, errorThrown ){
toastr.error("Unable to update Code");
}
});
}
)
</script>
{% endblock javascript %}
{% block css %}
Expand Down
Loading

0 comments on commit 9c6ffea

Please sign in to comment.