def test_then_json_pointer_is_any_float(self):
     path = util.rand_string()
     self.ctx.zato.response.data_impl[path] = util.rand_int()
     self.assertRaises(AssertionError, json.then_json_pointer_is_any_float,
                       self.ctx, '/' + path)
     self.ctx.zato.response.data_impl[path] = util.rand_float()
     self.assertTrue(
         json.then_json_pointer_is_any_float(self.ctx, '/' + path))
Example #2
0
 def test_given_i_store_sql_query_result_under_name_multi_elem_list(self):
     id = util.rand_int()
     name = util.rand_string()
     value = util.rand_string()
     self.cursor.execute("INSERT INTO TestDB (id, name, value) VALUES (?,?,?)", (id, name, value))
     self.conn.commit()
     q = 'SELECT name FROM TestDb'
     sql.given_i_store_sql_query_result_under_name(self.ctx, q, 'sql_result_multi', self.general_conn)
     self.assertEquals(self.ctx.zato.user_ctx['sql_result_multi'], [(self.name,), (name,)])
Example #3
0
    def test_given_i_store_zato_info_under_conn_name(self):
        conn_name = util.rand_string()
        cluster_id = util.rand_int()
        url_path = util.rand_string()
        username = util.rand_string()
        password = util.rand_string()
        zato_.given_i_store_zato_info_under_conn_name(self.ctx, cluster_id, url_path, username, password, conn_name)
        stored = self.ctx.zato.user_ctx[conn_name]

        for key in stored:
            self.assertEquals(stored[key], eval(key))
Example #4
0
    def test_i_create_table_and_insert_data_from_csv_file_using_types_and_header(self, open_mock):
        values = (util.rand_string(), util.rand_int(), util.rand_string())
        fake_csv = 'a-text, b:integer, c/varchar:30\n%s, %s, %s' % values
        kwargs = {'filename': util.rand_string(),
                    'tablename': util.rand_string(),
                    'conn_name': self.conn}

        open_mock.return_value = StringIO(fake_csv)
        sql.insert_csv(use_header=1, use_types=1, **kwargs)

        q = self.conn.execute('SELECT * FROM {tn}'.format(tn = kwargs['tablename']))
        result = q.fetchone()
        self.assertEquals(result, values)
Example #5
0
    def test_i_insert_data_from_csv_file(self, open_mock):
        values = (util.rand_int(), util.rand_string(), util.rand_string())
        fake_csv = 'id, name, value\n%s, %s, %s' % values
        kwargs = {'filename': util.rand_string(),
                    'tablename': 'TestDB',
                    'conn_name': self.general_conn}

        open_mock.return_value = StringIO(fake_csv)
        sql.insert_csv(use_header=1, **kwargs)

        q = self.general_conn.execute('SELECT * FROM TestDB')
        result = q.fetchall()[1]
        self.assertEquals(result, values)
Example #6
0
    def setUp(self):
        self.ctx = Bunch()
        self.ctx.zato = util.new_context(None, util.rand_string(), {})

        self.fake_service_code = util.rand_string()

        conn_name = util.rand_string()
        cluster_id = util.rand_int()
        url_path = util.rand_string()
        username = util.rand_string()
        password = util.rand_string()
        zato_.given_i_store_zato_info_under_conn_name(self.ctx, cluster_id, url_path, username, password, conn_name)
        self.stored = self.ctx.zato.user_ctx[conn_name]
Example #7
0
    def test_given_i_store_zato_info_under_conn_name(self):
        conn_name = util.rand_string()
        cluster_id = util.rand_int()
        url_path = util.rand_string()
        username = util.rand_string()
        password = util.rand_string()
        zato_.given_i_store_zato_info_under_conn_name(self.ctx, cluster_id,
                                                      url_path, username,
                                                      password, conn_name)
        stored = self.ctx.zato.user_ctx[conn_name]

        for key in stored:
            self.assertEquals(stored[key], eval(key))
Example #8
0
 def test_given_i_store_sql_query_result_under_name_multi_elem_list(self):
     id = util.rand_int()
     name = util.rand_string()
     value = util.rand_string()
     self.cursor.execute(
         "INSERT INTO TestDB (id, name, value) VALUES (?,?,?)",
         (id, name, value))
     self.conn.commit()
     q = 'SELECT name FROM TestDb'
     sql.given_i_store_sql_query_result_under_name(self.ctx, q,
                                                   'sql_result_multi',
                                                   self.general_conn)
     self.assertEquals(self.ctx.zato.user_ctx['sql_result_multi'],
                       [(self.name, ), (name, )])
