Exemple #1
0
 def tearDown(self):
     """Regular tear down method"""
     session = DBSession()
     Bmark.query.delete()
     Tag.query.delete()
     session.execute(bmarks_tags.delete())
     session.flush()
     transaction.commit()
Exemple #2
0
 def tearDown(self):
     """Regular tear down method"""
     session = DBSession()
     Bmark.query.delete()
     Tag.query.delete()
     session.execute(bmarks_tags.delete())
     session.flush()
     transaction.commit()
Exemple #3
0
 def tearDown(self):
     """Tear down each test"""
     testing.tearDown()
     session = DBSession()
     Bmark.query.delete()
     Tag.query.delete()
     session.execute(bmarks_tags.delete())
     session.flush()
     transaction.commit()
Exemple #4
0
 def tearDown(self):
     """We need to empty the bmarks table on each run"""
     testing.tearDown()
     session = DBSession()
     Bmark.query.delete()
     Tag.query.delete()
     session.execute(bmarks_tags.delete())
     session.flush()
     transaction.commit()
Exemple #5
0
 def tearDown(self):
     """We need to empty the bmarks table on each run"""
     testing.tearDown()
     session = DBSession()
     Bmark.query.delete()
     Tag.query.delete()
     session.execute(bmarks_tags.delete())
     session.flush()
     transaction.commit()
Exemple #6
0
 def tearDown(self):
     """Tear down each test"""
     testing.tearDown()
     session = DBSession()
     Bmark.query.delete()
     Tag.query.delete()
     session.execute(bmarks_tags.delete())
     session.flush()
     transaction.commit()
Exemple #7
0
    def search(self, phrase, content=False):
        """Need to perform searches against the three columns"""
        phrase = " | ".join(phrase.split())

        results = set()
        query = """SELECT bid
        FROM bmarks
        WHERE to_tsvector('english', description) @@ to_tsquery(:phrase) OR
              to_tsvector('english', extended) @@ to_tsquery(:phrase) OR
              to_tsvector('english', tag_str) @@ to_tsquery(:phrase)

        ORDER BY stored DESC;
        """

        res = DBSession.execute(text(query), {"phrase": phrase})

        ids = set([r.bid for r in res])

        results.update(
            set(
                [
                    bmark
                    for bmark in Bmark.query.join(Bmark.tags)
                    .options(contains_eager(Bmark.tags))
                    .filter(Bmark.bid.in_(ids))
                    .all()
                ]
            )
        )

        readable_res = []
        if content:
            query = """SELECT readable.hash_id
            FROM readable, bmarks
            WHERE to_tsvector('english', content) @@ to_tsquery(:phrase)
                  AND readable.hash_id = bmarks.hash_id
            ORDER BY bmarks.stored DESC
            """

            res = DBSession.execute(text(query), {"phrase": phrase})

            ids = set([r.hash_id for r in res])

            readable_res = [
                bmark
                for bmark in Bmark.query.join(Bmark.tags)
                .options(contains_eager(Bmark.tags))
                .filter(Bmark.hash_id.in_(ids))
                .all()
            ]

        results.update(set(readable_res))
        return sorted(list(results), key=lambda res: res.stored, reverse=True)
Exemple #8
0
def empty_db():
    """On teardown, remove all the db stuff"""

    Bmark.query.delete()
    Readable.query.delete()
    # we can't remove the toread tag we have from our commands
    Tag.query.filter(Tag.name != 'toread').delete()
    Hashed.query.delete()

    DBSession.execute(bmarks_tags.delete())
    DBSession.flush()
    transaction.commit()
Exemple #9
0
    def tearDown(self):
        """We need to empty the bmarks table on each run"""
        testing.tearDown()

        if BOOKIE_TEST_INI == 'test.ini':
            SqliteBmarkFT.query.delete()
        Bmark.query.delete()
        Tag.query.delete()
        Hashed.query.delete()

        DBSession.execute(bmarks_tags.delete())
        DBSession.flush()
        transaction.commit()
Exemple #10
0
def empty_db():
    """On teardown, remove all the db stuff"""

    if BOOKIE_TEST_INI == 'test.ini':
        SqliteBmarkFT.query.delete()
    Bmark.query.delete()
    # we can't remove the toread tag we have from our commands
    Tag.query.filter(Tag.name != 'toread').delete()
    Hashed.query.delete()

    DBSession.execute(bmarks_tags.delete())
    DBSession.flush()
    transaction.commit()
Exemple #11
0
    def tearDown(self):
        """We need to empty the bmarks table on each run"""
        testing.tearDown()

        # DBSession.execute("TRUNCATE bmarks;")
        # DBSession.execute("TRUNCATE fulltext;")
        # DBSession.execute("TRUNCATE tags;")
        # DBSession.execute("TRUNCATE bmarks_tags;")
        SqliteModel.query.delete()
        Bmark.query.delete()
        Tag.query.delete()
        DBSession.execute(bmarks_tags.delete())
        DBSession.flush()
        transaction.commit()
