Skip to content
This repository has been archived by the owner on Jan 28, 2020. It is now read-only.

Commit

Permalink
Merge branch 'rc/0.13.0' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
pwilkins committed Nov 2, 2015
2 parents 5955f9e + af50edf commit afef084
Show file tree
Hide file tree
Showing 26 changed files with 1,714 additions and 670 deletions.
13 changes: 13 additions & 0 deletions RELEASE.rst
@@ -1,6 +1,19 @@
Release Notes
-------------

Version 0.13.0
==============

- Refactored listing code for testing.
- Implemented lazy loading for resource tab.
- Added custom slugify function to allow any name for Repo, Vocab, Term.
- Fixed index mapping of terms and vocabularies.
- Set Elasticsearch log level higher during testing.
- Set Spinner `zIndex` to 0 to not have it float above everything else.
- Added loader on save.
- Removed unused functions.
- Fixed link click behavior for term edit and delete.

Version 0.12.0
==============

Expand Down
37 changes: 37 additions & 0 deletions learningresources/migrations/0018_fill_empty_slugs.py
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
from django.db.models import F

from rest.util import default_slugify

# pylint: skip-file


def backfill_empty_slugs(apps, schema_editor):
"""
Finds all the objects in the Repository
that do not have a slug and change the name;
this will automatically create a new slug.
"""
Repository = apps.get_model("learningresources", "Repository")

for repo in Repository.objects.filter(slug=''):
repo.slug = default_slugify(
repo.name,
Repository._meta.model_name,
lambda slug: Repository.objects.filter(slug=slug).exists()
)
repo.save()


class Migration(migrations.Migration):

dependencies = [
('learningresources', '0017_learningresource_missing_title_update'),
]

operations = [
migrations.RunPython(backfill_empty_slugs)
]
13 changes: 6 additions & 7 deletions learningresources/models.py
Expand Up @@ -11,11 +11,11 @@
from django.db import models
from django.db import transaction
from django.contrib.auth.models import User
from django.utils.text import slugify
from django.utils.encoding import python_2_unicode_compatible
from django.shortcuts import get_object_or_404

from audit.models import BaseModel
from rest.util import default_slugify
from roles.api import roles_update_repo
from roles.permissions import RepoPermission
from lore.settings import LORE_PREVIEW_BASE_URL
Expand Down Expand Up @@ -171,12 +171,11 @@ def save(self, *args, **kwargs):
if self.id is not None:
is_update = True
old_slug = get_object_or_404(Repository, id=self.id).slug
slug = slugify(self.name)
count = 1
while Repository.objects.filter(slug=slug).exists():
slug = "{0}{1}".format(slugify(self.name), count)
count += 1
self.slug = slug
self.slug = default_slugify(
self.name,
Repository._meta.model_name,
lambda slug: Repository.objects.filter(slug=slug).exists()
)
# check if it's necessary to initialize the permissions
new_repository = super(Repository, self).save(*args, **kwargs)
if is_update:
Expand Down
14 changes: 14 additions & 0 deletions learningresources/tests/test_models.py
Expand Up @@ -111,6 +111,20 @@ def test_repo_slug(self):
self.assertEqual(repo.name, "repo name")
self.assertEqual(repo.slug, "repo-name")

# using a weird name
repo.name = "&^%$"
repo.save()
self.assertEqual(repo.name, "&^%$")
self.assertEqual(repo.slug, "repository-slug")
# create a new repo with weird name
repo = Repository.objects.create(
name="****&&",
description="description",
created_by_id=self.user.id,
)
self.assertEqual(repo.name, "****&&")
self.assertEqual(repo.slug, "repository-slug1")

def test_static_asset_basepath(self):
"""Verify we are setting the path we expect"""
filename = 'asdf/asdf.txt'
Expand Down
5 changes: 3 additions & 2 deletions lore/settings.py
Expand Up @@ -15,7 +15,7 @@
from django.core.exceptions import ImproperlyConfigured
import yaml

VERSION = '0.12.0'
VERSION = '0.13.0'

CONFIG_PATHS = [
os.environ.get('LORE_CONFIG', ''),
Expand Down Expand Up @@ -277,6 +277,7 @@ def get_var(name, default):
# Logging configuration
LOG_LEVEL = get_var('LORE_LOG_LEVEL', 'DEBUG')
DJANGO_LOG_LEVEL = get_var('DJANGO_LOG_LEVEL', 'DEBUG')
ES_LOG_LEVEL = get_var('ES_LOG_LEVEL', 'INFO')

# For logging to a remote syslog host
LOG_HOST = get_var('LORE_LOG_HOST', 'localhost')
Expand Down Expand Up @@ -339,7 +340,7 @@ def get_var(name, default):
'level': 'INFO',
},
'elasticsearch': {
'level': 'INFO',
'level': ES_LOG_LEVEL,
},
},
}
Expand Down
43 changes: 43 additions & 0 deletions rest/tests/test_misc.py
Expand Up @@ -15,6 +15,7 @@
as_json,
)
from rest.pagination import LorePagination
from rest.util import default_slugify


class TestMisc(RESTTestCase):
Expand Down Expand Up @@ -105,3 +106,45 @@ def test_pagination(self):
LorePagination.max_page_size - 1,
LorePagination.max_page_size - 1
)

