Added tests for downloading files
A few notes: 1. Downloads are done through direct requests. This is due to the difficulty of downloading a file to the correct place 2. Modifiying a file will just change the file to a random 10 character string. 3. The page is reloaded in between uploads. This is due to a current caching bug that is in the process of being looked into and will be updated once it is fixed.
This commit is contained in:
@@ -4,12 +4,28 @@ Feature: Upload Files
|
||||
Scenario: Users can upload files
|
||||
Given I have opened a new course in Studio
|
||||
And I go to the files and uploads page
|
||||
When I upload the file "upload.feature"
|
||||
Then I see the file "upload.feature" was uploaded
|
||||
When I upload the file "test"
|
||||
Then I see the file "test" was uploaded
|
||||
And The url for the file "test" is valid
|
||||
|
||||
Scenario: Users can update files
|
||||
Given I have opened a new course in studio
|
||||
And I go to the files and uploads page
|
||||
When I upload the file "upload.feature"
|
||||
And I upload the file "upload.feature"
|
||||
Then I see only one "upload.feature"
|
||||
When I upload the file "test"
|
||||
And I upload the file "test"
|
||||
Then I see only one "test"
|
||||
|
||||
Scenario: Users can download files
|
||||
Given I have opened a new course in studio
|
||||
And I go to the files and uploads page
|
||||
When I upload the file "test"
|
||||
Then I can download the correct "test" file
|
||||
|
||||
Scenario: Users can download updated files
|
||||
Given I have opened a new course in studio
|
||||
And I go to the files and uploads page
|
||||
When I upload the file "test"
|
||||
And I modify "test"
|
||||
And I reload the page
|
||||
And I upload the file "test"
|
||||
Then I can download the correct "test" file
|
||||
|
||||
@@ -2,7 +2,13 @@
|
||||
#pylint: disable=W0621
|
||||
|
||||
from lettuce import world, step
|
||||
import os
|
||||
from django.conf import settings
|
||||
import requests
|
||||
import string
|
||||
import random
|
||||
|
||||
TEST_ROOT = settings.COMMON_TEST_DATA_ROOT
|
||||
HTTP_PREFIX = "http://localhost:8001"
|
||||
|
||||
|
||||
@step(u'I go to the files and uploads page')
|
||||
@@ -21,18 +27,24 @@ def upload_file(step, file_name):
|
||||
file_css = '.file-input'
|
||||
upload = world.css_find(file_css)
|
||||
#uploading the file itself
|
||||
upload._element.send_keys(os.path.dirname(__file__) + '/' + file_name)
|
||||
upload._element.send_keys(TEST_ROOT + '/uploads/' + file_name)
|
||||
|
||||
close_css = '.close-button'
|
||||
world.css_find(close_css).click()
|
||||
|
||||
|
||||
@step(u'I see the file "([^"]*)" was uploaded')
|
||||
@step(u'I see the file "([^"]*)" was uploaded$')
|
||||
def check_upload(step, file_name):
|
||||
index = get_index(file_name)
|
||||
assert index != -1
|
||||
|
||||
|
||||
@step(u'The url for the file "([^"]*)" is valid$')
|
||||
def check_url(step, file_name):
|
||||
r = get_file(file_name)
|
||||
assert r.status_code == 200
|
||||
|
||||
|
||||
@step(u'I see only one "([^"]*)"$')
|
||||
def no_duplicate(step, file_name):
|
||||
names_css = '.name-col > a.filename'
|
||||
@@ -44,6 +56,24 @@ def no_duplicate(step, file_name):
|
||||
assert only_one
|
||||
|
||||
|
||||
@step(u'I can download the correct "([^"]*)" file$')
|
||||
def check_download(step, file_name):
|
||||
cur_file = open(TEST_ROOT + '/uploads/' + file_name, 'r')
|
||||
cur_text = cur_file.read()
|
||||
r = get_file(file_name)
|
||||
downloaded_text = r.text
|
||||
assert cur_text == downloaded_text
|
||||
cur_file.close()
|
||||
|
||||
|
||||
@step(u'I modify "([^"]*)"$')
|
||||
def modify_upload(step, file_name):
|
||||
new_text = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(10))
|
||||
cur_file = open(TEST_ROOT + '/uploads/' + file_name, 'w')
|
||||
cur_file.write(new_text)
|
||||
cur_file.close()
|
||||
|
||||
|
||||
def get_index(file_name):
|
||||
names_css = '.name-col > a.filename'
|
||||
all_names = world.css_find(names_css)
|
||||
@@ -51,3 +81,12 @@ def get_index(file_name):
|
||||
if file_name == all_names[i].html:
|
||||
return i
|
||||
return -1
|
||||
|
||||
|
||||
def get_file(file_name):
|
||||
index = get_index(file_name)
|
||||
assert index != -1
|
||||
|
||||
url_css = 'input.embeddable-xml-input'
|
||||
url = world.css_find(url_css)[index].value
|
||||
return requests.get(HTTP_PREFIX + url)
|
||||
|
||||
1
common/test/data/uploads/test
Normal file
1
common/test/data/uploads/test
Normal file
@@ -0,0 +1 @@
|
||||
R22VMJ2M
|
||||
Reference in New Issue
Block a user