Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ __pycache__
*.pyc
*.swp
k8s/templates/
cloudbuild-*.yaml
cloudbuild-*.yaml
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

# Linting updates and fixes
a52e08e5c2031cecb97a03fbed49997756ebe01b
8ccaaa60efd1c07b220aefce5a307e4791345111
2 changes: 1 addition & 1 deletion .github/workflows/community-contribution-labeling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ jobs:
uses: learningequality/.github/.github/workflows/community-contribution-label.yml@main
secrets:
LE_BOT_APP_ID: ${{ secrets.LE_BOT_APP_ID }}
LE_BOT_PRIVATE_KEY: ${{ secrets.LE_BOT_PRIVATE_KEY }}
LE_BOT_PRIVATE_KEY: ${{ secrets.LE_BOT_PRIVATE_KEY }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Javascript Linting
name: Linting

on:
push:
Expand All @@ -7,6 +7,10 @@ on:
- hotfixes
- master
pull_request:
branches:
- unstable
- hotfixes
- master

jobs:
pre_job:
Expand All @@ -20,14 +24,17 @@ jobs:
uses: fkirc/skip-duplicate-actions@master
with:
github_token: ${{ github.token }}
paths: '["**.vue", "**.js", "pnpm-lock.yaml", ".github/workflows/frontendlint.yml"]'
test:
name: Frontend linting
paths_ignore: '["**.po", "**.json"]'
linting:
name: All file linting
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Use pnpm
uses: pnpm/action-setup@v4
- name: Use Node.js
Expand All @@ -39,8 +46,7 @@ jobs:
run: |
pnpm install --frozen-lockfile
pnpm rebuild node-sass
- name: Run tests
run: pnpm run lint-frontend:format
- uses: pre-commit/action@v3.0.1
- name: Run pre-commit-ci-lite
uses: pre-commit-ci/lite-action@v1.1.0
if: always()
96 changes: 80 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,91 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
- id: trailing-whitespace
- id: check-added-large-files
exclude: '^.+?\.ttf$'
- id: debug-statements
- id: end-of-file-fixer
- id: debug-statements
- id: end-of-file-fixer
exclude: '^.+?\.json.+?\.yml$'
- repo: https://github.com/PyCQA/flake8
- repo: https://github.com/PyCQA/flake8
rev: 7.1.2
hooks:
- id: flake8
- repo: https://github.com/asottile/reorder_python_imports
- id: flake8
additional_dependencies: [
'flake8-print==5.0.0'
]
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.14.0
hooks:
- id: reorder-python-imports
- id: reorder-python-imports
language_version: python3
- repo: local
- repo: local
hooks:
- id: frontend-lint
name: Linting of JS, Vue, SCSS and CSS files
description: This hook handles all frontend linting for Kolibri Studio
entry: pnpm run lint-frontend:format
language: system
files: \.(js|vue|scss|css)$
- id: frontend-lint
name: Linting of JS, Vue, SCSS and CSS files
description: This hook handles all frontend linting for Kolibri Studio
entry: pnpm run lint-frontend:format
language: system
files: \.(js|vue|scss|css)$
- repo: local
hooks:
- id: no-auto-migrations
name: no auto-named migrations
entry: We do not allow _auto_ in migration names. Please give the migration a telling name.
language: fail
files: .*/migrations/.*_auto_.*\.py$
exclude: (?x)^(
contentcuration/kolibri_content/migrations/0014_auto_20210603_1536.py|
contentcuration/kolibri_content/migrations/0023_auto_20250417_1516.py|
contentcuration/kolibri_content/migrations/0007_auto_20200613_0050.py|
contentcuration/kolibri_content/migrations/0004_auto_20180910_2342.py|
contentcuration/kolibri_content/migrations/0002_auto_20180327_1414.py|
contentcuration/kolibri_content/migrations/0022_auto_20240915_1414.py|
contentcuration/kolibri_content/migrations/0011_auto_20210504_1744.py|
contentcuration/kolibri_content/migrations/0010_auto_20210202_0604.py|
contentcuration/kolibri_content/migrations/0018_auto_20220224_2031.py|
contentcuration/kolibri_content/migrations/0019_auto_20230207_0116.py|
contentcuration/kolibri_content/migrations/0005_auto_20190424_1709.py|
contentcuration/kolibri_content/migrations/0006_auto_20191028_2325.py|
contentcuration/kolibri_content/migrations/0015_auto_20210707_1606.py|
contentcuration/kolibri_content/migrations/0013_auto_20210519_1759.py|
contentcuration/kolibri_content/migrations/0012_auto_20210511_1605.py|
contentcuration/kolibri_content/migrations/0021_auto_20240612_1847.py|
contentcuration/search/migrations/0002_auto_20201215_2110.py|
contentcuration/contentcuration/migrations/0001_squashed_0094_auto_20180910_2342.py|
contentcuration/contentcuration/migrations/0002_auto_20181220_1734.py|
contentcuration/contentcuration/migrations/0102_auto_20190904_1627.py|
contentcuration/contentcuration/migrations/0110_auto_20200511_2245.py|
contentcuration/contentcuration/migrations/0104_auto_20191028_2325.py|
contentcuration/contentcuration/migrations/0111_auto_20200513_2252.py|
contentcuration/contentcuration/migrations/0130_auto_20210706_2005.py|
contentcuration/contentcuration/migrations/0098_auto_20190424_1709.py|
contentcuration/contentcuration/migrations/0128_auto_20210511_1605.py|
contentcuration/contentcuration/migrations/0112_auto_20200613_0050.py|
contentcuration/contentcuration/migrations/0127_auto_20210504_1744.py|
contentcuration/contentcuration/migrations/0106_auto_20191113_0217.py|
contentcuration/contentcuration/migrations/0103_auto_20190905_0408.py|
contentcuration/contentcuration/migrations/0121_auto_20210305_2028.py|
contentcuration/contentcuration/migrations/0133_auto_20220124_2149.py|
contentcuration/contentcuration/migrations/0132_auto_20210708_0011.py|
contentcuration/contentcuration/migrations/0120_auto_20210128_1646.py|
contentcuration/contentcuration/migrations/0131_auto_20210707_2326.py|
contentcuration/contentcuration/migrations/0126_auto_20210219_2314.py|
contentcuration/contentcuration/migrations/0107_auto_20191115_2344.py|
contentcuration/contentcuration/migrations/0151_auto_20250417_1516.py|
contentcuration/contentcuration/migrations/0099_auto_20190715_2201.py|
contentcuration/contentcuration/migrations/0123_auto_20210407_0057.py|
contentcuration/contentcuration/migrations/0129_auto_20210519_2213.py|
contentcuration/contentcuration/migrations/0109_auto_20191202_1759.py|
contentcuration/kolibri_public/migrations/0004_auto_20240612_1847.py|
contentcuration/kolibri_public/migrations/0006_auto_20250417_1516.py|
)$
# Always keep black as the final hook so it reformats any other reformatting.
- repo: https://github.com/python/black
rev: 20.8b1
hooks:
- id: black
additional_dependencies: [
'click==8.0.4'
]
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

1 change: 0 additions & 1 deletion contentcuration/automation/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# from django.contrib import admin

# Register your models here.
4 changes: 2 additions & 2 deletions contentcuration/automation/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class AutomationConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'automation'
default_auto_field = "django.db.models.BigAutoField"
name = "automation"
68 changes: 42 additions & 26 deletions contentcuration/automation/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,59 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('kolibri_public', '0005_alter_localfile_extension'),
("kolibri_public", "0005_alter_localfile_extension"),
]

