summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2018-05-31 17:30:13 +0200
committerRémy Coutable <remy@rymai.me>2018-06-04 16:17:37 +0200
commit018bc92defad7daa234ffea16c2921b9dcba933d (patch)
tree97cb3f45d47259c540bd4abf6e07b1906d530369
parent9c2961947826442e780285cb551583b09cf6dae9 (diff)
downloadgitlab-ce-qa-251-api-tests.tar.gz
Automate the basic API tests in a QA scenarioqa-251-api-tests
Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r--qa/qa/specs/features/api/basics_spec.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/qa/qa/specs/features/api/basics_spec.rb b/qa/qa/specs/features/api/basics_spec.rb
new file mode 100644
index 00000000000..b5e9981425e
--- /dev/null
+++ b/qa/qa/specs/features/api/basics_spec.rb
@@ -0,0 +1,61 @@
+require 'securerandom'
+
+module QA
+ feature 'API basics', :core do
+ before(:context) do
+ @api_client = Runtime::API::Client.new(:gitlab)
+ end
+
+ let(:project_name) { "api-basics-#{SecureRandom.hex(8)}" }
+ let(:sanitized_project_path) { CGI.escape("#{Runtime::User.name}/#{project_name}") }
+
+ scenario 'user creates a project with a file and deletes them afterwards' do
+ create_project_request = Runtime::API::Request.new(@api_client, "/projects?path=#{project_name}&name=#{project_name}")
+ post create_project_request.url
+
+ expect_status(201)
+ expect(json_body).to match(
+ a_hash_including(name: project_name, path: project_name)
+ )
+
+ create_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/README%2Emd?branch=master&content=Hello+world&commit_message=Add+README%2Emd")
+ post create_file_request.url
+
+ expect_status(201)
+ expect(json_body).to match(
+ a_hash_including(branch: 'master', file_path: 'README.md')
+ )
+
+ get_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/README%2Emd?ref=master")
+ get get_file_request.url
+
+ expect_status(200)
+ expect(json_body).to match(
+ a_hash_including(
+ ref: 'master',
+ file_path: 'README.md', file_name: 'README.md',
+ encoding: 'base64', content: 'SGVsbG8gd29ybGQ='
+ )
+ )
+
+ delete_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/README%2Emd?branch=master&commit_message=Remove+README%2Emd")
+ delete delete_file_request.url
+
+ expect_status(204)
+
+ get_tree_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/tree")
+ get get_tree_request.url
+
+ expect_status(200)
+ expect(json_body).to eq([])
+
+ delete_project_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}")
+ delete delete_project_request.url
+
+ expect_status(202)
+ expect(json_body).to match(
+ a_hash_including(message: '202 Accepted')
+ )
+ end
+ end
+end