This repository has been archived by the owner on Apr 12, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Made 'put' exception text clearer * changed refs to 'snippets' to 'announcements' * changed return exceptions to raise. * Added manifest file to include templates * Added JSON responses * Cleaned up/simpified login/auth routines. * Added clickable IDs * Cleaned up some variable names (more consistent) * Added manifest file to include templates * Added JSON responses * Cleaned up/simpified login/auth routines. * Added clickable IDs * Added more tests for API functions * Cleaned up some variable names (more consistent) * Fix to use setup.py develop to resolve missing templates (I owe rfkelly several of his favorite beverages.) * Added path to health check * Updated Makefile to add run and install * Adding some verbosity to solve remote install issue * Added logger calls * Added config options to dump stack on exceptions, drop to debugger. * Added quick self-verifier * Added sql health check routine * Changed "fetchall*" to more consistent "get_all" * Added redirect for "/" urls => "/author/" * Normalized loc & lang to lowercase in db * Fixed bad JSON in default addresses * Added unit tests * removed extra __init__ * added nose to reqs.
- Loading branch information
Showing
14 changed files
with
545 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
include README.rst | |||
include MANIFEST.in | |||
include campaign.ini | |||
recursive-include campaign/templates *.mako *.css | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,16 +1,21 @@ | |||
APPNAME = geoip | APPNAME = campaign | ||
VE = virtualenv | VE = virtualenv | ||
PY = bin/python | PY = bin/python | ||
PI = bin/pip | PI = bin/pip | ||
NO = bin/nosetests -s --with-xunit | NO = bin/nosetests -s --with-xunit | ||
PS = bin/pserve | |||
|
|
||
all: build | all: build | ||
|
|
||
build: | build: | ||
$(VE) --no-site-packages . | $(VE) --no-site-packages . | ||
bin/easy_install -U distribute | |||
$(PI) install -r prod-reqs.txt | $(PI) install -r prod-reqs.txt | ||
$(PY) setup.py build | $(PY) setup.py develop | ||
|
|
||
test: | test: | ||
$(NO) $(APPNAME) | $(NO) $(APPNAME) | ||
|
|
||
run: | |||
$(PS) campaign-local.ini | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,99 @@ | |||
import json | |||
import time | |||
import unittest2 | |||
from pprint import pprint | |||
from campaign.storage.sql import Storage | |||
from campaign.tests import TConfig | |||
|
|||
class TestStorage(unittest2.TestCase): | |||
|
|||
now = int(time.time()) | |||
|
|||
test_announce = { | |||
'start_time': int(now - 300), | |||
'end_time': int(now + 3000), | |||
'lang': 'en', | |||
'locale': 'US', | |||
'note': 'Text Body', | |||
'title': 'Test', | |||
'dest_url': 'http://example.com' | |||
} | |||
|
|||
def setUp(self): | |||
self.storage = Storage(config = TConfig({'db.type': 'sqlite', | |||
'db.db': ':memory:'})) | |||
|
|||
def tearDown(self): | |||
self.storage.purge() | |||
|
|||
def test_announcement(self): | |||
self.storage.put_announce(self.test_announce) | |||
items = self.storage.get_all_announce() | |||
self.failUnless(len(items) > 0) | |||
self.failUnless(self.test_announce['note'] in items[0].note) | |||
self.failUnless(self.test_announce['title'] in items[0].note) | |||
self.failUnless(self.test_announce['dest_url'] in items[0].dest_url) | |||
|
|||
def update_note(self, announce, note_text): | |||
return announce.copy() | |||
|
|||
def test_search(self): | |||
""" Yes, this test does a lot of things. That's because I need | |||
to exercise the search algo using a lot of records. """ | |||
# really wish that update allowed chaining. | |||
updates = [{'lang':None, 'locale':None, 'title':'Everyone'}, | |||
{'platform':'a', 'channel':'a', 'title':'p:a;c:a'}, | |||
{'platform':'b', 'channel':'a', 'title':'p:b;c:a'}, | |||
{'platform':'a', 'start_time': self.now + 1, | |||
'end_time': self.now + 3, 'title':'notyet'}, | |||
{'platform':'a', 'end_time': self.now-5, 'title':'tooold'}, | |||
{'platform':'a', 'idle_time': 10, 'title': 'idle:10'}, | |||
{'platform':'a', 'channel':'b', 'lang':'a', 'locale':'a', | |||
'idle_time': 10, 'title': 'full_rec'} | |||
] | |||
# load the database | |||
for update in updates: | |||
test = self.test_announce.copy() | |||
test.update(update) | |||
self.storage.put_announce(test) | |||
data = {'platform':'f', 'channel':'f', 'version':0} | |||
announce = self.storage.get_announce(data) | |||
self.assertEqual(len(announce), 1) | |||
self.assertEqual(announce[0]['title'], 'Everyone') | |||
data = {'platform':'a', 'channel':'a'} | |||
announce = self.storage.get_announce(data) | |||
# only Everyone and p:a;c:a should be returned. | |||
print "P&C check:" | |||
self.assertEqual(len(announce), 2) | |||
|
|||
data = {'platform':'a', 'channel':'a', 'idle_time': 15} | |||
announce = self.storage.get_announce(data) | |||
print "Idle Check:" | |||
self.assertEqual(len(announce), 3) | |||
|
|||
data = {'platform':'a', 'channel':'b'} | |||
announce = self.storage.get_announce(data) | |||
print "P&C2 check:" | |||
self.assertEqual(len(announce), 1) | |||
# Store the unique record data for the resolve check. | |||
resolve_rec = announce[0] | |||
|
|||
data = {'platform':'a', 'channel':'a'} | |||
time.sleep(self.now + 2 - int(time.time())) | |||
print "Wake check: %s " % (int(time.time()) - self.now) | |||
announce = self.storage.get_announce(data) | |||
self.assertEqual(len(announce), 3); | |||
|
|||
time.sleep(self.now + 4 - int(time.time())) | |||
print "Expire check: %s " % (int(time.time()) - self.now) | |||
data = {'platform':'a', 'channel':'a'} | |||
announce = self.storage.get_announce(data) | |||
self.assertEqual(len(announce), 2); | |||
|
|||
# Since we have an ID for a unique record, query it to make | |||
# sure records resolve. | |||
print "resolve check: %s" % resolve_rec['id'] | |||
rec = self.storage.resolve(resolve_rec['id']) | |||
self.assertEqual('Everyone', json.loads(rec['note'])['title']) | |||
|
|||
#TODO: continue tests |
Oops, something went wrong.