Exemple #12
0
    def tearDown(self):
        """We need to empty the bmarks table on each run"""
        testing.tearDown()

        # DBSession.execute("TRUNCATE bmarks;")
        # DBSession.execute("TRUNCATE fulltext;")
        # DBSession.execute("TRUNCATE tags;")
        # DBSession.execute("TRUNCATE bmarks_tags;")
        SqliteModel.query.delete()
        Bmark.query.delete()
        Tag.query.delete()
        DBSession.execute(bmarks_tags.delete())
        DBSession.flush()
        transaction.commit()
Exemple #13
0
def empty_db():
    """On teardown, remove all the db stuff"""
    DBSession.execute(bmarks_tags.delete())
    Readable.query.delete()
    Bmark.query.delete()
    Tag.query.delete()
    # we can't remove the toread tag we have from our commands
    Hashed.query.delete()
    ImportQueue.query.delete()

    DBSession.flush()
    transaction.commit()

    # Clear the fulltext index as well.
    _reset_index()
Exemple #14
0
    def test_google_import(self):
        """Test that we can upload our google file"""
        self.testapp.post('/login',
                            params={
                                "login": "******",
                                "password": "******",
                                "form.submitted": "Log In",
                            },
                            status=302)

        session = DBSession()
        loc = os.path.dirname(__file__)
        del_file = open(os.path.join(loc, 'googlebookmarks.html'))
        res = DBSession.execute("SELECT api_key FROM users WHERE username = '******'").fetchone()
        API_KEY = res['api_key']

        post = {
            'api_key': API_KEY,
        }


        res = self.testapp.post('/admin/import',
                                params=post,
                                upload_files=[('import_file',
                                               'googlebookmarks.html',
                                               del_file.read())],
        )

        eq_(res.status, "302 Found",
            msg='Import status is 302 redirect by home, ' + res.status)

        session.flush()

        # test all the data we want to test after the import
        _google_data_test()
Exemple #15
0
    def test_add_bookmark(self):
        """We should be able to add a new bookmark to the system"""
        # we need to know what the current admin's api key is so we can try to
        # add
        res = DBSession.execute(
            "SELECT api_key FROM users WHERE username = '******'").fetchone()
        key = res['api_key']

        test_bmark = {
            'url': u'http://bmark.us',
            'description': u'Bookie',
            'extended': u'Extended notes',
            'tags': u'bookmarks',
            'api_key': key,
        }

        res = self.testapp.post('/api/v1/admin/bmark',
                                params=test_bmark,
                                status=200)

        self.assertTrue(
            '"location":' in res.body,
            "Should have a location result: " + res.body)
        self.assertTrue(
            'description": "Bookie"' in res.body,
            "Should have Bookie in description: " + res.body)
        self._check_cors_headers(res)
Exemple #16
0
 def api_key(self):
     """Cache the api key for all calls."""
     if not self._api_key:
         res = DBSession.execute(
             "SELECT api_key FROM users WHERE username='******'").fetchone()
         self._api_key = res['api_key']
     return self._api_key
Exemple #17
0
 def api_key(self):
     """Cache the api key for all calls."""
     if not self._api_key:
         res = DBSession.execute(
             "SELECT api_key FROM users WHERE username='******'").fetchone()
         self._api_key = res['api_key']
     return self._api_key
Exemple #18
0
    def setUp(self):
        from pyramid.paster import get_app
        app = get_app(BOOKIE_TEST_INI, 'main')
        from webtest import TestApp
        self.testapp = TestApp(app)
        testing.setUp()

        global API_KEY
        res = DBSession.execute("SELECT api_key FROM users WHERE username = '******'").fetchone()
        API_KEY = res['api_key']
Exemple #19
0
def empty_db():
    """On teardown, remove all the db stuff"""
    DBSession.execute(bmarks_tags.delete())
    Readable.query.delete()
    Bmark.query.delete()
    StatBookmark.query.delete()
    Tag.query.delete()
    # we can't remove the toread tag we have from our commands
    Hashed.query.delete()
    ImportQueue.query.delete()
    # Delete the users not admin in the system.
    Activation.query.delete()
    User.query.filter(User.username != u'admin').delete()

    AppLog.query.delete()
    DBSession.flush()
    transaction.commit()

    # Clear the fulltext index as well.
    _reset_index()
Exemple #20
0
def empty_db():
    """On teardown, remove all the db stuff"""
    DBSession.execute(bmarks_tags.delete())
    Readable.query.delete()
    Bmark.query.delete()
    StatBookmark.query.delete()
    Tag.query.delete()
    # we can't remove the toread tag we have from our commands
    Hashed.query.delete()
    ImportQueue.query.delete()
    # Delete the users not admin in the system.
    Activation.query.delete()
    User.query.filter(User.username != 'admin').delete()

    AppLog.query.delete()
    DBSession.flush()
    transaction.commit()

    # Clear the fulltext index as well.
    _reset_index()