operations = [
migrations.CreateModel(
name='RecommendationsCache',
name="RecommendationsCache",
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('request_hash', models.CharField(max_length=32, null=True)),
('topic_id', models.UUIDField()),
('rank', models.IntegerField(default=0, null=True)),
('override_threshold', models.BooleanField(default=False)),
('timestamp', models.DateTimeField(auto_now_add=True)),
('channel', models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name='channel_recommendations',
to='contentcuration.channel')),
('contentnode', models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name='contentnode_recommendations',
to='kolibri_public.contentnode')),
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
("request_hash", models.CharField(max_length=32, null=True)),
("topic_id", models.UUIDField()),
("rank", models.IntegerField(default=0, null=True)),
("override_threshold", models.BooleanField(default=False)),
("timestamp", models.DateTimeField(auto_now_add=True)),
(
"channel",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="channel_recommendations",
to="contentcuration.channel",
),
),
(
"contentnode",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="contentnode_recommendations",
to="kolibri_public.contentnode",
),
),
],
),
migrations.AddIndex(
model_name='recommendationscache',
index=models.Index(fields=['request_hash'], name='request_hash_idx'),
model_name="recommendationscache",
index=models.Index(fields=["request_hash"], name="request_hash_idx"),
),
migrations.AddIndex(
model_name='recommendationscache',
index=models.Index(fields=['contentnode'], name='contentnode_idx'),
model_name="recommendationscache",
index=models.Index(fields=["contentnode"], name="contentnode_idx"),
),
migrations.AlterUniqueTogether(
name='recommendationscache',
unique_together={('request_hash', 'contentnode')},
name="recommendationscache",
unique_together={("request_hash", "contentnode")},
),
]
10 changes: 5 additions & 5 deletions contentcuration/automation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ class RecommendationsCache(models.Model):
ContentNode,
null=True,
blank=True,
related_name='contentnode_recommendations',
related_name="contentnode_recommendations",
on_delete=models.CASCADE,
)
channel = models.ForeignKey(
Channel,
null=True,
blank=True,
related_name='channel_recommendations',
related_name="channel_recommendations",
on_delete=models.CASCADE,
)
rank = models.IntegerField(default=0, null=True)
override_threshold = models.BooleanField(default=False)
timestamp = models.DateTimeField(auto_now_add=True)

