Beispiel #1
0
 def test_entry_count(self):
     e = event.Event.for_name("Drink glass of water")
     e.track()
     e.track()
     e.track()
     Session.commit()
     self.assertEqual(e.entry_count(), 3)
 def setUp(self):
     engine = create_engine('sqlite:///:memory:', echo=True)
     Model.metadata.create_all(engine)
     Session.configure(bind=engine)
     import app  # Must be after Session is configured
     app.app.config['TESTING'] = True
     self.app = app.app.test_client()
Beispiel #3
0
 def test_list_attributes(self):
     e = event.Event.for_name("Drink glass of water")
     e.track(attrs=dict(size="16", location="office"))
     e.track(attrs=dict(hello="world"))
     e.track(attrs=dict(hello="goodbye", location="office"))
     event.Event.for_name("Fire ze missile", create=True).track(attrs=dict(le_tired="true"))
     Session.commit()
     self.assertEqual(e.attributes(), ["hello", "location", "size"])
Beispiel #4
0
    def test_latest_entry(self):
        e = event.Event.for_name("Drink glass of water")
        e.track(when=earlier(seconds=3))
        e.track(when=earlier(seconds=2))
        f = e.track(when=earlier(seconds=1))
        Session.commit()

        self.assertEqual(e.latest_entry().id, f.id)
Beispiel #5
0
 def test_exports_csv(self):
     e = event.Event.for_name("Drink glass of water")
     o = e.track(when=earlier(seconds=-1), attrs=dict(size="16", location="office"))
     e.track(attrs=dict(hello="world", when="now"))
     e.track(attrs=dict(hello="goodbye", location="office"))
     Session.commit()
     csv_file = list(csv.reader(e.export_csv().splitlines()))
     self.assertEqual(csv_file[0], ["When", "hello", "location", "size", "when"])
     self.assertEqual(csv_file[1], [str(o.when), "", "office", "16", ""])
     self.assertEqual(len(csv_file), 4)
Beispiel #6
0
    def test_events_persist(self):
        e = event.Event.for_name("Drink glass of water")
        o = e.track(attrs=dict(size="16", location="office"))
        when = o.when
        attrs = dict(o.attrs)

        # Reload from db
        Session.commit()
        Session.remove()

        e = event.Event.for_name("Drink glass of water")
        o1 = e.entries()[0]
        self.assertDatetimesEqual(when, o1.when)
        self.assertEqual(attrs, o1.attrs)
Beispiel #7
0
def remove_session(exc):
    if exc and not is_fake_error(exc):
        app.logger.exception("Rolling back database")
        Session.rollback()
    else:
        Session.commit()
    Session.remove()
 def test_doesnt_create(self):
     for url in ('/event/Run_the_unit_tests', '/export/Run_the_unit_tests.csv'):
         resp = self.app.get(url)
         self.assertEqual(resp.status_code, 404, "Didn't 404 for %s" % url)
         self.assertEqual(Session.query(event.Event).count(), 0, "Created event for %s" % url)
 def test_allows_query_string(self):
     resp = self.app.post('/track/Run_the_unit_tests?auth=secr3t', data=dict(test="very yes"))
     self.assertEqual(resp.status_code, 200)
     self.assertEqual(Session.query(event.Event).count(), 1)
 def test_allows_header(self):
     resp = self.app.post('/track/Run_the_unit_tests', data=dict(test="very yes"), headers={"X-Auth-Token": "secr3t"})
     self.assertEqual(resp.status_code, 200)
     self.assertEqual(Session.query(event.Event).count(), 1)
 def test_nothing_without_token(self):
     resp = self.app.post('/track/Run_the_unit_tests', data=dict(test="very yes"))
     self.assertEqual(resp.status_code, 403)
     self.assertEqual(Session.query(event.Event).count(), 0)
     self.assertEqual(Session.query(event.Event).count(), 0)
     self.assertEqual(Session.query(event.Attribute).count(), 0)
 def tearDown(self):
     Session.remove()
Beispiel #13
0
if 'MEMCACHEDCLOUD_SERVERS' in os.environ and 'OPENID_AUTH_IDENTITY' in os.environ:
    use_openid = True
    app.cache = bmemcached.Client(
        os.environ['MEMCACHEDCLOUD_SERVERS'].split(','),
        os.environ.get('MEMCACHEDCLOUD_USERNAME'),
        os.environ.get('MEMCACHEDCLOUD_PASSWORD')
    )
    app.session_interface = memcache_session.Session()
    openid_store = MemoryStore()
    openid_identity = os.environ["OPENID_AUTH_IDENTITY"]


TOKEN = os.environ.get('AUTH_TOKEN')
if not is_database_bound():
    # Don't mess with the database connection if someone else set it up already
    Session.configure(bind=create_engine(os.environ['DATABASE_URL']))


def check_auth_token(fn):
    @wraps(fn)
    def _fn(*args, **kwargs):
        token = request.headers.get('X-Auth-Token', request.args.get('auth'))
        if TOKEN == token:
            return fn(*args, **kwargs)
        else:
            abort(403)
    return _fn


def check_openid_credentials(fn):
    if not use_openid:
Beispiel #14
0
 def setUp(self):
     engine = create_engine("sqlite:///:memory:", echo=True)
     Model.metadata.create_all(engine)
     Session.configure(bind=engine)
     event.Event.for_name("Drink glass of water", create=True)