Esempio n. 1
0
    def test_succeeds_with_duplicate_name_but_different_user(
            self, client, auth):
        user1 = make_user()
        user2 = make_user('bob')

        auth.login(user1)
        response = client.post('experiments/create',
                               follow_redirects=True,
                               data=dict(name='my experiment',
                                         description='Something'))
        assert (b"Experiment created" in response.data)

        auth.login(user2)
        response = client.post('experiments/create',
                               follow_redirects=True,
                               data=dict(name='my experiment',
                                         description='Something else'))
        assert (b"Experiment created" in response.data)
Esempio n. 2
0
    def test_fails_without_name(self, client, auth):
        user = make_user()
        auth.login(user)

        response = client.post('experiments/create',
                               follow_redirects=True,
                               data=dict(name='', description='Something'))

        assert (b"Experiment.name is required" in response.data)
Esempio n. 3
0
    def test_succeeds_without_description(self, client, auth):
        user = make_user()
        auth.login(user)

        response = client.post('experiments/create',
                               follow_redirects=True,
                               data=dict(name='experiment', description=''))

        assert (b"Experiment created" in response.data)
Esempio n. 4
0
    def test_fails_with_wrong_password(self, client):
        user = self.make_user()

        response = client.post('/users/perform_login', follow_redirects=True, data=dict(
            username = '******',
            password = '******'
        ))

        assert(b"Password is incorrect" in response.data)
Esempio n. 5
0
    def test_fails_with_blank_form(self, client):
        user = self.make_user()

        response = client.post('/users/perform_login', follow_redirects=True, data=dict(
            username = '',
            password = ''
        ))

        assert(b"Invalid username" in response.data)
Esempio n. 6
0
    def test_succeeds_with_username_password(self, client):
        user = self.make_user()

        response = client.post('/users/perform_login', follow_redirects=True, data=dict(
            username = '******',
            password = '******'
        ))

        assert(b"Logged in" in response.data)
Esempio n. 7
0
    def test_fails_with_right_pass_wrong_user(self, client):
        user1 = self.make_user()
        user2 = self.make_user('Bob', 'securepass123')

        response = client.post('/users/perform_login', follow_redirects=True, data=dict(
            username = '******',
            password = '******'
        ))

        assert(b"Password is incorrect" in response.data)
Esempio n. 8
0
    def test_fails_with_short_password(self, client):
        response = client.post('/users/create', follow_redirects=True, data=dict(
            name = "my_organization",
            password_1 = "abc",
            password_2 = "abc"
        ))

        assert(b"Password must be at least 4 characters" in response.data)

        user = get(u for u in User if u.name == "my_organization")

        assert(user == None)
Esempio n. 9
0
    def test_fails_with_blank_username(self, client):
        response = client.post('/users/create', follow_redirects=True, data=dict(
            name = "",
            password_1 = "mypass",
            password_2 = "mypass"
        ))

        assert(b"Must provide a username" in response.data)

        user = get(u for u in User if u.name == "my_organization")

        assert(user == None)
Esempio n. 10
0
    def test_fails_with_non_matching_passwords(self, client):
        response = client.post('/users/create', follow_redirects=True, data=dict(
            name = "my_organization",
            password_1 = "mypass",
            password_2 = "lakdjf"
        ))

        assert(b"Passwords did not match" in response.data)

        user = get(u for u in User if u.name == "my_organization")

        assert(user == None)
Esempio n. 11
0
    def test_succeeds_with_valid_user(self, client):
        response = client.post('/users/create', follow_redirects=True, data=dict(
            name = "my_organization",
            password_1 = "mypass",
            password_2 = "mypass"
        ))

        assert(b"Your account was created" in response.data)

        user = get(u for u in User if u.name == "my_organization")

        assert(user != None)
Esempio n. 12
0
    def test_valid_schema(self, client, auth):
        user = make_user()
        auth.login(user)

        schema = {'field_1': "numeric", 'field_2': "numeric"}

        response = client.post('experiments/create',
                               follow_redirects=True,
                               data=dict(name='name',
                                         description='test',
                                         **self.schema_to_form_fields(schema)))

        experiment = select(ex for ex in Experiment
                            if ex.name == 'name').first()
        eid = experiment.get_pk().hex

        assert schema == Schema.for_experiment(eid).as_dict()
Esempio n. 13
0
    def test_fails_with_duplicate_user(self, client):
        user = User.create(
            username = '******',
            password_1 = 'somepass',
            password_2 = 'somepass',
        )

        flush()

        response = client.post('/users/create', follow_redirects=True, data=dict(
            name = "my_organization",
            password_1 = "mypass",
            password_2 = "mypass"
        ))

        assert(b"This username is taken" in response.data)

        users = count(u for u in User if u.name == "my_organization")

        assert(users == 1)
Esempio n. 14
0
 def test_requires_authentication(self, client):
     response = client.post('experiments/create',
                            follow_redirects=False,
                            data=dict(name='name', description='test'))
     assert (requires_authentication(response))