class Meta:
unique_together = ('request_hash', 'contentnode')
unique_together = ("request_hash", "contentnode")
indexes = [
models.Index(fields=['request_hash'], name=REQUEST_HASH_INDEX_NAME),
models.Index(fields=['contentnode'], name=CONTENTNODE_INDEX_NAME),
models.Index(fields=["request_hash"], name=REQUEST_HASH_INDEX_NAME),
models.Index(fields=["contentnode"], name=CONTENTNODE_INDEX_NAME),
]
1 change: 0 additions & 1 deletion contentcuration/automation/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# from django.test import TestCase

# Create your tests here.
20 changes: 12 additions & 8 deletions contentcuration/automation/tests/appnexus/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,33 @@


def test_session_with_max_connection_age_request():
with patch.object(requests.Session, 'request') as mock_request:
with patch.object(requests.Session, "request") as mock_request:
session = SessionWithMaxConnectionAge()
session.request('GET', 'https://example.com')
session.request("GET", "https://example.com")
assert mock_request.call_count == 1


def test_session_with_max_connection_age_not_closing_connections():
with patch.object(requests.Session, 'close') as mock_close, patch.object(requests.Session, 'request') as mock_request:
with patch.object(requests.Session, "close") as mock_close, patch.object(
requests.Session, "request"
) as mock_request:
session = SessionWithMaxConnectionAge(60)
session.request('GET', 'https://example.com')
session.request("GET", "https://example.com")
time.sleep(0.1)
session.request('GET', 'https://example.com')
session.request("GET", "https://example.com")

assert mock_close.call_count == 0
assert mock_request.call_count == 2


def test_session_with_max_connection_age_closing_connections():
with patch.object(requests.Session, 'close') as mock_close, patch.object(requests.Session, 'request') as mock_request:
with patch.object(requests.Session, "close") as mock_close, patch.object(
requests.Session, "request"
) as mock_request:
session = SessionWithMaxConnectionAge(1)
session.request('GET', 'https://example.com')
session.request("GET", "https://example.com")
time.sleep(2)
session.request('GET', 'https://example.com')
session.request("GET", "https://example.com")

assert mock_close.call_count == 1
assert mock_request.call_count == 2
Expand Down
Loading