Beispiel #1
0
    def setUp(self):
        self.app = application.app
        bcrypt = Bcrypt(self.app)

        # forcibly reconnect to testing db
        connection.disconnect()
        self.app.config['MONGO_CONFIG']['db_name'] = 'pipeline_testing'
        self.connection = connect(
            self.app.config['MONGO_CONFIG']['db_name']
            , host=self.app.config['MONGO_CONFIG']['host']
            , port=int(self.app.config['MONGO_CONFIG']['port'])
        )
        # drop any lingering test dbs
        self.connection.drop_database(
            self.app.config['MONGO_CONFIG']['db_name'])

        member_user = User(
            admin_rights = False
            , email = '*****@*****.**'
            , email_confirmation_code = 'goodday'
            , email_confirmed = True
            , last_login_time = datetime.datetime.utcnow()
            , password_hash = bcrypt.generate_password_hash('hola!')
            , registration_time = datetime.datetime.utcnow()
            , verified = True)
        member_user.save()

        ''' create a test org
        '''
        test_org = Organization(
            label = 'best-org'
            , name = 'best org')
        test_org.save()

        # save membership
        member_user.update(push__organizations = test_org)

        ''' create a test project
        '''
        test_project = Project(
            creation_time = datetime.datetime.utcnow()
            , label = 'best-project'
            , name = 'best project'
            , organization = test_org)
        test_project.save()
        test_org.update(push__projects=test_project)

        ''' create a data-less upload
        '''
        '''
Beispiel #2
0
    def setUp(self):
        self.app = application.app
        bcrypt = Bcrypt(self.app)

        # forcibly reconnect to testing db
        connection.disconnect()
        self.app.config['MONGO_CONFIG']['db_name'] = 'pipeline_testing'
        mongo_config = self.app.config['MONGO_CONFIG']
        mongodb_uri = 'mongodb://'
        if mongo_config['dbuser'] and mongo_config['dbpassword']:
            mongodb_uri += '%s:%s@' % (mongo_config['dbuser']
                    , mongo_config['dbpassword'])
        mongodb_uri += '%s/%s' % (mongo_config['hosts'], mongo_config['db_name'])
        self.connection = connect(mongo_config['db_name'], host=mongodb_uri)

        # drop any lingering test dbs
        self.connection.drop_database(
            self.app.config['MONGO_CONFIG']['db_name'])

        ''' create test user
        '''
        member_user = User(
            admin_rights = False
            , email = '*****@*****.**'
            , email_confirmation_code = 'goodday'
            , email_confirmed = True
            , last_login_time = datetime.utcnow()
            , password_hash = bcrypt.generate_password_hash('hola!')
            , registration_time = datetime.utcnow()
            , verified = True)
        member_user.save()

        ''' create test org
        '''
        test_org = Organization(
            label = 'euro-water'
            , name = 'Euro Water')
        test_org.save()
        # save membership
        member_user.update(push__organizations = test_org)

        ''' create test headers
        '''
        date_header = Header(data_type = 'datetime', name = 'date',
                label = 'date')
        date_header.save()

        pH_header = Header(data_type = 'number', name = 'pH', label = 'pH')
        pH_header.save()

        city_header = Header(data_type = 'string', name = 'city',
                label = 'city')
        city_header.save()
        headers = [date_header, pH_header, city_header]

        # save ref to this header for later test
        self.date_header_id = date_header.id

        ''' create test project
        '''
        test_project = Project(
            creation_time = datetime.utcnow()
            , label = 'water-quality'
            , name = 'water quality'
            , ordered_schema = headers
            , organization = test_org)
        test_project.save()
        test_org.update(push__projects=test_project)

        ''' update the headers with a ref to the project
        '''
        for header in headers:
            header.update(set__project = test_project)

        ''' create test datapoints
        '''
        test_data = [
            {'date': datetime(2012, 3, 4), 'pH': 2.2, 'city': 'Madrid'}
            , {'date': datetime(2012, 3, 5), 'pH': 3, 'city': 'Paris'}
            , {'date': datetime(2012, 3, 6), 'pH': 4, 'city': 'London'}
            , {'date': datetime(2012, 3, 6), 'pH': 3, 'city': 'London'}
            , {'date': datetime(2012, 3, 6), 'pH': None, 'city': 'London'}
        ]
        for datapoint in test_data:
            new_entry = Entry(
                project = test_project
                , unique = True
                , values = datapoint)
            new_entry.save()
Beispiel #3
0
    def setUp(self):
        self.app = application.app
        bcrypt = Bcrypt(self.app)

        # forcibly reconnect to testing db
        connection.disconnect()
        self.app.config['MONGO_CONFIG']['db_name'] = 'pipeline_testing'
        mongo_config = self.app.config['MONGO_CONFIG']
        mongodb_uri = 'mongodb://'
        if mongo_config['dbuser'] and mongo_config['dbpassword']:
            mongodb_uri += '%s:%s@' % (mongo_config['dbuser']
                    , mongo_config['dbpassword'])
        mongodb_uri += '%s/%s' % (mongo_config['hosts'], mongo_config['db_name'])
        self.connection = connect(mongo_config['db_name'], host=mongodb_uri)

        # drop any lingering test dbs
        self.connection.drop_database(
            self.app.config['MONGO_CONFIG']['db_name'])

        admin_user = User(
            admin_rights = True
            , email = '*****@*****.**'
            , email_confirmation_code = 'goodday'
            , email_confirmed = True
            , last_login_time = datetime.datetime.utcnow()
            , password_hash = bcrypt.generate_password_hash('hola!')
            , registration_time = datetime.datetime.utcnow()
            , verified = True)
        admin_user.save()

        # same as verified but will push into an org for membership
        member_user = User(
            admin_rights = False
            , email = '*****@*****.**'
            , email_confirmation_code = 'goodday'
            , email_confirmed = True
            , last_login_time = datetime.datetime.utcnow()
            , password_hash = bcrypt.generate_password_hash('hola!')
            , registration_time = datetime.datetime.utcnow()
            , verified = True)
        member_user.save()

        verified_user = User(
            admin_rights = False
            , email = '*****@*****.**'
            , email_confirmation_code = 'goodday'
            , email_confirmed = True
            , last_login_time = datetime.datetime.utcnow()
            , password_hash = bcrypt.generate_password_hash('hola!')
            , registration_time = datetime.datetime.utcnow()
            , verified = True)
        verified_user.save()

        unverified_user = User(
            admin_rights = False
            , email = '*****@*****.**'
            , email_confirmation_code = 'goodday'
            , email_confirmed = True
            , last_login_time = datetime.datetime.utcnow()
            , password_hash = bcrypt.generate_password_hash('hola!')
            , registration_time = datetime.datetime.utcnow()
            , verified = False)
        unverified_user.save()

        ''' create a test org
        '''
        test_org = Organization(
            label = 'best-org'
            , name = 'best org')
        test_org.save()

        # save membership
        member_user.update(push__organizations = test_org)

        ''' create a test project
        '''
        test_project = Project(
            creation_time = datetime.datetime.utcnow()
            , label = 'best-project'
            , name = 'best project'
            , organization = test_org)
        test_project.save()
        test_org.update(push__projects=test_project)