Skip to content

Commit

Permalink
refactor common code, better requirement management (#1551)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwvolo authored Mar 1, 2024
1 parent b921b61 commit 87a03b8
Show file tree
Hide file tree
Showing 44 changed files with 10,124 additions and 1,634 deletions.
54 changes: 27 additions & 27 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
name: CI
name: Tests

on: [push]
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
tests:
timeout-minutes: 30
runs-on: ubuntu-latest

services:
postgres:
image: postgres:13
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
env:
POSTGRES_PASSWORD: postgres

Expand All @@ -24,32 +27,29 @@ jobs:
with:
fetch-depth: 1

- name: Setup Python 3.8
uses: actions/setup-python@v4
- name: Setup Python and install dependencies
uses: actions/setup-python@v5
with:
python-version: 3.8
cache: 'pip'
python-version-file: '.python-version'
cache-dependency-path: requirements/test.txt
- run: pip install -r requirements/test.txt

- uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements/test.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements/test.txt
if: steps.cache.outputs.cache-hit != 'true'

- name: Run Django tests
run: python manage.py test --settings=openstax.settings.test
- name: Check migrations
run: python manage.py makemigrations --check

- name: Run tests and generate coverage reports
run: coverage run --source '.' manage.py test --settings=openstax.settings.test
env:
SALESFORCE_USERNAME: ${{ secrets.SALESFORCE_USERNAME }}
SALESFORCE_PASSWORD: ${{ secrets.SALESFORCE_PASSWORD }}
SALESFORCE_SECURITY_TOKEN: ${{ secrets.SALESFORCE_SECURITY_TOKEN }}
SOCIAL_AUTH_OPENSTAX_KEY: ${{ secrets.SOCIAL_AUTH_OPENSTAX_KEY }}
SOCIAL_AUTH_OPENSTAX_SECRET: ${{ secrets.SOCIAL_AUTH_OPENSTAX_SECRET }}
- uses: codecov/codecov-action@v3

- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: openstax/openstax-cms

5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/.vagrant
/wagtaildemo/settings/local.py
*/public
/public/static
/public/media
/static
Expand All @@ -14,7 +14,6 @@ openstax/settings/local.py
.venv
.DS_STORE
*.icloud

*.bk
admin_templates/templates/wagtailadmin/login.html*
.vscode/settings.json
.env
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.10.9
3.11
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![CI](https://github.com/openstax/openstax-cms/actions/workflows/tests.yml/badge.svg)](https://github.com/openstax/openstax-cms/actions/workflows/tests.yml)
[![OpenStax](https://img.shields.io/badge/OpenStax-Web-00A6C9?style=for-the-badge&logo=openstax&logoColor=white)](https://openstax.org)\
[![codecov](https://codecov.io/gh/openstax/openstax-cms/branch/main/graph/badge.svg?token=hHMb4KUGYC)](https://codecov.io/gh/openstax/openstax-cms)

[![CI](https://github.com/openstax/openstax-cms/actions/workflows/tests.yml/badge.svg)](https://github.com/openstax/openstax-cms/actions/workflows/tests.yml)
![](https://codebuild.us-west-2.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiek9QM293aWxTZkdOZ0kwb00yTlZPaFJqck53RENqMFFaWGNGS2xQZFpEbThaOENrWnFUQmd2cFZIdHJoUkNFekN6Z3ozc2d3MFh6dlBaT29nNVcrM2RBPSIsIml2UGFyYW1ldGVyU3BlYyI6IklqT2p6T3NwT1pHVVVKRU0iLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=main)
![](https://img.shields.io/github/v/tag/openstax/openstax-cms?label=latest%20tag)

Expand All @@ -16,15 +16,15 @@ Dependencies
```bash
brew install postgresql
```
* [Python](https://www.python.org/) (≥ 3.10)
* [PIP](https://github.com/pypa/pip) (≥ 8.0.0)
* [Python](https://www.python.org/) (≥ 3.11)
* [PIP](https://github.com/pypa/pip)
```bash
brew install python3
```

Installation
=======================
Verify you have Python ≥ 3.6 installed:
Verify you have Python ≥ 3.11 installed:
```bash
python --version
python3 --version
Expand Down Expand Up @@ -54,7 +54,7 @@ After all the modules in requirements are installed, run the migration script:
```bash
python3 manage.py migrate
```
Now, create a super user. Run the following command and then proceed with the instructions:
Now, create a superuser. Run the following command and then proceed with the instructions:

```bash
python3 manage.py createsuperuser
Expand All @@ -69,14 +69,16 @@ python3 manage.py runserver
Testing
=======================
To test OpenStax CMS on a local device, you need to overwrite some settings. This can be streamlined by introducing `local.py` in `openstax/settings/`. Any changes on or additions to `local.py` will overwrite settings. Make copy of `local.py.example` and rename it to `local.py`:
Alternatively, and maybe more conveniently, use a `.env` file in the project root to set environmental variables.

```bash
cd openstax/settings/
cp local.py.example local.py
```

Start the server:
Run the tests:
```bash
python3 manage.py test --liveserver=localhost:8001 --settings=openstax.settings.dev
python3 manage.py test --settings=openstax.settings.test
```

SQLite Support
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 5.0.2 on 2024-02-27 15:58

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("books", "0153_book_polish_site_link"),
]

operations = [
migrations.AlterField(
model_name="book",
name="salesforce_abbreviation",
field=models.CharField(
blank=True,
help_text="This should match the Books Name from Salesforce.",
max_length=255,
null=True,
verbose_name="Subject Book Name",
),
),
migrations.AlterField(
model_name="book",
name="salesforce_name",
field=models.CharField(
blank=True,
help_text="This is the name shown on interest/adoption forms and used in Partner filtering. The website only shows unique values from here, so it is possible to combine books for forms",
max_length=255,
null=True,
verbose_name="Name displayed on website forms",
),
),
]
2 changes: 1 addition & 1 deletion books/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def setUpTestData(cls):
# add book index to homepage
homepage.add_child(instance=book_index)

test_image = SimpleUploadedFile(name='openstax.png', content=open("oxauth/static/images/openstax.png", 'rb').read())
test_image = SimpleUploadedFile(name='openstax.png', content=open("pages/static/images/openstax.png", 'rb').read())
cls.test_doc = Document.objects.create(title='Test Doc', file=test_image)

cls.book_index = Page.objects.get(id=book_index.id)
Expand Down
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ parsers:
comment: false
ignore:
- "*tests.py"
- 'healthcheck/*'
- 'manage.py'
- '*/migrations/*'
- '*/settings/*'
- '*settings.py'
- '*wsgi.py'
Empty file removed errata/management/__init__.py
Empty file.
Empty file.
12 changes: 0 additions & 12 deletions errata/management/commands/migrate_errata_openstax_books.py

This file was deleted.

39 changes: 0 additions & 39 deletions errata/management/commands/migrate_errata_user_accounts.py

This file was deleted.

29 changes: 0 additions & 29 deletions errata/management/commands/populate_errata_accounts_data.py

This file was deleted.

2 changes: 1 addition & 1 deletion errata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from books.models import Book
from django.conf import settings
from oxauth.functions import get_user_info
from openstax_accounts.functions import get_user_info
from global_settings.functions import invalidate_cloudfront_caches


Expand Down
2 changes: 1 addition & 1 deletion errata/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setUp(self):
# add book index to homepage
homepage.add_child(instance=book_index)
# create book (finally! needed for Errata reports)
test_image = SimpleUploadedFile(name='openstax.png', content=open("oxauth/static/images/openstax.png", 'rb').read())
test_image = SimpleUploadedFile(name='openstax.png', content=open("pages/static/images/openstax.png", 'rb').read())
test_doc = Document.objects.create(title='Test Doc', file=test_image)
book = Book(cnx_id='d50f6e32-0fda-46ef-a362-9bd36ca7c97d',
title='University Physics',
Expand Down
4 changes: 1 addition & 3 deletions errata/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import django_filters
from django.http import HttpResponse
from django.db import models
from django.contrib.auth.decorators import permission_required
from rest_framework.renderers import JSONRenderer
from rest_framework.viewsets import ModelViewSet
from rest_framework.filters import OrderingFilter
Expand All @@ -10,7 +8,7 @@
from .models import Errata, ERRATA_STATUS
from .serializers import ErrataSerializer
from .forms import ErrataModelForm
from oxauth.functions import get_user_info
from openstax_accounts.functions import get_user_info


class JSONResponse(HttpResponse):
Expand Down
Loading

0 comments on commit 87a03b8

Please sign in to comment.