Skip to content
Browse files

Fixing tests to run; ensuring search tests load by reducing duplicate…

… keys
  • Loading branch information...
1 parent 0556bed commit 4259d3534b1be5396e3573a907d6ca7b07dae090 @davidjb committed Nov 30, 2012
Showing with 62 additions and 48 deletions.
  1. +17 −12 sunburnt/test_schema.py
  2. +45 −35 sunburnt/test_search.py
  3. +0 −1 sunburnt/test_sunburnt.py
View
29 sunburnt/test_schema.py
@@ -4,7 +4,11 @@
import datetime
import uuid
-import mx.DateTime
+try:
+ import mx.DateTime
+ HAS_MX_DATETIME = True
+except ImportError:
+ HAS_MX_DATETIME = False
import pytz
from .schema import solr_date, SolrSchema, SolrError, SolrUpdate, SolrDelete
@@ -29,14 +33,15 @@
datetime.datetime(2009, 07, 23, 0, 24, 34, tzinfo=pytz.utc)]
}
-samples_from_mxdatetimes = {
- "2009-07-23T03:24:34.000376Z":
- [mx.DateTime.DateTime(2009, 07, 23, 3, 24, 34.000376),
- datetime.datetime(2009, 07, 23, 3, 24, 34, 376, pytz.utc)],
- "2009-07-23T03:24:34Z":
- [mx.DateTime.DateTime(2009, 07, 23, 3, 24, 34),
- datetime.datetime(2009, 07, 23, 3, 24, 34, tzinfo=pytz.utc)],
- }
+if HAS_MX_DATETIME:
+ samples_from_mxdatetimes = {
+ "2009-07-23T03:24:34.000376Z":
+ [mx.DateTime.DateTime(2009, 07, 23, 3, 24, 34.000376),
+ datetime.datetime(2009, 07, 23, 3, 24, 34, 376, pytz.utc)],
+ "2009-07-23T03:24:34Z":
+ [mx.DateTime.DateTime(2009, 07, 23, 3, 24, 34),
+ datetime.datetime(2009, 07, 23, 3, 24, 34, tzinfo=pytz.utc)],
+ }
samples_from_strings = {
@@ -56,14 +61,14 @@ def check_solr_date_from_date(s, date, canonical_date):
def check_solr_date_from_string(s, date):
assert solr_date(s)._dt_obj == date
-
def test_solr_date_from_pydatetimes():
for k, v in samples_from_pydatetimes.items():
yield check_solr_date_from_date, k, v[0], v[1]
def test_solr_date_from_mxdatetimes():
- for k, v in samples_from_mxdatetimes.items():
- yield check_solr_date_from_date, k, v[0], v[1]
+ if HAS_MX_DATETIME:
+ for k, v in samples_from_mxdatetimes.items():
+ yield check_solr_date_from_date, k, v[0], v[1]
def test_solr_date_from_strings():
for k, v in samples_from_strings.items():
View
80 sunburnt/test_search.py
@@ -9,7 +9,11 @@
from lxml.builder import E
from lxml.etree import tostring
-import mx.DateTime
+try:
+ import mx.DateTime
+ HAS_MX_DATETIME = True
+except ImportError:
+ HAS_MX_DATETIME = False
from .schema import SolrSchema, SolrError
from .search import SolrSearch, MltSolrSearch, PaginateOptions, SortOptions, FieldLimitOptions, FacetOptions, HighlightOptions, MoreLikeThisOptions, params_from_dict
@@ -118,17 +122,6 @@ class MockInterface(object):
[("fq", u"hello\\ world"), ("q", "*:*")]),
),
- "query":(
- (["hello"], {},
- [("q", u"hello")]),
- (["hello"], {"int_field":3},
- [("q", u"hello AND int_field:3")]),
- (["hello", "world"], {},
- [("q", u"hello AND world")]),
- (["hello world"], {},
- {"q":u"\"hello world\""}),
- ),
-
"filter":(
(["hello"], {},
[("fq", u"hello"), ("q", "*:*")]),
@@ -141,47 +134,60 @@ class MockInterface(object):
),
"query":(
+ #Basic queries
+ (["hello"], {},
+ [("q", u"hello")]),
+ (["hello"], {"int_field":3},
+ [("q", u"hello AND int_field:3")]),
+ (["hello", "world"], {},
+ [("q", u"hello AND world")]),
+ (["hello world"], {},
+ [("q", u"hello\\ world")]),
+ #Test fields
+ # Boolean fields take any truth-y value
([], {"boolean_field":True},
- {"q":u"boolean_field:true"}),
+ [("q", u"boolean_field:true")]),
+ ([], {"boolean_field":'true'},
+ [("q", u"boolean_field:true")]),
+ ([], {"boolean_field":1},
+ [("q", u"boolean_field:true")]),
([], {"boolean_field":"false"},
- {"q":u"boolean_field:true"}), # boolean field takes any truth-y value
+ [("q", u"boolean_field:false")]),
([], {"boolean_field":0},
- {"q":u"boolean_field:false"}),
+ [("q", u"boolean_field:false")]),
+ ([], {"boolean_field":False},
+ [("q", u"boolean_field:false")]),
([], {"int_field":3},
- {"q":u"int_field:3"}),
+ [("q", u"int_field:3")]),
([], {"int_field":3.1}, # casting from float should work
- {"q":u"int_field:3"}),
+ [("q", u"int_field:3")]),
([], {"sint_field":3},
- {"q":u"sint_field:3"}),
+ [("q", u"sint_field:3")]),
([], {"sint_field":3.1}, # casting from float should work
- {"q":u"sint_field:3"}),
+ [("q", u"sint_field:3")]),
([], {"long_field":2**31},
- {"q":u"long_field:2147483648"}),
+ [("q", u"long_field:2147483648")]),
([], {"slong_field":2**31},
- {"q":u"slong_field:2147483648"}),
+ [("q", u"slong_field:2147483648")]),
([], {"float_field":3.0},
- {"q":u"float_field:3.0"}),
+ [("q", u"float_field:3.0")]),
([], {"float_field":3}, # casting from int should work
- {"q":u"float_field:3.0"}),
+ [("q", u"float_field:3.0")]),
([], {"sfloat_field":3.0},
- {"q":u"sfloat_field:3.0"}),
+ [("q", u"sfloat_field:3.0")]),
([], {"sfloat_field":3}, # casting from int should work
- {"q":u"sfloat_field:3.0"}),
+ [("q", u"sfloat_field:3.0")]),
([], {"double_field":3.0},
- {"q":u"double_field:3.0"}),
+ [("q", u"double_field:3.0")]),
([], {"double_field":3}, # casting from int should work
- {"q":u"double_field:3.0"}),
+ [("q", u"double_field:3.0")]),
([], {"sdouble_field":3.0},
- {"q":u"sdouble_field:3.0"}),
+ [("q", u"sdouble_field:3.0")]),
([], {"sdouble_field":3}, # casting from int should work
- {"q":u"sdouble_field:3.0"}),
+ [("q", u"sdouble_field:3.0")]),
([], {"date_field":datetime.datetime(2009, 1, 1)},
- {"q":u"date_field:2009-01-01T00\\:00\\:00Z"}),
- ([], {"date_field":mx.DateTime.DateTime(2009, 1, 1)},
- {"q":u"date_field:2009-01-01T00\\:00\\:00Z"}),
- ),
-
- "query":(
+ [("q", u"date_field:2009\\-01\\-01T00\\:00\\:00Z")]),
+ #Test ranges
([], {"int_field__any":True},
[("q", u"int_field:[* TO *]")]),
([], {"int_field__lt":3},
@@ -219,6 +225,10 @@ class MockInterface(object):
[("q", "string_field:abc\\*\\?\\?\\?")]),
),
}
+if HAS_MX_DATETIME:
+ good_query_data['query'] += \
+ ([], {"date_field":mx.DateTime.DateTime(2009, 1, 1)},
+ [("q", u"date_field:2009-01-01T00\\:00\\:00Z")])
def check_query_data(method, args, kwargs, output):
solr_search = SolrSearch(interface)
View
1 sunburnt/test_sunburnt.py
@@ -9,7 +9,6 @@
from lxml.builder import E
from lxml.etree import tostring
-import mx.DateTime
from .sunburnt import SolrInterface

0 comments on commit 4259d35

Please sign in to comment.
Something went wrong with that request. Please try again.