Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

STCC-180 Reimplement test_can_request_project_info_for_id #123

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Scratch2Catrobat Converter
short_name: S2CC
version: 0.10.0
build_name: Aegean cat
build_number: 984
build_number: 985

;-------------------------------------------------------------------------------
[CATROBAT]
Expand Down
22 changes: 8 additions & 14 deletions src/scratchtocatrobat/scratch/scratchwebapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,29 +274,23 @@ def extract_project_details(project_id, escape_quotes=True):

extracted_text = getMetaDataEntry(project_id , "history")
extracted_text = extracted_text["modified"]
if extracted_text is None: return None
modified_date_str = unicode(extracted_text).replace("Modified:", "").replace("Z","000").strip()
try:
modified_date = datetime.strptime(modified_date_str, "%Y-%m-%dT%H:%M:%S.%f")
except:
modified_date = None
modified_date = convertHistoryDatesToDatetime(extracted_text)

extracted_text = getMetaDataEntry(project_id , "history")
extracted_text = extracted_text["shared"]
if extracted_text is None: return None
shared_date_str = unicode(extracted_text).replace("Shared:", "").replace("Z","000").strip()
try:
shared_date = datetime.strptime(shared_date_str, "%Y-%m-%dT%H:%M:%S.%f")
except:
shared_date = None
shared_date = convertHistoryDatesToDatetime(extracted_text)

return ScratchProjectInfo(title = title, owner = owner, image_url = image_url,
instructions = instructions, notes_and_credits = notes_and_credits,
tags = remixes, views = views, favorites = favorites, loves = loves,
modified_date = modified_date, shared_date = shared_date)



def convertHistoryDatesToDatetime(data):
try:
datestring = unicode(data).replace("Z","000").strip()
return datetime.strptime(datestring, "%Y-%m-%dT%H:%M:%S.%f")
except:
return None

def getMetaDataEntry(projectID, *entryKey):
try:
Expand Down
105 changes: 26 additions & 79 deletions src/scratchtocatrobat/scratch/test_scratchwebapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
}

TEST_PROJECT_ID_TO_IMAGE_URL_MAP = {
"10205819": "https://uploads.scratch.mit.edu/projects/thumbnails/10205819.png",
"10132588": "https://uploads.scratch.mit.edu/projects/thumbnails/10132588.png",
"2365565" : "https://uploads.scratch.mit.edu/projects/thumbnails/2365565.png",
"117300839": "https://uploads.scratch.mit.edu/projects/thumbnails/117300839.png"
"10205819": "https://cdn2.scratch.mit.edu/get_image/project/10205819_480x360.png",
"10132588": "https://cdn2.scratch.mit.edu/get_image/project/10132588_480x360.png",
"2365565" : "https://cdn2.scratch.mit.edu/get_image/project/2365565_480x360.png",
"117300839": "https://cdn2.scratch.mit.edu/get_image/project/117300839_480x360.png"
}

TEST_PROJECT_ID_TO_OWNER_MAP = {
Expand Down Expand Up @@ -245,13 +245,6 @@
}]
}

TEST_PROJECT_ID_TO_TAGS_MAP = {
"10205819": ['animations', 'castle'],
"10132588": ['music', 'simulations', 'animations'],
"2365565" : [],
"117300839": []
}

