opensupports/tests/libs.rb

57 lines
1.3 KiB
Ruby
Raw Normal View History

2016-08-04 22:18:42 +02:00
$agent = Mechanize.new
2016-05-05 04:25:01 +02:00
2017-02-15 07:08:48 +01:00
def plainRequest(path, data = {}, method = 'POST')
uri = 'http://localhost:8080' + path
2017-02-15 07:08:48 +01:00
if method == 'POST'
@response = $agent.post(uri, data)
else
@response = $agent.get(uri, data)
end
return @response
end
def request(path, data = {})
2016-08-04 06:37:23 +02:00
uri = 'http://localhost:8080' + path
2016-08-04 22:18:42 +02:00
response = $agent.post(uri, data)
2016-05-05 04:25:01 +02:00
return JSON.parse(response.body)
end
class Database
def initialize()
2018-03-28 04:30:18 +02:00
mysqlHost = ENV['MYSQL_HOST'] || '127.0.0.1'
mysqlUser = ENV['MYSQL_USER'] || 'root'
mysqlPass = ENV['MYSQL_PASSWORD'] || ''
2018-03-28 04:30:18 +02:00
@connection = Mysql.new(mysqlHost, mysqlUser, mysqlPass, 'development', 4040)
end
2016-05-05 04:25:01 +02:00
def close()
@connection.close
end
2016-05-05 04:25:01 +02:00
def getRow(table, value, field = 'id')
queryResponse = @connection.query("select * from #{table} where #{field}='#{value.to_s}'")
return queryResponse.fetch_hash
end
2016-12-29 21:25:45 +01:00
def getLastRow(table)
queryResponse = @connection.query("select * from #{table} order by id desc limit 1")
return queryResponse.fetch_hash
end
def query(query_string)
return @connection.query(query_string);
end
2016-05-05 04:25:01 +02:00
end
$database = Database.new
$staff = {
:email => 'staff@opensupports.com',
:password => 'staff'
}