Exemple #21
0
    def setUp(self):
        from pyramid.paster import get_app
        app = get_app(BOOKIE_TEST_INI, 'bookie')
        from webtest import TestApp
        self.testapp = TestApp(app)
        testing.setUp()

        global API_KEY
        res = DBSession.execute(
            "SELECT api_key FROM users WHERE username = '******'").fetchone()
        API_KEY = res['api_key']
Exemple #22
0
 def setUp(self):
     """Setup Tests"""
     from pyramid.paster import get_app
     from bookie.tests import BOOKIE_TEST_INI
     app = get_app(BOOKIE_TEST_INI, 'bookie')
     from webtest import TestApp
     self.app = TestApp(app)
     testing.setUp()
     res = DBSession.execute(
         "SELECT api_key FROM users WHERE username = '******'").\
         fetchone()
     self.api_key = res['api_key']
Exemple #23
0
 def setUp(self):
     """Setup Tests"""
     from pyramid.paster import get_app
     from bookie.tests import BOOKIE_TEST_INI
     app = get_app(BOOKIE_TEST_INI, 'bookie')
     from webtest import TestApp
     self.app = TestApp(app)
     testing.setUp()
     res = DBSession.execute(
         "SELECT api_key FROM users WHERE username = '******'").\
         fetchone()
     self.api_key = res['api_key']
Exemple #24
0
    def setUp(self):
        """Setup Tests"""
        from pyramid.paster import get_app
        from bookie.tests import BOOKIE_TEST_INI

        app = get_app(BOOKIE_TEST_INI, "bookie")
        from webtest import TestApp

        self.testapp = TestApp(app)
        testing.setUp()
        global API_KEY
        if API_KEY is None:
            res = DBSession.execute("SELECT api_key FROM users WHERE username = '******'").fetchone()
            API_KEY = res["api_key"]
Exemple #25
0
    def test_add_bookmark_empty_body(self):
        """When missing a POST body we get an error response."""
        res = DBSession.execute(
            "SELECT api_key FROM users WHERE username = '******'").fetchone()
        key = res['api_key']

        res = self.testapp.post(
            str('/api/v1/admin/bmark?api_key={0}'.format(key)),
            params={},
            status=400)

        data = json.loads(res.body)
        self.assertTrue('error' in data)
        self.assertEqual(data['error'], 'Bad Request: No url provided')
Exemple #26
0
    def test_add_bookmark_missing_url_in_JSON(self):
        """When missing the url in the JSON POST we get an error response."""
        res = DBSession.execute(
            "SELECT api_key FROM users WHERE username = '******'").fetchone()
        key = res['api_key']

        params = {
            'description': u'This is my test desc',
        }

        res = self.testapp.post(
            str('/api/v1/admin/bmark?api_key={0}'.format(key)),
            content_type='application/json',
            params=json.dumps(params),
            status=400)

        data = json.loads(res.body)
        self.assertTrue('error' in data)
        self.assertEqual(data['error'], 'Bad Request: No url provided')
Exemple #27
0
    def search(self, phrase):
        """Need to perform searches against the three columns"""
        phrase = " | ".join(phrase.split())

        query = """SELECT bid
        FROM bmarks
        WHERE to_tsvector('english', description) @@ to_tsquery(:phrase) OR
              to_tsvector('english', extended) @@ to_tsquery(:phrase) OR
              to_tsvector('english', tag_str) @@ to_tsquery(:phrase)

        ORDER BY stored DESC;
        """

        res = DBSession.execute(text(query), {'phrase': phrase})

        ids = set([r.bid for r in res])

        return Bmark.query.join(Bmark.tags).\
                  options(contains_eager(Bmark.tags)).\
                  filter(Bmark.bid.in_(ids)).all()
Exemple #28
0
    def test_add_bookmark(self):
        """We should be able to add a new bookmark to the system"""
        # we need to know what the current admin's api key is so we can try to
        # add
        res = DBSession.execute(
            "SELECT api_key FROM users WHERE username = '******'").fetchone()
        key = res['api_key']

        test_bmark = {
            'url': u'http://bmark.us',
            'description': u'Bookie',
            'extended': u'Extended notes',
            'tags': u'bookmarks',
            'api_key': key,
        }

        res = self.testapp.post('/api/v1/admin/bmark',
                                params=test_bmark,
                                status=200)

        ok_('"location":' in res.body,
            "Should have a location result: " + res.body)
        ok_('description": "Bookie"' in res.body,
            "Should have Bookie in description: " + res.body)
Exemple #29
0
 def _reset_admin(self):
     """Reset the admin account"""
     DBSession.execute("UPDATE users SET activated='1' WHERE username='******';")
     Activation.query.delete()
     transaction.commit()
Exemple #30
0
 def _reset_admin(self):
     """Reset the admin account"""
     DBSession.execute(
         "UPDATE users SET activated='1' WHERE username='******';")
     Activation.query.delete()
     transaction.commit()
Exemple #31
0
 def setUp(self):
     """Store off the commands so we can return them"""
     self.saved_commandlist = COMMANDLIST
     for key in COMMANDLIST.keys():
         del(COMMANDLIST[key])
     DBSession.execute("INSERT INTO tags (name) VALUES ('toread')")