TEST_PROJECT_ID_TO_INSTRUCTIONS_MAP = {
"10205819": "Click the flag to run the stack. Click the space bar to change it up!",
"10132588": "D,4,8 for the animals to move.C,A for background. ",
Expand Down Expand Up @@ -297,40 +290,6 @@ def test_can_request_project_code_for_id(self):
raw_project = scratch.RawProject.from_project_code_content(project_code_content)
assert raw_project is not None

def test_can_request_project_title_for_id(self):
for (project_id, expected_project_title) in TEST_PROJECT_ID_TO_TITLE_MAP.iteritems():
extracted_project_title = scratchwebapi.getMetaDataEntry(project_id, 'title')
assert extracted_project_title is not None
assert extracted_project_title == expected_project_title, \
"'{}' is not equal to '{}'".format(extracted_project_title, expected_project_title)

def test_can_request_project_title_and_image_for_id(self):
extracted_project_title, image = scratchwebapi.getMetaDataEntry(10205819, "title", "image")
assert extracted_project_title == "Dancin' in the Castle"
assert image == "https://cdn2.scratch.mit.edu/get_image/project/10205819_480x360.png"

def test_can_request_project_owner_for_id(self):
for (project_id, expected_project_owner) in TEST_PROJECT_ID_TO_OWNER_MAP.iteritems():
extracted_project_owner = scratchwebapi.getMetaDataEntry(project_id, 'username')

assert extracted_project_owner is not None
assert extracted_project_owner == expected_project_owner, \
"'{}' is not equal to '{}'".format(extracted_project_owner, expected_project_owner)

def test_can_request_project_instructions_for_id(self):
for (project_id, expected_project_instructions) in TEST_PROJECT_ID_TO_INSTRUCTIONS_MAP.iteritems():
extracted_project_instructions = scratchwebapi.getMetaDataEntry(project_id, 'instructions')
assert extracted_project_instructions== expected_project_instructions, \
"'{}' is not equal to '{}'".format(extracted_project_instructions, expected_project_instructions)

def test_can_request_project_notes_and_credits_for_id(self):
for (project_id, expected_project_notes_and_credits) in TEST_PROJECT_ID_TO_NOTES_AND_CREDITS_MAP.iteritems():
extracted_project_notes_and_credits = scratchwebapi.getMetaDataEntry(project_id, 'description')
assert extracted_project_notes_and_credits is not None
assert extracted_project_notes_and_credits == expected_project_notes_and_credits, \
"'{}' is not equal to '{}'".format(extracted_project_notes_and_credits,
expected_project_notes_and_credits)

def test_can_request_remixes_for_id(self):
for (project_id, expected_project_remixes) in TEST_PROJECT_ID_TO_REMIXES_MAP.iteritems():
extracted_project_remixes = scratchwebapi.request_project_remixes_for(project_id)
Expand All @@ -345,40 +304,28 @@ def test_extract_project_details(self):
assert details.as_dict()["modified_date"] != None
assert details.as_dict()["shared_date"] != None

# def test_can_request_project_info_for_id(self):
# for (project_id, expected_project_title) in TEST_PROJECT_ID_TO_TITLE_MAP.iteritems():
# extracted_project_info = scratchwebapi.request_project_details_for(project_id)
# assert extracted_project_info is not None
# assert isinstance(extracted_project_info, scratchwebapi.ScratchProjectInfo)
# assert extracted_project_info.title is not None
# assert extracted_project_info.title == expected_project_title, \
# "'{}' is not equal to '{}'".format(extracted_project_info.title, expected_project_title)
# assert extracted_project_info.owner is not None
# assert extracted_project_info.owner == TEST_PROJECT_ID_TO_OWNER_MAP[project_id], \
# "'{}' is not equal to '{}'".format(extracted_project_info.owner, TEST_PROJECT_ID_TO_OWNER_MAP[project_id])
# assert extracted_project_info.image_url is not None
# assert extracted_project_info.image_url == TEST_PROJECT_ID_TO_IMAGE_URL_MAP[project_id], \
# "'{}' is not equal to '{}'".format(extracted_project_info.image_url, TEST_PROJECT_ID_TO_IMAGE_URL_MAP[project_id])
# assert extracted_project_info.instructions == TEST_PROJECT_ID_TO_INSTRUCTIONS_MAP[project_id], \
# "'{}' is not equal to '{}'".format(extracted_project_info.instructions, TEST_PROJECT_ID_TO_INSTRUCTIONS_MAP[project_id])
# assert extracted_project_info.notes_and_credits == TEST_PROJECT_ID_TO_NOTES_AND_CREDITS_MAP[project_id], \
# "'{}' is not equal to '{}'".format(extracted_project_info.notes_and_credits, TEST_PROJECT_ID_TO_NOTES_AND_CREDITS_MAP[project_id])
# assert extracted_project_info.tags is not None
# assert extracted_project_info.tags == TEST_PROJECT_ID_TO_TAGS_MAP[project_id], \
# "'{}' is not equal to '{}'".format(extracted_project_info.tags, TEST_PROJECT_ID_TO_TAGS_MAP[project_id])
# assert extracted_project_info.views is not None
# assert isinstance(extracted_project_info.views, int)
# assert extracted_project_info.views > 0
# assert extracted_project_info.favorites is not None
# assert extracted_project_info.favorites >= 0
# assert isinstance(extracted_project_info.favorites, int)
# assert extracted_project_info.loves is not None
# assert extracted_project_info.loves >= 0
# assert isinstance(extracted_project_info.loves, int)
# assert extracted_project_info.modified_date is not None
# assert isinstance(extracted_project_info.modified_date, datetime)
# assert extracted_project_info.shared_date is not None
# assert isinstance(extracted_project_info.shared_date, datetime)
def test_can_request_project_info_for_id(self):
for (project_id, expected_project_title) in TEST_PROJECT_ID_TO_TITLE_MAP.iteritems():
title, owner, image_url, instructions, notes_and_credits, stats, history\
= scratchwebapi.getMetaDataEntry(project_id, 'title', 'username', 'image', 'instructions', 'description', 'stats', 'history')
assert title == expected_project_title, \
"'{}' is not equal to '{}'".format(title, expected_project_title)
assert owner == TEST_PROJECT_ID_TO_OWNER_MAP[project_id], \
"'{}' is not equal to '{}'".format(owner, TEST_PROJECT_ID_TO_OWNER_MAP[project_id])
assert image_url == TEST_PROJECT_ID_TO_IMAGE_URL_MAP[project_id], \
"'{}' is not equal to '{}'".format(image_url, TEST_PROJECT_ID_TO_IMAGE_URL_MAP[project_id])
assert instructions == TEST_PROJECT_ID_TO_INSTRUCTIONS_MAP[project_id], \
"'{}' is not equal to '{}'".format(instructions, TEST_PROJECT_ID_TO_INSTRUCTIONS_MAP[project_id])
assert notes_and_credits == TEST_PROJECT_ID_TO_NOTES_AND_CREDITS_MAP[project_id], \
"'{}' is not equal to '{}'".format(notes_and_credits, TEST_PROJECT_ID_TO_NOTES_AND_CREDITS_MAP[project_id])
assert isinstance(stats['views'], int)
assert stats['views'] > 0
assert isinstance(stats['favorites'], int)
assert stats['favorites'] >= 0
assert isinstance(stats['loves'], int)
assert stats['loves'] >= 0
assert isinstance(scratchwebapi.convertHistoryDatesToDatetime(history['modified']), datetime)
assert isinstance(scratchwebapi.convertHistoryDatesToDatetime(history['shared']), datetime)

def test_can_detect_correct_availability_state_of_project(self):
project_availability_map = {
Expand Down