本文整理汇总了Python中seo_pysolr.Solr.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Solr.delete方法的具体用法?Python Solr.delete怎么用?Python Solr.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类seo_pysolr.Solr
的用法示例。
在下文中一共展示了Solr.delete方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clear_solr
# 需要导入模块: from seo_pysolr import Solr [as 别名]
# 或者: from seo_pysolr.Solr import delete [as 别名]
def clear_solr(buid):
"""Delete all jobs for a given business unit/job source."""
conn = Solr(settings.HAYSTACK_CONNECTIONS['default']['URL'])
hits = conn.search(q="*:*", rows=1, mlt="false", facet="false").hits
logging.info("BUID:%s - SOLR - Deleting all %s jobs" % (buid, hits))
conn.delete(q="buid:%s" % buid)
logging.info("BUID:%s - SOLR - All jobs deleted." % buid)
示例2: DirectSEOBase
# 需要导入模块: from seo_pysolr import Solr [as 别名]
# 或者: from seo_pysolr.Solr import delete [as 别名]
class DirectSEOBase(TestCase):
def setUp(self):
db_backend = settings.DATABASES['default']['ENGINE'].split('.')[-1]
# Set columns that are utf8 in production to utf8
if db_backend == 'mysql':
cursor = connections['default'].cursor()
cursor.execute("alter table seo_customfacet convert to character "
"set utf8 collate utf8_unicode_ci")
cursor.execute("alter table seo_seositefacet convert to character "
"set utf8 collate utf8_unicode_ci")
cursor.execute("alter table seo_company convert to character set "
"utf8 collate utf8_unicode_ci")
cursor.execute("alter table seo_queryredirect convert to character "
"set utf8 collate utf8_unicode_ci")
cursor.execute("alter table taggit_tag convert to character set "
"utf8 collate utf8_unicode_ci")
cursor.execute("alter table taggit_taggeditem convert to "
"character set "
"utf8 collate utf8_unicode_ci")
cursor.execute("alter table seo_seositeredirect convert to "
"character set utf8 collate utf8_unicode_ci")
cursor.execute("alter table django_redirect convert to "
"character set utf8 collate utf8_unicode_ci")
setattr(settings, 'ROOT_URLCONF', 'dseo_urls')
setattr(settings, "PROJECT", 'dseo')
clear_url_caches()
self.base_middleware_classes = settings.MIDDLEWARE_CLASSES
middleware_classes = self.base_middleware_classes + (
'wildcard.middleware.WildcardMiddleware',
'middleware.RedirectOverrideMiddleware')
setattr(settings, 'MIDDLEWARE_CLASSES', middleware_classes)
self.base_context_processors = settings.TEMPLATE_CONTEXT_PROCESSORS
context_processors = self.base_context_processors + (
"social_links.context_processors.social_links_context",
"seo.context_processors.site_config_context",
)
setattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS', context_processors)
context._standard_context_processors = None
self.conn = Solr('http://127.0.0.1:8983/solr/seo')
self.conn.delete(q="*:*")
cache.clear()
clear_url_caches()
setattr(settings, 'MEMOIZE', False)
def tearDown(self):
from django.conf import settings
from django.template import context
setattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS',
self.base_context_processors)
context._standard_context_processors = None
setattr(settings, 'MIDDLEWARE_CLASSES',
self.base_middleware_classes)
示例3: remove_expired_jobs
# 需要导入模块: from seo_pysolr import Solr [as 别名]
# 或者: from seo_pysolr.Solr import delete [as 别名]
def remove_expired_jobs(buid, active_jobs, upload_chunk_size=1024):
"""
Given a job source id and a list of active jobs for that job source,
Remove the jobs on solr that are not among the active jobs.
"""
conn = Solr(settings.HAYSTACK_CONNECTIONS['default']['URL'])
count = conn.search("*:*", fq="buid:%s" % buid, facet="false",
mlt="false").hits
old_jobs = conn.search("*:*", fq="buid:%s" % buid, facet="false",
rows=count, mlt="false").docs
active_ids = set(j['id'] for j in active_jobs)
old_ids = set(j['id'] for j in old_jobs)
expired = old_ids - active_ids
chunks = chunk(list(expired), upload_chunk_size)
for jobs in chunks:
query = "id:(%s)" % " OR ".join([str(x) for x in jobs])
conn.delete(q=query)
return expired
示例4: MyJobsBase
# 需要导入模块: from seo_pysolr import Solr [as 别名]
# 或者: from seo_pysolr.Solr import delete [as 别名]
class MyJobsBase(TestCase):
def setUp(self):
from django.conf import settings
setattr(settings, 'ROOT_URLCONF', 'myjobs_urls')
cache.clear()
clear_url_caches()
self.ms_solr = Solr('http://127.0.0.1:8983/solr/seo')
self.ms_solr.delete(q='*:*')
setattr(settings, "PROJECT", 'myjobs')
self.base_context_processors = settings.TEMPLATE_CONTEXT_PROCESSORS
context_processors = self.base_context_processors + (
'mymessages.context_processors.message_lists',
)
setattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS', context_processors)
setattr(settings, 'MEMOIZE', False)
def tearDown(self):
self.ms_solr.delete(q='*:*')
setattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS',
self.base_context_processors)
示例5: delete_by_guid
# 需要导入模块: from seo_pysolr import Solr [as 别名]
# 或者: from seo_pysolr.Solr import delete [as 别名]
def delete_by_guid(guids):
"""
Removes a jobs from solr by guid.
inputs:
:guids: A list of guids
outputs:
The number of jobs that were requested to be deleted. This may
be higher than the number of actual jobs deleted if a guid
passed in did not correspond to a job in solr.
"""
conn = Solr(settings.HAYSTACK_CONNECTIONS['default']['URL'])
if not guids:
return 0
num_guids = len(guids)
guids = chunk(guids)
for guid_group in guids:
delete_str = " OR ".join(guid_group)
conn.delete(q="guid: (%s)" % delete_str)
return num_guids
示例6: SiteTestCase
# 需要导入模块: from seo_pysolr import Solr [as 别名]
# 或者: from seo_pysolr.Solr import delete [as 别名]
class SiteTestCase(DirectSEOBase):
"""
We're adding these tests to ensure unicode jobs descriptions and titles
make it through the import process and work with high-level features.
We should use http requests wherever possible since it's difficult to
predict which modules will have issues with unicode.
"""
def setUp(self):
super(SiteTestCase, self).setUp()
self.conn = Solr('http://127.0.0.1:8983/solr/seo')
self.conn.delete(q="*:*")
self.businessunit = factories.BusinessUnitFactory(id=0)
self.buid = self.businessunit.id
self.filepath = os.path.join(import_jobs.DATA_DIR,
'dseo_feed_%s.xml' % self.buid)
SeoSite.objects.all().delete()
self.site = factories.SeoSiteFactory(id=1)
self.configuration = factories.ConfigurationFactory(status=2)
self.configuration.save()
self.site.configurations.clear()
self.site.configurations.add(self.configuration)
def tearDown(self):
super(SiteTestCase, self).tearDown()
self.conn.delete(q="*:*")
def test_unicode_title(self):
# Test imports
group = factories.GroupFactory()
self.site.group = group
self.site.business_units.add(self.businessunit)
self.site.save()
import_jobs.update_solr(self.buid, download=False, delete_feed=False,
data_dir='seo/tests/data/')
solr_jobs = self.conn.search("*:*")
resp = self.client.get('/')
self.assertEqual(resp.context['total_jobs_count'], solr_jobs.hits)
# test standard facets against Haystack query
standard_cf = factories.CustomFacetFactory.build(
# default facet will return both jobs
name="Keyword Facet",
group=group,
show_production=True)
standard_cf.save()
standard_cf.keyword.add(u'Ключевые')
standard_cf.save()
standard_site_facet = factories.SeoSiteFacetFactory(
seosite=self.site,
customfacet=standard_cf,
facet_type=factories.SeoSiteFacet.STANDARD)
standard_site_facet.save()
# test standard facets against Haystack query
standard_cf2 = factories.CustomFacetFactory.build(
# default facet will return both jobs
name='Country Facet',
country='United States',
group=group,
show_production=True)
standard_cf2.save()
standard_site_facet2 = factories.SeoSiteFacetFactory(
seosite=self.site,
customfacet=standard_cf2,
facet_type=factories.SeoSiteFacet.STANDARD)
standard_site_facet2.save()
resp = self.client.get('/keyword-facet/new-jobs/',
HTTP_HOST=self.site.domain, follow=True)
sqs = DESearchQuerySet().filter(text=u'Ключевые')
self.assertEqual(len(resp.context['default_jobs']), sqs.count())
for facet_widget in resp.context['widgets']:
# Ensure that no standard facet has more results than current
# search results
for count_tuple in facet_widget.items:
self.assertTrue(sqs.count() >= count_tuple[1])
# Test default site facets against PySolr query
from django.core.cache import cache
cache.clear()
default_cf = factories.CustomFacetFactory.build(
name="Default Facet",
title=u"Специалист",
group=group,
show_production=True)
default_cf.save()
default_site_facet = factories.SeoSiteFacetFactory(
seosite=self.site,
facet_type=factories.SeoSiteFacet.DEFAULT,
customfacet=default_cf)
default_site_facet.save()
resp = self.client.get('/jobs/', HTTP_HOST=self.site.domain,
follow=True)
total_jobs = resp.context['total_jobs_count']
solr_jobs = self.conn.search(q=u"title:Специалист")
self.assertEqual(total_jobs, solr_jobs.hits)
self.assertEqual(len(resp.context['default_jobs']), total_jobs)
#.........这里部分代码省略.........
示例7: SitemapTestCase
# 需要导入模块: from seo_pysolr import Solr [as 别名]
# 或者: from seo_pysolr.Solr import delete [as 别名]
class SitemapTestCase(DirectSEOBase):
def setUp(self):
super(SitemapTestCase, self).setUp()
self.conn = Solr('http://127.0.0.1:8983/solr/seo')
self.conn.add(SOLR_FIXTURE)
def test_index(self):
resp = self.client.get("/sitemap.xml")
self.assertEqual(resp.status_code, 200)
def test_no_buid_sitemap(self):
"""
Test to verify that a sitemap is generated with sites that have no
BUID.
"""
site = SeoSite.objects.get(id=1)
site.business_units = []
site.save()
today = datetime.datetime.today()
dt = datetime.date(*today.timetuple()[0:3]).isoformat()
resp = self.client.get("/sitemap-" + dt + ".xml")
self.assertTrue("<url>" in resp.content)
def test_noreverse(self):
"""
Test to ensure that jobs with bad/ugly data do not block the
creation of a sitemap page, but instead are just skipped over in
`SolrSitemap.get_urls().`
This is a regression test. It was prompted by a job in a job feed
file having "~" in the "city" field. Because our URL pattern
doesn't recognize that character in its regex, it caused a
`NoReverseMatch` exception to be thrown. Instead of adding a
tilde, we want to be able to handle any weird characters not
specified in our URL config.
"""
# Sometimes the site settings are messed up from other tests. Ensure
# that the settings are compatible with actually searching for the
# jobs we're adding.
settings.SITE_BUIDS = []
site = SeoSite.objects.get(pk=1)
site.business_units = []
site.save()
# These are kwargs from the actual error that created this error in the
# first place.
kwargs = {
'location': '~, WV',
'title': '911 Coordinator',
'uid': '25901630'
}
job = dict(SOLR_FIXTURE[0])
job.update(kwargs)
self.conn.add([job])
today = datetime.datetime.now()
dt = today.date().isoformat()
resp = self.client.get("/sitemap-" + dt + ".xml")
self.assertEqual(resp.status_code, 200)
self.assertTrue("<url>" in resp.content)
def tearDown(self):
super(SitemapTestCase, self).tearDown()
self.conn.delete("*:*")
示例8: update_solr
# 需要导入模块: from seo_pysolr import Solr [as 别名]
# 或者: from seo_pysolr.Solr import delete [as 别名]
def update_solr(buid, download=True, force=True, set_title=False,
delete_feed=True, data_dir=DATA_DIR, clear_cache=False):
"""
Update the Solr master index with the data contained in a feed file
for a given buid/jsid.
This is meant to be a standalone function such that the state of the
Solr index is not tied to the state of the database.
Inputs:
:buid: An integer; the ID for a particular business unit.
:download: Boolean. If False, this process will not download a new
feedfile, but instead use the one on disk. Should only be false for
the purposes of our test suite.
:force: Boolean. If True, every job seen in the feed file will be
updated in the index. Otherwise, only the jobs seen in the feed file
but not seen in the index will be updated. This latter option will
soon be deprecated.
Returns:
A 2-tuple consisting of the number of jobs added and the number deleted.
Writes/Modifies:
Job data found in the feed file is used to modify the Solr index. This
includes adds & deletes. (Solr does not have a discrete equivalent to
SQL's UPDATE; by adding a document with the same UID as a document in
the index, the equivalent of an update operation is performed.)
"""
if download:
filepath = download_feed_file(buid, data_dir=data_dir)
else:
# Get current worker process id, to prevent race conditions.
try:
p = current_process()
process_id = p.index
except:
process_id = 0
filepath = os.path.join(data_dir, str(process_id), FEED_FILE_PREFIX + str(buid) +
'.xml')
bu = BusinessUnit.objects.get(id=buid)
try:
co = bu.company_set.all()[0]
except IndexError:
co = None
jobfeed = DEv2JobFeed(filepath, jsid=buid, markdown=bu.enable_markdown,
company=co)
# If the feed file did not pass validation, return. The return value is
# '(0, 0)' to match what's returned on a successful parse.
if jobfeed.errors:
error = jobfeed.error_messages
logging.error("BUID:%s - Feed file has failed validation on line %s. "
"Exception: %s" % (buid, error['line'],
error['exception']))
raise FeedImportError(error)
# A dictionary of uids
jobs = jobfeed.jobparse()
# Build a set of all the UIDs for all those instances.
job_uids = set([long(i.get('uid')) for i in jobs if i.get('uid')])
conn = Solr(settings.HAYSTACK_CONNECTIONS['default']['URL'])
step1 = 1024
# Get the count of all the results in the Solr index for this BUID.
hits = conn.search("*:*", fq="buid:%s" % buid, facet="false",
mlt="false").hits
# Create (start-index, stop-index) tuples to facilitate handling results
# in ``step1``-sized chunks. So if ``hits`` returns 2048 results,
# ``job_slices`` will look like ``[(0,1024), (1024, 2048)]``. Those
# values are then used to slice up the total results.
#
# This was put in place because part of the logic to figuring out what
# jobs to delete from and add jobs to the Solr index is using set
# algebra. We convert the total list of UIDs in the index and the UIDs
# in the XML feed to sets, then compare them via ``.difference()``
# (seen below). However for very large feed files, say 10,000+ jobs,
# this process was taking so long that the connection would time out. To
# address this problem we break up the comparisons as described above.
# This results in more requests but it alleviates the connection timeout
# issue.
job_slices = slices(range(hits), step=step1)
results = [_solr_results_chunk(tup, buid, step1) for tup in job_slices]
solr_uids = reduce(lambda x, y: x | y, results) if results else set()
# Return the job UIDs that are in the Solr index but not in the feed
# file.
solr_del_uids = solr_uids.difference(job_uids)
if not force:
# Return the job UIDs that are in the feed file but not in the Solr
# index.
solr_add_uids = job_uids.difference(solr_uids)
# ``jobfeed.solr_jobs()`` yields a list of dictionaries. We want to
# filter out any dictionaries whose "uid" key is not in
# ``solr_add_uids``. This is because by default we only want to add
# new documents (which each ``solr_jobs()`` dictionary represents),
# not update.
add_docs = filter(lambda x: int(x.get("uid", 0)) in solr_add_uids,
jobfeed.solr_jobs())
else:
#.........这里部分代码省略.........
示例9: LoadETLTestCase
# 需要导入模块: from seo_pysolr import Solr [as 别名]
# 或者: from seo_pysolr.Solr import delete [as 别名]
class LoadETLTestCase(DirectSEOBase):
fixtures = ['countries.json']
def setUp(self):
self.solr_settings = {
'default': {'URL': 'http://127.0.0.1:8983/solr/seo'}
}
self.solr = Solr(settings.HAYSTACK_CONNECTIONS['default']['URL'])
self.solr.delete(q="*:*")
self.zipfile = os.path.join(os.path.dirname(os.path.abspath(__file__)),
'data',
'ActiveDirectory_ce2ca701-eeca-4c13-96ba-e6bde9cb7060.zip')
with open(self.zipfile) as zf:
self.jobs = list(get_jobs_from_zipfile(zf, "ce2ca701-eeca-4c13-96ba-e6bde9cb7060"))
self.businessunit = BusinessUnitFactory(id=0)
self.buid = self.businessunit.id
self.guid = 'ce2ca701-eeca-4c13-96ba-e6bde9cb7060'
self.name = "Test"
def tearDown(self):
pass
@patch('import_jobs.get_jobsfs_zipfile')
def test_update_job_source(self, mock_jobsfs):
mock_jobsfs.return_value = open(self.zipfile, 'rb')
count = self.solr.search('*:*').hits
self.assertEqual(count, 0, "Jobs for buid in solr before the test. Cannot guarantee correct behavior.")
self.assertEqual(self.businessunit.associated_jobs, 4, "Initial Job Count does not match the factory")
update_job_source(self.guid, self.buid, self.name)
count = self.solr.search('buid:%s' % self.buid).hits
# Note the job count being one low here is due to one job being filtered out due to include_in_index_bit
self.assertEqual(count, 38, "38 Jobs not in solr after call to update job source. Found %s" % count)
self.assertEqual(BusinessUnit.objects.get(id=self.buid).associated_jobs, 38,
"Job Count not updated after imports: Should be 38 was %s" % self.businessunit.associated_jobs)
def test_filtering_on_includeinindex_bit(self):
"""Test that filtering on the include_in_index bit works"""
#Prove we have the expected number of jobs in the zipfile itself.
self.assertEqual(len(self.jobs), 39,
"Expected to find 0 jobs in the test zipfile, instead found %s" % len(self.jobs))
# Prove that filtering works.
filtered_jobs = list(filter_current_jobs(self.jobs, self.businessunit))
self.assertEqual(len(filtered_jobs), 38,
"filter_current_jobs should rmeove jobs with the includeinindex bit set, "
"it's expected to return %s. Instead it returned %s" % (38, len(filtered_jobs)))
def test_businessunit_ignore_includeinindex(self):
"""Test that filtering on the include_in_index bit can be overridden on a per business unit basis."""
# Set ignore_includeinindex on the test BusinessUnit
self.businessunit.ignore_includeinindex = True
self.businessunit.save()
#Prove we have the expected number of jobs in the zipfile itself.
self.assertEqual(len(self.jobs), 39,
"Expected to find 0 jobs in the test zipfile, instead found %s" % len(self.jobs))
# Prove that filtering works.
filtered_jobs = list(filter_current_jobs(self.jobs, self.businessunit))
self.assertEqual(len(filtered_jobs), 39,
"filter_current_jobs should ignore the includeinindex bit, returning 39 jobs. "
"Instead returned %s." % len(filtered_jobs))
示例10: ImportJobsTestCase
# 需要导入模块: from seo_pysolr import Solr [as 别名]
# 或者: from seo_pysolr.Solr import delete [as 别名]
class ImportJobsTestCase(DirectSEOBase):
fixtures = ['import_jobs_testdata.json']
def setUp(self):
super(ImportJobsTestCase, self).setUp()
self.businessunit = BusinessUnitFactory(id=0)
self.buid_id = self.businessunit.id
self.filepath = os.path.join(DATA_DIR, '0', 'dseo_feed_%s.xml' % self.buid_id)
self.solr_settings = {
'default': {'URL': 'http://127.0.0.1:8983/solr/seo'}
}
self.solr = Solr(settings.HAYSTACK_CONNECTIONS['default']['URL'])
def tearDown(self):
super(ImportJobsTestCase, self).tearDown()
self.solr.delete(q='*:*')
def test_solr_rm_feedfile(self):
"""
Test that at the end of Solr parsing, the feed file is deleted.
"""
update_solr(self.buid_id)
self.assertFalse(os.access(self.filepath, os.F_OK))
def test_subsidiary_rename(self):
company1 = CompanyFactory()
company1.save()
bu1 = self.businessunit
bu1.title = "Acme corp"
bu2 = BusinessUnitFactory(title=bu1.title)
bu2.save()
self.businessunit.company_set.add(company1)
# Test that a company was created for both business units
add_company(bu1)
companies = bu1.company_set.all()
self.assertEqual(len(companies), 1)
co = companies[0]
self.assertEqual(co.name, bu1.title)
# Add the 2nd business unit
add_company(bu2)
# Both units should be attached to that company
self.assertEqual(bu1.company_set.all()[0], bu2.company_set.all()[0])
self.assertEqual(bu1.company_set.all().count(), 1)
self.assertIn(bu1, co.job_source_ids.all())
self.assertIn(bu2, co.job_source_ids.all())
self.assertEqual(co.name, bu1.title)
self.assertEqual(co.name, bu2.title)
bu2.title = "New company name"
add_company(bu1)
add_company(bu2)
self.assertEqual(len(co.job_source_ids.all()), 1)
self.assertNotEqual(bu1.company_set.all(), bu2.company_set.all())
self.assertEqual(co.name, bu1.title)
self.assertEqual(len(bu2.company_set.all()), 1)
co2 = bu2.company_set.all()[0]
self.assertEqual(co2.name, bu2.title)
self.assertNotEqual(co2.name, bu1.title)
self.assertNotEqual(co.name, bu2.title)
def test_duplicate_company(self):
company1 = CompanyFactory()
company1.save()
company2 = CompanyFactory(name="Acme corp")
company2.save()
self.businessunit.company_set.add(company1)
self.businessunit.title = "Acme corp"
add_company(self.businessunit)
self.assertEqual(self.businessunit.company_set.all()[0], company2)
def test_set_bu_title(self):
"""
Ensure that if a feedfile for a BusinessUnit comes through, and
the `title` attribute for that BusinessUnit is not set, that
`helpers.update_solr` sets the `title` attribute properly.
"""
bu = BusinessUnit.objects.get(id=self.buid_id)
bu.title = None
bu.save()
# Since the BusinessUnit title is None, the intent is that update_solr
# will set its title to match the company name found in the feed file.
results = update_solr(self.buid_id)
# We have to get the updated state of the BusinessUnit instance, since
# changes to the database won't be reflected by our in-memory version of
# the data.
bu = BusinessUnit.objects.get(id=self.buid_id)
# The title attribute should now equal the initial value established in
# the setUp method.
self.assertEquals(self.businessunit.title, bu.title)
def test_add_company(self):
"""
Create environment to test for every possible case--
- Existing relationship but the name is different pk=10
#.........这里部分代码省略.........
示例11: MyJobsBase
# 需要导入模块: from seo_pysolr import Solr [as 别名]
# 或者: from seo_pysolr.Solr import delete [as 别名]
class MyJobsBase(TestCase):
def setUp(self):
settings.ROOT_URLCONF = "myjobs_urls"
settings.PROJECT = "myjobs"
self.app_access = AppAccessFactory()
self.activities = [
ActivityFactory(name=activity, app_access=self.app_access)
for activity in [
"create communication record", "create contact",
"create partner saved search", "create partner", "create role",
"create tag", "create user", "delete tag", "delete partner",
"delete role", "delete user", "read contact",
"read communication record", "read partner saved search",
"read partner", "read role", "read user", "read tag",
"update communication record", "update contact",
"update partner", "update role", "update tag", "update user",
"read outreach email address", "create outreach email address",
"delete outreach email address",
"update outreach email address", "read outreach record",
"convert outreach record"]]
self.company = CompanyFactory(app_access=[self.app_access])
# this role will be populated by activities on a test-by-test basis
self.role = RoleFactory(company=self.company, name="Admin")
self.user = UserFactory(roles=[self.role], is_staff=True)
cache.clear()
clear_url_caches()
self.ms_solr = Solr(settings.SOLR['seo_test'])
self.ms_solr.delete(q='*:*')
self.base_context_processors = settings.TEMPLATE_CONTEXT_PROCESSORS
context_processors = self.base_context_processors + (
'mymessages.context_processors.message_lists',
)
setattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS', context_processors)
setattr(settings, 'MEMOIZE', False)
self.patcher = patch('urllib2.urlopen', return_file())
self.mock_urlopen = self.patcher.start()
self.client = TestClient()
self.client.login_user(self.user)
def tearDown(self):
self.ms_solr.delete(q='*:*')
setattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS',
self.base_context_processors)
try:
self.patcher.stop()
except RuntimeError:
# patcher was stopped in a test
pass
def assertRequires(self, view_name, *activities, **kwargs):
"""
Asserts that the given view is only accessible when a user has a role
with the given activities.
"""
url = reverse(view_name, kwargs=kwargs.get('kwargs'))
method = kwargs.get("method", "get").lower()
response = getattr(self.client, method)(path=url)
self.assertEqual(type(response), MissingActivity)
self.role.activities = [activity for activity in self.activities
if activity.name in activities]
response = getattr(self.client, method)(path=url)
self.assertNotEqual(type(response), MissingActivity)
self.role.activities.clear()
示例12: DirectSEOBase
# 需要导入模块: from seo_pysolr import Solr [as 别名]
# 或者: from seo_pysolr.Solr import delete [as 别名]
class DirectSEOBase(TestCase):
def setUp(self):
db_backend = settings.DATABASES['default']['ENGINE'].split('.')[-1]
# Set columns that are utf8 in production to utf8
if db_backend == 'mysql':
cursor = connections['default'].cursor()
cursor.execute("alter table seo_customfacet convert to character "
"set utf8 collate utf8_unicode_ci")
cursor.execute("alter table seo_seositefacet convert to character "
"set utf8 collate utf8_unicode_ci")
cursor.execute("alter table seo_company convert to character set "
"utf8 collate utf8_unicode_ci")
cursor.execute("alter table seo_queryredirect convert to character "
"set utf8 collate utf8_unicode_ci")
cursor.execute("alter table taggit_tag convert to character set "
"utf8 collate utf8_unicode_ci")
cursor.execute("alter table taggit_taggeditem convert to "
"character set "
"utf8 collate utf8_unicode_ci")
cursor.execute("alter table seo_seositeredirect convert to "
"character set utf8 collate utf8_unicode_ci")
cursor.execute("alter table django_redirect convert to "
"character set utf8 collate utf8_unicode_ci")
# We have a data migration that does this, but we don't run
# migrations during tests (Django 1.6.5
cursor.execute("ALTER TABLE django_flatpage CONVERT TO "
"CHARACTER SET utf8 COLLATE utf8_general_ci")
cursor.execute("ALTER TABLE seo_custompage CONVERT TO "
"CHARACTER SET utf8 COLLATE utf8_general_ci")
setattr(settings, 'ROOT_URLCONF', 'dseo_urls')
setattr(settings, "PROJECT", 'dseo')
clear_url_caches()
self.base_middleware_classes = settings.MIDDLEWARE_CLASSES
middleware_classes = self.base_middleware_classes + (
'wildcard.middleware.WildcardMiddleware',
'middleware.RedirectOverrideMiddleware')
setattr(settings, 'MIDDLEWARE_CLASSES', middleware_classes)
self.base_context_processors = settings.TEMPLATE_CONTEXT_PROCESSORS
context_processors = self.base_context_processors + (
"social_links.context_processors.social_links_context",
"seo.context_processors.site_config_context",
)
setattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS', context_processors)
context._standard_context_processors = None
self.conn = Solr('http://127.0.0.1:8983/solr/seo')
self.conn.delete(q="*:*")
cache.clear()
clear_url_caches()
setattr(settings, 'MEMOIZE', False)
# As we added tests that created more and more companies, we
# approached the hardcoded companies in import_jobs_testdata.json.
# When we hit those ids, we began to get IntegrityErrors during
# testing. Reset the sequence used by CompanyFactory to clear this
# build-up.
CompanyFactory.reset_sequence()
def tearDown(self):
from django.conf import settings
from django.template import context
setattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS',
self.base_context_processors)
context._standard_context_processors = None
setattr(settings, 'MIDDLEWARE_CLASSES',
self.base_middleware_classes)