def test_DefaultFileServerAddRaisesNotImplentedError(self):
     fs = file_server.FileServer()
     
     db = main.sessionDB()
     db.insert = Mock(return_value=1)
     
     self.assertRaises(NotImplementedError, fs.add, "This is file data", "myapp")
Example #2
0
 def setUp(self):
     # HACK: We kept getting db.printing inexplicably set to True, so patch
     # it to be False here.
     _real_db_execute = web.db.DB._db_execute
     def _db_execute(self, cur, sql_query):
         self.printing = False
         return _real_db_execute(self, cur, sql_query)
     web.db.DB._db_execute = _db_execute
         
     # Set the dev flag in Config to False.
     Config.load()
     Config.data['dev'] = False
     
     # Set the debug flag to true, despite what is in the config file
     web.config.debug = False
     web.config.session_parameters['cookie_name'] = 'gam'
     
     # TODO: Clean up this initialization
     web.ctx.method = ''
     web.ctx.path = ''
     import StringIO
     web.ctx.env = {'wsgi.input': StringIO.StringIO(),
                    'REQUEST_METHOD': ''}
     
     # Set up the routes
     app = web.application(main.ROUTES, globals())
     
     # Grab a database connection
     self.db = main.sessionDB()
     
     # Initialize the session holder (I don't know what that is yet)
     #main.SessionHolder.set(web.session.Session(app, web.session.DBStore(db, 'web_session')))
     
     # Finally, create a test app
     self.app = TestApp(app.wsgifunc())
Example #3
0
 def should_allow_admin_user_to_create_user(self):
     self.login(user_id=3)
     
     response = self.app.post('/admin/user/add',
         params={
             'f_name': 'Jane',
             'l_name': 'Doe',
             'email': '*****@*****.**',
             'password': '******',
             'role': '1',
             'affiliation': '',
         },
         status=200)
     
     # Check to see if the user was created
     db = main.sessionDB()
     results = db.query("select user_id from user where email = '*****@*****.**'")
     assert_equal(len(results), 1)
Example #4
0
 def should_not_allow_anonymous_user_to_create_user(self):
     # Check out http://webpy.org/cookbook/testing_with_paste_and_nose for
     # more about testing with Paste.
     response = self.app.post('/admin/user/add',
         params={
             'f_name': 'John',
             'l_name': 'Smith',
             'email': '*****@*****.**',
             'password': '******',
             'role': '1',
             'affiliation': '',
         },
         status=303)
     db = main.sessionDB()
     
     # Check to see if the user was created even though the response
     # returned a redirect (303).
     results = db.query("select user_id from user where email = '*****@*****.**'")
     assert_equal(len(results), 0)
Example #5
0
    def should_allow_admin_user_to_create_user(self):
        self.login(user_id=3)

        response = self.app.post(
            "/admin/user/add",
            params={
                "f_name": "Jane",
                "l_name": "Doe",
                "email": "*****@*****.**",
                "password": "******",
                "role": "1",
                "affiliation": "",
            },
            status=200,
        )

        # Check to see if the user was created
        db = main.sessionDB()
        results = db.query("select user_id from user where email = '*****@*****.**'")
        assert_equal(len(results), 1)
Example #6
0
    def should_not_allow_anonymous_user_to_create_user(self):
        # Check out http://webpy.org/cookbook/testing_with_paste_and_nose for
        # more about testing with Paste.
        response = self.app.post(
            "/admin/user/add",
            params={
                "f_name": "John",
                "l_name": "Smith",
                "email": "*****@*****.**",
                "password": "******",
                "role": "1",
                "affiliation": "",
            },
            status=303,
        )
        db = main.sessionDB()

        # Check to see if the user was created even though the response
        # returned a redirect (303).
        results = db.query("select user_id from user where email = '*****@*****.**'")
        assert_equal(len(results), 0)
Example #7
0
    def setUp(self):
        Config.load()

        # Use the test_db, so that you don't blow stuff away.
        db_config = Config.get('database')
        if 'test_db' in db_config and db_config['test_db']:
            db_config['db'] = db_config['test_db']

        # Grab a database connection
        self.db = main.sessionDB()
        self.install_db_structure(self.db)
        self.load_db_fixtures(self.db, *self.fixtures)

        # HACK: We kept getting db.printing inexplicably set to True, so patch
        # it to be False here.
        _real_db_execute = web.db.DB._db_execute
        def _db_execute(self, cur, sql_query):
            self.printing = False
            return _real_db_execute(self, cur, sql_query)
        web.db.DB._db_execute = _db_execute

        super(DbFixturesMixin, self).setUp()
Example #8
0
    def setUp(self):
        # HACK: We kept getting db.printing inexplicably set to True, so patch
        # it to be False here.
        _real_db_execute = web.db.DB._db_execute

        def _db_execute(self, cur, sql_query):
            self.printing = False
            return _real_db_execute(self, cur, sql_query)

        web.db.DB._db_execute = _db_execute

        # Set the dev flag in Config to False.
        Config.load()
        Config.data['dev'] = False

        # Set the debug flag to true, despite what is in the config file
        web.config.debug = False
        web.config.session_parameters['cookie_name'] = 'gam'

        # TODO: Clean up this initialization
        web.ctx.method = ''
        web.ctx.path = ''
        import StringIO
        web.ctx.env = {'wsgi.input': StringIO.StringIO(), 'REQUEST_METHOD': ''}

        # Set up the routes
        app = web.application(main.ROUTES, globals())

        # Grab a database connection
        self.db = main.sessionDB()

        # Initialize the session holder (I don't know what that is yet)
        #main.SessionHolder.set(web.session.Session(app, web.session.DBStore(db, 'web_session')))

        # Finally, create a test app
        self.app = TestApp(app.wsgifunc())
#!/usr/bin/env python

import os
import sys
import main
from framework.log import log
from framework.config import Config
from giveaminute.projectResource import ProjectResource
from framework.image_server import ImageServer

if __name__ == "__main__":
    """
    Main execution for import script.
    """
    db = main.sessionDB()
    sql = 'select * from import_project_resource'
    import_data = list(db.query(sql))
    for row in import_data:
        image_id = None
            
        # Create image.
        try:
            image_path = './import/data/import-resources-images/%s.jpg' % row.external_id
            if os.path.exists(image_path):
                # Open file
                source = open('./import/data/import-resources-images/%s.jpg' % row.external_id, 'rb')
                # Save file (does not work)
                image_id = ImageServer.add(db, source.read(), 'giveaminute', max_size=None, grayscale=False, mirror=True, thumb_max_size=None)
                # Close file
                source.close()
#!/usr/bin/env python

import os
import sys
import main
from framework.log import log
from framework.config import Config
from giveaminute.projectResource import ProjectResource
from framework.image_server import ImageServer

if __name__ == "__main__":
    """
    Main execution for import script.
    """
    db = main.sessionDB()
    sql = 'select * from import_project_resource'
    import_data = list(db.query(sql))
    for row in import_data:
        image_id = None

        # Create image.
        try:
            image_path = './import/data/import-resources-images/%s.jpg' % row.external_id
            if os.path.exists(image_path):
                # Open file
                source = open(
                    './import/data/import-resources-images/%s.jpg' %
                    row.external_id, 'rb')
                # Save file (does not work)
                image_id = ImageServer.add(db,