Example #9
0
    def test_i_insert_data_from_csv_file(self, open_mock):
        values = (util.rand_int(), util.rand_string(), util.rand_string())
        fake_csv = 'id, name, value\n%s, %s, %s' % values
        kwargs = {
            'filename': util.rand_string(),
            'tablename': 'TestDB',
            'conn_name': self.general_conn
        }

        open_mock.return_value = StringIO(fake_csv)
        sql.insert_csv(use_header=1, **kwargs)

        q = self.general_conn.execute('SELECT * FROM TestDB')
        result = q.fetchall()[1]
        self.assertEquals(result, values)
Example #10
0
    def test_i_create_table_and_insert_data_from_csv_file_using_header(self, open_mock):
        colnames = (tuple((element) for element in util.rand_string(5)))
        values = (util.rand_string(), util.rand_string(), util.rand_int(), round(util.rand_float(), 4), util.rand_string())
        t = colnames + values
        fake_csv = '%s, %s, %s, %s, %s\ntext, varchar:30, integer, float, char\n%s, %s, %s, %s, %s' % t
        kwargs = {'filename': util.rand_string(),
                    'tablename': util.rand_string(),
                    'conn_name': self.conn}

        open_mock.return_value = StringIO(fake_csv)
        sql.insert_csv(use_header=1, use_types=0, **kwargs)

        q = self.conn.execute('SELECT * FROM {tn}'.format(tn = kwargs['tablename']))
        result = q.fetchone()
        self.assertEquals(result, values)
Example #11
0
    def setUp(self):
        self.ctx = Bunch()
        self.ctx.zato = util.new_context(None, util.rand_string(), {})

        self.fake_service_code = util.rand_string()

        conn_name = util.rand_string()
        cluster_id = util.rand_int()
        url_path = util.rand_string()
        username = util.rand_string()
        password = util.rand_string()
        zato_.given_i_store_zato_info_under_conn_name(self.ctx, cluster_id,
                                                      url_path, username,
                                                      password, conn_name)
        self.stored = self.ctx.zato.user_ctx[conn_name]
Example #12
0
    def test_i_create_table_and_insert_data_from_csv_file_using_types_and_header(
            self, open_mock):
        values = (util.rand_string(), util.rand_int(), util.rand_string())
        fake_csv = 'a-text, b:integer, c/varchar:30\n%s, %s, %s' % values
        kwargs = {
            'filename': util.rand_string(),
            'tablename': util.rand_string(),
            'conn_name': self.conn
        }

        open_mock.return_value = StringIO(fake_csv)
        sql.insert_csv(use_header=1, use_types=1, **kwargs)

        q = self.conn.execute(
            'SELECT * FROM {tn}'.format(tn=kwargs['tablename']))
        result = q.fetchone()
        self.assertEquals(result, values)
Example #13
0
    def setUp(self):
        self.ctx = Bunch()
        self.ctx.zato = util.new_context(None, util.rand_string(), {})

        self.id = util.rand_int()
        self.name = util.rand_string()
        self.value = util.rand_string()
        self.temp_db = NamedTemporaryFile().name

        self.conn = sqlite3.connect(self.temp_db)
        self.cursor = self.conn.cursor()
        self.cursor.execute("CREATE TABLE TestDB (id integer, name text, value text)")
        self.cursor.execute("INSERT INTO TestDB (id, name, value) VALUES (?,?,?)", (self.id, self.name, self.value))
        self.conn.commit()

        self.sqlalchemy_url = 'sqlite:///' + self.temp_db
        general_conn_name = 'general_connn_name'
        sql.given_i_connect_to_sqlalchemy_url_as_conn_name(self.ctx, self.sqlalchemy_url, general_conn_name)
        self.general_conn = self.ctx.zato.user_ctx[general_conn_name]
Example #14
0
    def test_i_create_table_and_insert_data_from_csv_file_using_header(
            self, open_mock):
        colnames = (tuple((element) for element in util.rand_string(5)))
        values = (util.rand_string(), util.rand_string(), util.rand_int(),
                  round(util.rand_float(), 4), util.rand_string())
        t = colnames + values
        fake_csv = '%s, %s, %s, %s, %s\ntext, varchar:30, integer, float, char\n%s, %s, %s, %s, %s' % t
        kwargs = {
            'filename': util.rand_string(),
            'tablename': util.rand_string(),
            'conn_name': self.conn
        }

        open_mock.return_value = StringIO(fake_csv)
        sql.insert_csv(use_header=1, use_types=0, **kwargs)

        q = self.conn.execute(
            'SELECT * FROM {tn}'.format(tn=kwargs['tablename']))
        result = q.fetchone()
        self.assertEquals(result, values)
