Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #57 from mardiros/revert-56-master
Browse files Browse the repository at this point in the history
Revert "Fix case insensitivity matching of packages names"
  • Loading branch information
mardiros committed May 21, 2015
2 parents e71c37e + ca67624 commit 77c5988
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
15 changes: 9 additions & 6 deletions pyshop/models.py
Expand Up @@ -22,7 +22,7 @@

from sqlalchemy import (Table, Column, ForeignKey, Index,
Integer, Boolean, Unicode, UnicodeText,
DateTime, Enum, func)
DateTime, Enum)
from sqlalchemy.orm import relationship, synonym, backref
from sqlalchemy.sql.expression import func, or_, and_
from sqlalchemy.ext.declarative import declared_attr
Expand Down Expand Up @@ -517,13 +517,16 @@ def by_name(cls, session, name):
:return: package instance
:rtype: :class:`pyshop.models.Package`
"""
name = name.lower()
pkg = cls.first(session, where=(func.lower(cls.name).like(name),))
# XXX the field "name" should be created with a
# case insensitive collation.
pkg = cls.first(session, where=(cls.name.like(name),))
if not pkg:
# XXX _ is a LIKE operator, backslash it
name = name.replace(u'-', u'\\_')
name = name.replace(u'-', u'_').upper()
pkg = cls.first(session,
where=(func.lower(cls.name).like(name),))
where=(cls.name.like(name),))
# XXX _ is a like operator
if pkg and pkg.name.upper().replace(u'-', u'_') != name:
pkg = None
return pkg

@classmethod
Expand Down
4 changes: 0 additions & 4 deletions pyshop/tests/case.py
Expand Up @@ -20,10 +20,6 @@ class ModelTestCase(TestCase):
def setUp(self):
transaction.begin()
self.session = DBSession()
# With SQLite3 - used for tests - 'x' LIKE 'X' returns true which is
# not the case of, for instance, PostgreSQL. Disabling this behaviour
# makes tests more realistic.
self.session.execute('PRAGMA case_sensitive_like = ON')

def tearDown(self):
transaction.commit()
Expand Down
6 changes: 0 additions & 6 deletions pyshop/tests/test_models.py
Expand Up @@ -89,12 +89,6 @@ def test_by_name(self):
self.assertEqual(pkg.id, 1)
self.assertEqual(pkg.name, u'mirrored_package1')

# Test case insensitivity
pkg = Package.by_name(self.session, u'MirRored_pAckaGe1')
self.assertIsInstance(pkg, Package)
self.assertEqual(pkg.id, 1)
self.assertEqual(pkg.name, u'mirrored_package1')

def test_by_owner(self):
from pyshop.models import Package
pkges = Package.by_owner(self.session, u'johndo')
Expand Down

0 comments on commit 77c5988

Please sign in to comment.