Пример #1
0
    def test_block_repeat_signup_attempt(self):

        '''
        Test that an attempt to signup again using the same username (i.e.,
        email address) will be blocked.
        
        '''

        firstname = fakeuser['firstname']
        username = fakeuser['username']
        password = rndpasswd(minimal_password_length + 1)

        self.signup_new_user(password = password,
                             confirmpassword = password,
                             firstname = firstname,
                             username = username)

        self.wilhelmlogout()

        self.signup_new_user(password = password,
                             confirmpassword = password,
                             firstname = firstname,
                             username = username)
        
        expected_error_msg = msg(
        '''An account using the email "%s" already exists. Do you already have an account?''' 
                % (username)
        )

        error_msg_span = self.driver\
            .find_element_by_class_name('username-error')

        self.assertIn(expected_error_msg, error_msg_span.text)
Пример #2
0
    def get_prep_value(self, integer_list):
        '''
        This is the from_python_to_db function.
        '''
        
        if not integer_list:
            return ''

        try:

            integer_list = list(integer_list)

            assert min(integer_list) == 0
            N = max(integer_list)
            assert type(N) is int
            assert sorted(integer_list) == range(N)

            return json.dumps(integer_list)
            
        except AssertionError:
             raise exceptions.ValidationError(
                strings.msg(self.not_an_integer_list % integer_list)
             )

        except TypeError:
            raise exceptions.ValidationError(
                could_not_convert(integer_list, 'json_str')
            )
Пример #3
0
def convert_duration(duration, convert_from='seconds', convert_to='seconds'):

    '''
    Convert from one temporal duration to another. 
    Acceptable units are milliseconds, seconds, minutes, hours, days, weeks,
    months, and years. 
    '''

    _duration_units = (
                       ('milliseconds', 1e-3),
                       ('seconds', 1.0),
                       ('minutes', 60.0),
                       ('hours', 60.0 * 60.0),
                       ('days',  60.0 * 60.0 * 24),
                       ('weeks', 60.0 * 60.0 * 24 * 7),
                       ('months', 60.0 * 60.0 * 24 * 365.242/12),
                       ('years', 60.0 * 60.0 * 24 * 365.242)
                       )


    duration_units_value_error = '''
    The specified type of units must be one of the following type: %s.
    ''' % ', '.join([_duration_unit[0] for _duration_unit in _duration_units])

    duration_units = dict(_duration_units)

    try:
        to_seconds = duration * duration_units[convert_from]

        return to_seconds / duration_units[convert_to]

    except KeyError:

        print(strings.msg(duration_units_value_error))
        raise
Пример #4
0
    def make_experiments(self):

        '''
        Create experiment versions (and their experiment parents, if necessary)
        for each experiment listed in this archive. The creation entails the
        creation of playlists for each experiment.
        '''

        exported_archive = git.export(self.repository.path,
                                      self.commit_hash)

        experiments_module = python.impfromsource(
            conf.repository_experiments_modulename, exported_archive
        )

        experiments_settings = os.path.join(exported_archive,
                                            conf.repository_settings_filename)

        config = configobj.ConfigObj(
            experiments_settings,
            configspec = conf.repository_settings_configspec
            )

        validator = validate.Validator()

        assert config.validate(validator, copy=True)

        for class_name, experiment_notes in config['experiments'].items():

            label = utils.make_experiment_release_code(class_name,
                                                       self)

            release_note = experiment_notes['release-note']

            try:

                playlist_factory = getattr(experiments_module, class_name)

            except AttributeError:

                error_msg = strings.msg('''
                No experiment named %s in the repository %s (commit hash: %s).
                ''' % (class_name, self.repository.name, self.commit_hash)
                )

                print(error_msg) # You could log it too.

                raise

            playlist = playlist_factory.new()

            ExperimentVersion.new(
                experiment=Experiment.new(class_name=class_name),
                label=label,
                release_note=release_note,
                playlist=playlist,
                archive=self)
Пример #5
0
def could_not_convert(x, conversion_type):
    '''
    A generic error message raised when trying to convert something `x` to
    `conversion_type`.
    '''

    msg = 'Could not convert %s (%s) to %s.' % (str(x),
                                                type(x),
                                                conversion_type)
    return strings.msg(msg)
Пример #6
0
def wilhelmlogin(request, username, password):

        user = authenticate(username=username, 
                            password=password)

        assert user is not None,\
            msg('The username or password you entered is incorrect.')

        assert user.is_active, msg('Your account is not active.')

        login(request, user)

        if is_demo_account(request):
            subject = Subject.objects.create_temp_subject(user)
            request.session['temp_subject_uid'] = subject.uid
        else:
            subject = Subject.objects.get(user=user)

        return user, subject
Пример #7
0
    def getuser(self):

        emailaddr = self.username.strip()
        assert len(emailaddr), 'Email address should not be empty'
        assert validate_email(emailaddr), 'Invalid email address.'
        assert user_exists(emailaddr), msg('''
                An account using the email "%s" does not exist. Are you sure
                you have an account?
                ''' % emailaddr)

        self.user = User.objects.get(username=emailaddr)
Пример #8
0
    def getusername(self):

        emailaddr = self.postdict['username'].strip()
        assert len(emailaddr), 'Email address should not be empty'
        assert validate_email(emailaddr), 'Invalid email address.'
        assert user_does_not_exist(emailaddr), msg('''
                An account using the email "%s" already exists. Do you already
                have an account?
                ''' % emailaddr)

        return emailaddr
    def stop_nowplaying(self):
        '''
        Stop the slide with the current_slide_rank (assuming it has been
        started), i.e. set completed=True.
        '''

        started, completed = (self.current_slide_in_playlist.started,
                              self.current_slide_in_playlist.completed)
        
        assert started and (not completed), strings.msg(
                '''Slide should be started but not yet completed.
                    Started is %s, Completed is %s.''' % (started, completed)
        )
        
        self.current_slide_in_playlist.set_completed()

        assert self.current_slide_in_playlist.completed, 'Should be True'
    def start_nowplaying(self):

        '''
        Start the slide with current_slide_rank, i.e. set started=True.
        '''

        #===================================================================
        # Conditions that must be met before we start nowplaying.
        #===================================================================
        assert len(self.slides_started_but_not_completed) == 0, strings.msg(
            '''There should be no slides that have been started and not
               finished.'''
        )
        # ==================================================================

        self.current_slide_in_playlist.set_started()

        assert self.current_slide_in_playlist.started, 'Should be True'