示例#1
0
    def test_delete_connection_removes_connection(self):
        connection_id = 1234
        test_utils.create_connection(connection_id=connection_id)

        self.post_to_delete_connection(connection_id=connection_id)

        connection = helpers.get_record_from_id(Connection, connection_id)

        assert not connection
示例#2
0
    def test_delete_connection_requires_writer_privileges(self):
        connection_id = 1234
        test_utils.create_connection(connection_id=connection_id)

        self.post_to_delete_connection(connection_id=connection_id,
                                       token_type='viewer')

        connection = helpers.get_record_from_id(Connection, connection_id)

        assert connection
示例#3
0
    def test_add_usergroup_to_connection_with_bad_user_id(self):
        connection_id = 1234
        test_utils.create_connection(connection_id=connection_id)

        response = self.patch_to_edit_connection(connection_id=connection_id,
                                                 usergroup_ids=[99999])

        connection = helpers.get_record_from_id(Connection, connection_id)

        assert response.status_code == 400
        assert not connection.usergroups
示例#4
0
    def test_get_all_connections_returns_all_connections(self):
        test_utils.create_connection(label='ug101')
        test_utils.create_connection(label='ug201')

        connection_count = len(Connection.query.all())

        response = self.get_to_get_all_connections()
        response_dict = json.loads(response.data)
        response_count = len(response_dict['connections'])

        assert response.status_code == 200
        assert connection_count == response_count
示例#5
0
    def test_add_connection_to_usergroup(self):
        usergroup_id = 1234
        test_utils.create_usergroup(usergroup_id=usergroup_id)

        connection_id = 42
        test_utils.create_connection(connection_id=connection_id)

        response = self.patch_to_edit_usergroups(
            usergroup_id=usergroup_id, connection_ids=[connection_id])

        usergroup = helpers.get_record_from_id(Usergroup, usergroup_id)

        assert response.status_code == 200
        assert len(usergroup.connections) == 1
示例#6
0
    def test_edit_label_with_bad_label(self):
        starting_label = 'my_conn'
        conn_id = 42
        test_utils.create_connection(label=starting_label,
                                     connection_id=conn_id)

        new_label = ''
        response = self.patch_to_edit_connection(label=new_label,
                                                 connection_id=conn_id)
        response_dict = json.loads(response.data)
        connection = helpers.get_record_from_id(Connection, conn_id)
        connection_label = connection.label

        assert connection_label == starting_label
示例#7
0
    def test_edit_label_with_valid_data(self):
        starting_label = 'my_conn'
        conn_id = 42
        test_utils.create_connection(label=starting_label,
                                     connection_id=conn_id)

        new_label = 'my_new_conn'
        response = self.patch_to_edit_connection(label=new_label,
                                                 connection_id=conn_id)
        connection = helpers.get_record_from_id(Connection, conn_id)
        connection_label = connection.label

        assert response.status_code == 200
        assert connection_label == new_label
示例#8
0
    def test_add_usergroup_to_connection(self):
        usergroup_id = 42
        usergroup = test_utils.create_usergroup(usergroup_id=usergroup_id)

        connection_id = 1234
        test_utils.create_connection(connection_id=connection_id)

        response = self.patch_to_edit_connection(connection_id=connection_id,
                                                 usergroup_ids=[usergroup_id])

        connection = helpers.get_record_from_id(Connection, connection_id)

        assert response.status_code == 200
        assert len(connection.usergroups) == 1
        assert connection.usergroups[0].id == usergroup_id
示例#9
0
    def test_create_connection_with_valid_input(self):
        conn = test_utils.create_connection(label='test_conn',
                                            db_type='sqlite',
                                            host='/tmp')
        connection = cm.create_connection(conn)

        assert connection
示例#10
0
    def test_create_chart_with_invalid_data(self):
        with db.session.no_autoflush:
            sql_query_id = 111
            test_utils.create_query(query_id=sql_query_id)

            connection_id = 222
            test_utils.create_connection(connection_id=connection_id)

            label = ''
            response = self.post_to_create_charts(label=label,
                                                  sql_query_id=sql_query_id,
                                                  connection_id=connection_id)
            response_dict = json.loads(response.data)

            chart = Chart.query.filter(Chart.label == label).first()

        assert response.status_code == 400
        assert not chart
示例#11
0
    def test_create_chart_requires_writer_privileges(self):
        with db.session.no_autoflush:
            sql_query_id = 111
            test_utils.create_query(query_id=sql_query_id)

            connection_id = 222
            test_utils.create_connection(connection_id=connection_id)

            label = 'my chart'
            response = self.post_to_create_charts(label=label,
                                                  sql_query_id=sql_query_id,
                                                  connection_id=connection_id,
                                                  token_type='viewer')
            response_dict = json.loads(response.data)

            chart = Chart.query.filter(Chart.label == label).first()

        assert response.status_code == 401
        assert not chart
示例#12
0
    def test_create_connection_with_invalid_input(self):
        conn = test_utils.create_connection(label='test_conn',
                                            db_type='sqlite',
                                            host='bananas')

        try:
            connection = cm.create_connection(conn)
            assert not connection
        except exc.ArgumentError:
            pass
        except:
            assert False
示例#13
0
    def create_db_with_test_data(self):
        conn = test_utils.create_connection(label='test_conn',
                                            db_type='sqlite',
                                            host='/tmp')
        connection = cm.create_connection(conn)
        connection.execute('DROP TABLE IF EXISTS "TABLE1"')
        connection.execute('CREATE TABLE "TABLE1" ('
                           'id INTEGER NOT NULL,'
                           'name VARCHAR, '
                           'PRIMARY KEY (id));')

        connection.execute(
            'INSERT INTO "TABLE1" '
            '(id, name) '
            'VALUES (1,"raw1"), (2,"raw2"), (3,"raw3"), (4,"raw4")')
        return conn