Example #15
0
    def setUp(self):
        self.ctx = Bunch()
        self.ctx.zato = util.new_context(None, util.rand_string(), {})

        self.id = util.rand_int()
        self.name = util.rand_string()
        self.value = util.rand_string()
        self.temp_db = NamedTemporaryFile().name

        self.conn = sqlite3.connect(self.temp_db)
        self.cursor = self.conn.cursor()
        self.cursor.execute(
            "CREATE TABLE TestDB (id integer, name text, value text)")
        self.cursor.execute(
            "INSERT INTO TestDB (id, name, value) VALUES (?,?,?)",
            (self.id, self.name, self.value))
        self.conn.commit()

        self.sqlalchemy_url = 'sqlite:///' + self.temp_db
        general_conn_name = 'general_connn_name'
        sql.given_i_connect_to_sqlalchemy_url_as_conn_name(
            self.ctx, self.sqlalchemy_url, general_conn_name)
        self.general_conn = self.ctx.zato.user_ctx[general_conn_name]
Example #16
0
 def test_then_status_is_needs_an_int(self):
     expected = util.rand_string()
     actual = util.rand_int()
     self.ctx.zato.response.data.status_code = actual
     self.assertRaises(ValueError, common.then_status_is, self.ctx,
                       expected)
Example #17
0
 def test_then_json_pointer_is_an_integer(self):
     path = util.rand_string()
     value = util.rand_int()
     self.ctx.zato.response.data_impl[path] = value + 1
     self.assertRaises(AssertionError, json.then_json_pointer_is_an_integer,
                       self.ctx, '/' + path, value)
Example #18
0
 def test_then_status_is_needs_an_int(self):
     expected = util.rand_string()
     actual = util.rand_int()
     self.ctx.zato.response.data.status_code = actual
     self.assertRaises(ValueError, common.then_status_is, self.ctx, expected)
Example #19
0
 def test_then_json_pointer_is_any_float(self):
     path = util.rand_string()
     self.ctx.zato.response.data_impl[path] = util.rand_int()
     self.assertRaises(AssertionError, json.then_json_pointer_is_any_float, self.ctx, '/' + path)
     self.ctx.zato.response.data_impl[path] = util.rand_float()
     self.assertTrue(json.then_json_pointer_is_any_float(self.ctx, '/' + path))
Example #20
0
 def test_given_json_pointer_in_request_is_an_integer(self):
     path = util.rand_string()
     value = util.rand_int()
     json.given_json_pointer_in_request_is_an_integer(
         self.ctx, '/' + path, value)
     self.assertEquals(self.ctx.zato.request.data_impl[path], int(value))
Example #21
0
 def test_then_status_is_not_ok(self):
     expected, actual = util.rand_int(count=2)
     self.ctx.zato.response.data.status_code = actual
     self.assertRaises(AssertionError, common.then_status_is, self.ctx,
                       expected)
Example #22
0
 def test_then_status_is_ok(self):
     expected = actual = util.rand_int()
     self.ctx.zato.response.data.status_code = actual
     self.assertTrue(common.then_status_is(self.ctx, expected))
Example #23
0
 def test_then_json_pointer_is_an_integer(self):
     path = util.rand_string()
     value = util.rand_int()
     self.ctx.zato.response.data_impl[path] = value + 1
     self.assertRaises(AssertionError, json.then_json_pointer_is_an_integer, self.ctx, '/' + path, value)
Example #24
0
 def test_then_status_is_ok(self):
     expected = actual = util.rand_int()
     self.ctx.zato.response.data.status_code = actual
     self.assertTrue(common.then_status_is(self.ctx, expected))
Example #25
0
 def test_given_json_pointer_in_request_is_an_integer(self):
     path = util.rand_string()
     value = util.rand_int()
     json.given_json_pointer_in_request_is_an_integer(self.ctx, '/' + path, value)
     self.assertEquals(self.ctx.zato.request.data_impl[path], int(value))
Example #26
0
 def test_then_status_is_not_ok(self):
     expected, actual = util.rand_int(count=2)
     self.ctx.zato.response.data.status_code = actual
     self.assertRaises(AssertionError, common.then_status_is, self.ctx, expected)