Skip to content

Commit

Permalink
Add some new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vCra committed May 2, 2019
1 parent c6c13c1 commit 30aa3a3
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 9 deletions.
29 changes: 29 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,35 @@ In production, a few changes will need to be made.



Development
-----------

If you want to develop Programdom, then you should do the following, after ensuring that you have all of the development requirements installed

1. Create and activate a virtualenv, with Python >= 3.6

2. Install packages via ``pip install -r requirements/local.txt``

3. Run gulp - this will build all static files, and launch browsersync, which will refresh the browser on any static file changes

4. Run ``./manage.py runserver`` and ``./manage.py runworker judgebridge`` for the bridge server

5. To run tests, run ``pytest``


Development Requirements
------------------------
Python >=3.6
npm
docker
docker-compose
google-chrome and chromedriver (only for UI tests)

Related packages
----------------

You might also want to check out `judge0api <https://github.com/vCra/judge0api>`_

Licence
-------

Expand Down
2 changes: 1 addition & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
# https://docs.djangoproject.com/en/dev/ref/settings/#databases

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

# URLS
Expand Down
5 changes: 2 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ gulp.task('scripts', function () {
.pipe(gulp.dest(paths.js));
});


// Vendor Javascript minification
gulp.task('vendor-scripts', function () {
return gulp.src(paths.vendorsJs)
Expand Down Expand Up @@ -101,7 +100,7 @@ gulp.task('imgCompression', function () {
gulp.task('browserSync', function () {
browserSync.init(
[paths.css + "/*.css", paths.js + "*.js", paths.templates + '*.html'], {
proxy: "localhost:8000"
proxy: {target: "localhost:8000", ws:true}
});
});

Expand All @@ -119,5 +118,5 @@ gulp.task('build',

// Default task
gulp.task('default',
gulp.series('build', 'watch')
gulp.series('build', gulp.parallel('watch', 'browserSync'))
);
2 changes: 1 addition & 1 deletion requirements/local.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pytest
mypy
pytest-sugar
factory-boy
django-coverage-plugin
pytest-django
pytest-asyncio
pytest-cov
splinter[django]

Expand Down
11 changes: 11 additions & 0 deletions tests/ui/test_homepage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.urls import reverse

from tests.ui.testcases import AuthedSplinterTestCase

class TestHomepage(AuthedSplinterTestCase):

def test_homepage_elements(self):
url = f'{self.live_server_url}{reverse("home")}'
self.browser.visit(url)
assert len(self.browser.find_by_css(".card")) == 2

16 changes: 16 additions & 0 deletions tests/ui/test_workshop.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

from django.urls import reverse

from programdom.models import Workshop
Expand All @@ -6,6 +8,8 @@

class TestWorkshop(AuthedSplinterTestCase):

fixtures = ['workshops', "languages", "problems", "problem_tests"]

def test_create_workshop(self):
url = f'{self.live_server_url}{reverse("workshop_new")}'
self.browser.visit(url)
Expand All @@ -15,3 +19,15 @@ def test_create_workshop(self):

Workshop.objects.get(title="New Test Workshop").delete()

def test_present_workshop(self):
workshop = Workshop.objects.get(pk=1)
workshop.end()
url = f'{self.live_server_url}{reverse("workshop_present", kwargs={"pk":workshop.id})}'
self.browser.visit(url)
assert self.browser.find_by_tag("h3").first.value == workshop.title
assert self.browser.find_by_id("btn_workshop_toggle").first.value == "Begin Workshop"
self.browser.find_by_id("btn_workshop_toggle").first.click()
time.sleep(500)
workshop = Workshop.objects.get(pk=1)

assert self.browser.find_by_css(".workshop_code").first.value == workshop.code
9 changes: 5 additions & 4 deletions tests/ui/testcases.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from channels.testing import ChannelsLiveServerTestCase
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from splinter import Browser
from django.urls import reverse
Expand All @@ -6,11 +7,11 @@
from tests.generators.user import AuthUserFactory


class AuthedSplinterTestCase(StaticLiveServerTestCase):
class AuthedSplinterTestCase(ChannelsLiveServerTestCase):


def setUp(self):
self.browser = Browser('chrome', headless=True)
self.browser = Browser('chrome', headless=False)

user = AuthUserFactory()
self.browser.visit(f'{self.live_server_url}{reverse("users:login")}')
Expand All @@ -22,12 +23,12 @@ def tearDown(self):
self.browser.quit()


class StudentSplinterTestCase(StaticLiveServerTestCase):
class StudentSplinterTestCase(ChannelsLiveServerTestCase):

fixtures = ['workshops', "languages", "problems", "problem_tests"]

def setUp(self):
self.browser = Browser('chrome', headless=True)
self.browser = Browser('chrome', headless=False)
self.browser.visit(f'{self.live_server_url}{reverse("workshop_auth")}')
self.workshop = Workshop.objects.get(pk=1)
self.workshop.start()
Expand Down

0 comments on commit 30aa3a3

Please sign in to comment.