Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Travis CI with GitHub Actions #57

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Tests
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Chrome
uses: browser-actions/setup-chrome@v1
with:
chrome-version: 129
install-chromedriver: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run tests and collect coverage
run: coverage run runtests.py
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ django-publications

A Django app for managing scientific publications.

[![Build Status](https://travis-ci.org/lucastheis/django-publications.svg?branch=develop)](https://travis-ci.org/lucastheis/django-publications)
[![CI](https://github.com/lucastheis/django-publications/actions/workflows/ci.yaml/badge.svg)](https://github.com/lucastheis/django-publications/actions)
[![Coverage Status](https://coveralls.io/repos/github/lucastheis/django-publications/badge.svg)](https://coveralls.io/github/lucastheis/django-publications)

Screenshots
Expand Down
Empty file.
67 changes: 67 additions & 0 deletions publications/settings/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from pathlib import Path

SECRET_KEY = 'test#ca=(=^t8h1a*1ee65_%m$sr38vdd_)!riw9rs17we41no4l3yd'

BASE_DIR = Path(__file__).resolve().parent

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.staticfiles',
'django.contrib.messages',
'publications',
)

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}

MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'publications.tests.urls'

STATIC_URL = '/static/'
STATICFILES_DIRS = []
STATIC_ROOT = BASE_DIR / 'build' / 'static'

MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'build/media/' # Where user uploads live during development.

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages'
],
},
},
]

STORAGES = {
'default': {
'BACKEND': 'django.core.files.storage.FileSystemStorage',
'OPTIONS': {
'location': MEDIA_ROOT,
'base_url': MEDIA_URL,
},
},
'staticfiles': {
'BACKEND': 'django.contrib.staticfiles.storage.StaticFilesStorage',
},
}

4 changes: 2 additions & 2 deletions publications/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from tests import Tests
from tests_live import LiveTests
from .tests import Tests
from .tests_live import LiveTests
70 changes: 0 additions & 70 deletions publications/tests/__main__.py

This file was deleted.

1 change: 1 addition & 0 deletions publications/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-

from django.test import TestCase
from django.contrib.auth.models import User
from django.urls import reverse
Expand Down
38 changes: 25 additions & 13 deletions publications/tests/tests_live.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
# -*- coding: utf-8 -*-

from django.test import LiveServerTestCase
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.support.expected_conditions import presence_of_element_located
from selenium.webdriver.support.wait import WebDriverWait
from publications.tests import tests
from publications.models import Publication


class LiveTests(LiveServerTestCase):
fixtures = ['initial_data.json', 'test_data.json']
urls = 'publications.tests.urls'

@classmethod
def setUpClass(cls):
options = webdriver.firefox.options.Options()
options = webdriver.ChromeOptions()
options.add_argument('--headless')
cls.selenium = webdriver.Firefox(options=options)
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')

cls.selenium = webdriver.Chrome(options=options)
cls.wait = WebDriverWait(cls.selenium, timeout=5)

super(LiveTests, cls).setUpClass()


Expand All @@ -26,24 +34,27 @@ def tearDownClass(cls):


def setUp(self):
User.objects.create_superuser('admin', '[email protected]', 'admin')
get_user_model().objects.create_superuser('admin', '[email protected]', 'admin')

# login
self.selenium.get('{0}{1}'.format(self.live_server_url, '/admin/'))
username_input = self.selenium.find_element_by_name("username")
username_input = self.selenium.find_element(By.NAME, 'username')
username_input.send_keys('admin')
password_input = self.selenium.find_element_by_name("password")
password_input = self.selenium.find_element(By.NAME, 'password')
password_input.send_keys('admin')
self.selenium.find_element_by_xpath('//input[@value="Log in"]').click()
self.selenium.find_element(By.XPATH, '//input[@value="Log in"]').click()


def test_import_bibtex(self):
count = Publication.objects.count()

self.selenium.get('{0}{1}'.format(self.live_server_url, '/admin/publications/publication/import_bibtex/'))
bibliography_input = self.selenium.find_element_by_name("bibliography")
self.selenium.get(
'{0}{1}'.format(self.live_server_url, '/admin/publications/publication/import_bibtex/')
)
self.wait.until(presence_of_element_located((By.NAME, 'bibliography')))
bibliography_input = self.selenium.find_element(By.NAME, 'bibliography')
bibliography_input.send_keys(tests.TEST_BIBLIOGRAPHY)
self.selenium.find_element_by_xpath('//input[@value="Import"]').click()
self.selenium.find_element(By.XPATH, '//input[@value="Import"]').click()

self.assertEqual(Publication.objects.count() - count, tests.TEST_BIBLIOGRAPHY_COUNT)

Expand All @@ -52,5 +63,6 @@ def test_import_bibtex_button(self):
count = Publication.objects.count()

self.selenium.get('{0}{1}'.format(self.live_server_url, '/admin/publications/publication/'))
self.selenium.find_element_by_link_text('Import BibTex').click()
self.selenium.find_element_by_xpath('//input[@value="Import"]').click()
self.wait.until(presence_of_element_located((By.LINK_TEXT, 'Import BibTex')))
self.selenium.find_element(By.LINK_TEXT, 'Import BibTex').click()
self.selenium.find_element(By.XPATH, '//input[@value="Import"]').click()
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coverage==7.5.1
django==5.1.2
pillow==10.3.0
selenium==4.24.0
25 changes: 25 additions & 0 deletions runtests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python3

import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'publications.settings.test'

import django
from django.conf import settings
from django.test.utils import get_runner


def main():
django.setup()

TestRunner = get_runner(settings)
test_runner = TestRunner()

failures = test_runner.run_tests(['publications.tests'])

sys.exit(bool(failures))


if __name__ == '__main__':
main()
Loading