def test_default_slugify(self):
"""
Test for the default slugify function.
Since this function is generic, here we test the generic call
"""
# a normal string
self.assertEqual(
default_slugify(
'foo',
'bar',
lambda x: False
),
'foo'
)
# the normal string already exists
self.assertEqual(
default_slugify(
'foo',
'bar',
lambda x: x == 'foo'
),
'foo1'
)
# a string that gives an empty slug
self.assertEqual(
default_slugify(
'%^%$',
'bar',
lambda x: False
),
'bar-slug'
)
# the default slug already exists
self.assertEqual(
default_slugify(
'%^%$',
'bar',
lambda x: x == 'bar-slug'
),
'bar-slug1'
)
41 changes: 23 additions & 18 deletions rest/tests/test_search.py
Expand Up @@ -144,7 +144,7 @@ def test_num_queries(self):
Make sure we're not hitting the database for the search
more than necessary.
"""
with self.assertNumQueries(8):
with self.assertNumQueries(9):
self.get_results()

def test_sortby(self):
Expand Down Expand Up @@ -289,15 +289,15 @@ def test_facets(self):
term1_results = self.get_results(
selected_facets=["{v}_exact:{t}".format(
v=vocab_key,
t=term1.slug
t=term1.id
)]
)
self.assertEqual(1, term1_results['count'])
self.assert_result_equal(term1_results['results'][0], resource1)
term2_results = self.get_results(
selected_facets=["{v}_exact:{t}".format(
v=vocab_key,
t=term2.slug
t=term2.id
)]
)
self.assertEqual(1, term2_results['count'])
Expand Down Expand Up @@ -385,7 +385,7 @@ def test_facets(self):
# Facet count
facet_counts = self.get_results(
selected_facets=["{v}_exact:{t}".format(
v=vocab_key, t=term1.slug
v=vocab_key, t=term1.id
)]
)['facet_counts']
self.assertEqual(
Expand Down Expand Up @@ -439,7 +439,7 @@ def test_facets(self):
},
'values': [{
'count': 1,
'key': term1.slug,
'key': str(term1.id),
'label': term1.label
}]
}
Expand Down Expand Up @@ -492,14 +492,14 @@ def test_selected_facets(self):

selected_facets = self.get_results(
selected_facets=["{v}_exact:{t}".format(
v=vocab_key, t=term1.slug
v=vocab_key, t=term1.id
)]
)['selected_facets']
self.assertEqual(
selected_facets,
{
'{v}'.format(v=vocab_key): {'{t}'.format(
t=term1.slug): True},
t=term1.id): True},
'course': {},
'resource_type': {},
'run': {}
Expand All @@ -510,7 +510,7 @@ def test_selected_facets(self):
# we should have no checkboxes that show up.
selected_facets = self.get_results(
selected_facets=["{v}_exact:{t}".format(
v=vocab_key, t=term1.slug
v=vocab_key, t=term1.id
), "run_exact:doesnt_exist"]
)['selected_facets']
self.assertEqual(
Expand Down Expand Up @@ -546,12 +546,17 @@ def test_empty_term_name(self):
vocab_dict['learning_resource_types'] = [
self.resource.learning_resource_type.name
]
vocab_slug = self.create_vocabulary(self.repo.slug, vocab_dict)['slug']
term_slug = self.create_term(self.repo.slug, vocab_slug, {
vocab_result = self.create_vocabulary(self.repo.slug, vocab_dict)
vocab_slug = vocab_result['slug']
vocab_id = vocab_result['id']
vocab_key = make_vocab_key(vocab_id)

term_result = self.create_term(self.repo.slug, vocab_slug, {
"label": "empty",
"weight": 4
})['slug']
vocab_key = make_vocab_key(vocab_slug)
})
term_id = term_result['id']
term_slug = term_result['slug']

# There is one resource and it is missing a term.
# Test that a missing search will get one result.
Expand All @@ -566,7 +571,7 @@ def test_empty_term_name(self):
results = self.get_results(
selected_facets=["{v}_exact:{t}".format(
v=vocab_key,
t=term_slug
t=term_id
)]
)
self.assertEqual(results['count'], 0)
Expand All @@ -592,7 +597,7 @@ def test_empty_term_name(self):
results = self.get_results(
selected_facets=["{v}_exact:{t}".format(
v=vocab_key,
t=term_slug
t=term_id
)]
)
self.assertEqual(results['count'], 1)
Expand Down Expand Up @@ -645,14 +650,14 @@ def test_name_collision(self):
self.assertEqual(
self.get_results(selected_facets=["{v}_exact:{t}".format(
v=vocab1_key,
t=term1.slug
t=term1.id
)])['count'],
0
)
self.assertEqual(
self.get_results(selected_facets=["{v}_exact:{t}".format(
v=vocab2_key,
t=term2.slug
t=term2.id
)])['count'],
1
)
Expand All @@ -663,14 +668,14 @@ def test_name_collision(self):
self.assertEqual(
self.get_results(selected_facets=["{v}_exact:{t}".format(
v=vocab1_key,
t=term1.slug
t=term1.id
)])['count'],
1
)
self.assertEqual(
self.get_results(selected_facets=["{v}_exact:{t}".format(
v=vocab2_key,
t=term2.slug
t=term2.id
)])['count'],
0
)
Expand Down

0 comments on commit afef084

Please sign in to comment.