Skip to content

Commit 4807635

Browse files
sandra0521AntiDog
authored andcommitted
STCC-180 Reimplement test_can_request_project_info_for_id (#123)
1 parent 59c22cf commit 4807635

File tree

3 files changed

+35
-94
lines changed

3 files changed

+35
-94
lines changed

config/default.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: Scratch2Catrobat Converter
44
short_name: S2CC
55
version: 0.10.0
66
build_name: Aegean cat
7-
build_number: 984
7+
build_number: 985
88

99
;-------------------------------------------------------------------------------
1010
[CATROBAT]

src/scratchtocatrobat/scratch/scratchwebapi.py

+8-14
Original file line numberDiff line numberDiff line change
@@ -274,29 +274,23 @@ def extract_project_details(project_id, escape_quotes=True):
274274

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

284279
extracted_text = getMetaDataEntry(project_id , "history")
285280
extracted_text = extracted_text["shared"]
286-
if extracted_text is None: return None
287-
shared_date_str = unicode(extracted_text).replace("Shared:", "").replace("Z","000").strip()
288-
try:
289-
shared_date = datetime.strptime(shared_date_str, "%Y-%m-%dT%H:%M:%S.%f")
290-
except:
291-
shared_date = None
281+
shared_date = convertHistoryDatesToDatetime(extracted_text)
292282

293283
return ScratchProjectInfo(title = title, owner = owner, image_url = image_url,
294284
instructions = instructions, notes_and_credits = notes_and_credits,
295285
tags = remixes, views = views, favorites = favorites, loves = loves,
296286
modified_date = modified_date, shared_date = shared_date)
297287

298-
299-
288+
def convertHistoryDatesToDatetime(data):
289+
try:
290+
datestring = unicode(data).replace("Z","000").strip()
291+
return datetime.strptime(datestring, "%Y-%m-%dT%H:%M:%S.%f")
292+
except:
293+
return None
300294

301295
def getMetaDataEntry(projectID, *entryKey):
302296
try:

src/scratchtocatrobat/scratch/test_scratchwebapi.py

+26-79
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
}
3737

3838
TEST_PROJECT_ID_TO_IMAGE_URL_MAP = {
39-
"10205819": "https://uploads.scratch.mit.edu/projects/thumbnails/10205819.png",
40-
"10132588": "https://uploads.scratch.mit.edu/projects/thumbnails/10132588.png",
41-
"2365565" : "https://uploads.scratch.mit.edu/projects/thumbnails/2365565.png",
42-
"117300839": "https://uploads.scratch.mit.edu/projects/thumbnails/117300839.png"
39+
"10205819": "https://cdn2.scratch.mit.edu/get_image/project/10205819_480x360.png",
40+
"10132588": "https://cdn2.scratch.mit.edu/get_image/project/10132588_480x360.png",
41+
"2365565" : "https://cdn2.scratch.mit.edu/get_image/project/2365565_480x360.png",
42+
"117300839": "https://cdn2.scratch.mit.edu/get_image/project/117300839_480x360.png"
4343
}
4444

4545
TEST_PROJECT_ID_TO_OWNER_MAP = {
@@ -245,13 +245,6 @@
245245
}]
246246
}
247247

248-
TEST_PROJECT_ID_TO_TAGS_MAP = {
249-
"10205819": ['animations', 'castle'],
250-
"10132588": ['music', 'simulations', 'animations'],
251-
"2365565" : [],
252-
"117300839": []
253-
}
254-
255248
TEST_PROJECT_ID_TO_INSTRUCTIONS_MAP = {
256249
"10205819": "Click the flag to run the stack. Click the space bar to change it up!",
257250
"10132588": "D,4,8 for the animals to move.C,A for background. ",
@@ -297,40 +290,6 @@ def test_can_request_project_code_for_id(self):
297290
raw_project = scratch.RawProject.from_project_code_content(project_code_content)
298291
assert raw_project is not None
299292

300-
def test_can_request_project_title_for_id(self):
301-
for (project_id, expected_project_title) in TEST_PROJECT_ID_TO_TITLE_MAP.iteritems():
302-
extracted_project_title = scratchwebapi.getMetaDataEntry(project_id, 'title')
303-
assert extracted_project_title is not None
304-
assert extracted_project_title == expected_project_title, \
305-
"'{}' is not equal to '{}'".format(extracted_project_title, expected_project_title)
306-
307-
def test_can_request_project_title_and_image_for_id(self):
308-
extracted_project_title, image = scratchwebapi.getMetaDataEntry(10205819, "title", "image")
309-
assert extracted_project_title == "Dancin' in the Castle"
310-
assert image == "https://cdn2.scratch.mit.edu/get_image/project/10205819_480x360.png"
311-
312-
def test_can_request_project_owner_for_id(self):
313-
for (project_id, expected_project_owner) in TEST_PROJECT_ID_TO_OWNER_MAP.iteritems():
314-
extracted_project_owner = scratchwebapi.getMetaDataEntry(project_id, 'username')
315-
316-
assert extracted_project_owner is not None
317-
assert extracted_project_owner == expected_project_owner, \
318-
"'{}' is not equal to '{}'".format(extracted_project_owner, expected_project_owner)
319-
320-
def test_can_request_project_instructions_for_id(self):
321-
for (project_id, expected_project_instructions) in TEST_PROJECT_ID_TO_INSTRUCTIONS_MAP.iteritems():
322-
extracted_project_instructions = scratchwebapi.getMetaDataEntry(project_id, 'instructions')
323-
assert extracted_project_instructions== expected_project_instructions, \
324-
"'{}' is not equal to '{}'".format(extracted_project_instructions, expected_project_instructions)
325-
326-
def test_can_request_project_notes_and_credits_for_id(self):
327-
for (project_id, expected_project_notes_and_credits) in TEST_PROJECT_ID_TO_NOTES_AND_CREDITS_MAP.iteritems():
328-
extracted_project_notes_and_credits = scratchwebapi.getMetaDataEntry(project_id, 'description')
329-
assert extracted_project_notes_and_credits is not None
330-
assert extracted_project_notes_and_credits == expected_project_notes_and_credits, \
331-
"'{}' is not equal to '{}'".format(extracted_project_notes_and_credits,
332-
expected_project_notes_and_credits)
333-
334293
def test_can_request_remixes_for_id(self):
335294
for (project_id, expected_project_remixes) in TEST_PROJECT_ID_TO_REMIXES_MAP.iteritems():
336295
extracted_project_remixes = scratchwebapi.request_project_remixes_for(project_id)
@@ -345,40 +304,28 @@ def test_extract_project_details(self):
345304
assert details.as_dict()["modified_date"] != None
346305
assert details.as_dict()["shared_date"] != None
347306

348-
# def test_can_request_project_info_for_id(self):
349-
# for (project_id, expected_project_title) in TEST_PROJECT_ID_TO_TITLE_MAP.iteritems():
350-
# extracted_project_info = scratchwebapi.request_project_details_for(project_id)
351-
# assert extracted_project_info is not None
352-
# assert isinstance(extracted_project_info, scratchwebapi.ScratchProjectInfo)
353-
# assert extracted_project_info.title is not None
354-
# assert extracted_project_info.title == expected_project_title, \
355-
# "'{}' is not equal to '{}'".format(extracted_project_info.title, expected_project_title)
356-
# assert extracted_project_info.owner is not None
357-
# assert extracted_project_info.owner == TEST_PROJECT_ID_TO_OWNER_MAP[project_id], \
358-
# "'{}' is not equal to '{}'".format(extracted_project_info.owner, TEST_PROJECT_ID_TO_OWNER_MAP[project_id])
359-
# assert extracted_project_info.image_url is not None
360-
# assert extracted_project_info.image_url == TEST_PROJECT_ID_TO_IMAGE_URL_MAP[project_id], \
361-
# "'{}' is not equal to '{}'".format(extracted_project_info.image_url, TEST_PROJECT_ID_TO_IMAGE_URL_MAP[project_id])
362-
# assert extracted_project_info.instructions == TEST_PROJECT_ID_TO_INSTRUCTIONS_MAP[project_id], \
363-
# "'{}' is not equal to '{}'".format(extracted_project_info.instructions, TEST_PROJECT_ID_TO_INSTRUCTIONS_MAP[project_id])
364-
# assert extracted_project_info.notes_and_credits == TEST_PROJECT_ID_TO_NOTES_AND_CREDITS_MAP[project_id], \
365-
# "'{}' is not equal to '{}'".format(extracted_project_info.notes_and_credits, TEST_PROJECT_ID_TO_NOTES_AND_CREDITS_MAP[project_id])
366-
# assert extracted_project_info.tags is not None
367-
# assert extracted_project_info.tags == TEST_PROJECT_ID_TO_TAGS_MAP[project_id], \
368-
# "'{}' is not equal to '{}'".format(extracted_project_info.tags, TEST_PROJECT_ID_TO_TAGS_MAP[project_id])
369-
# assert extracted_project_info.views is not None
370-
# assert isinstance(extracted_project_info.views, int)
371-
# assert extracted_project_info.views > 0
372-
# assert extracted_project_info.favorites is not None
373-
# assert extracted_project_info.favorites >= 0
374-
# assert isinstance(extracted_project_info.favorites, int)
375-
# assert extracted_project_info.loves is not None
376-
# assert extracted_project_info.loves >= 0
377-
# assert isinstance(extracted_project_info.loves, int)
378-
# assert extracted_project_info.modified_date is not None
379-
# assert isinstance(extracted_project_info.modified_date, datetime)
380-
# assert extracted_project_info.shared_date is not None
381-
# assert isinstance(extracted_project_info.shared_date, datetime)
307+
def test_can_request_project_info_for_id(self):
308+
for (project_id, expected_project_title) in TEST_PROJECT_ID_TO_TITLE_MAP.iteritems():
309+
title, owner, image_url, instructions, notes_and_credits, stats, history\
310+
= scratchwebapi.getMetaDataEntry(project_id, 'title', 'username', 'image', 'instructions', 'description', 'stats', 'history')
311+
assert title == expected_project_title, \
312+
"'{}' is not equal to '{}'".format(title, expected_project_title)
313+
assert owner == TEST_PROJECT_ID_TO_OWNER_MAP[project_id], \
314+
"'{}' is not equal to '{}'".format(owner, TEST_PROJECT_ID_TO_OWNER_MAP[project_id])
315+
assert image_url == TEST_PROJECT_ID_TO_IMAGE_URL_MAP[project_id], \
316+
"'{}' is not equal to '{}'".format(image_url, TEST_PROJECT_ID_TO_IMAGE_URL_MAP[project_id])
317+
assert instructions == TEST_PROJECT_ID_TO_INSTRUCTIONS_MAP[project_id], \
318+
"'{}' is not equal to '{}'".format(instructions, TEST_PROJECT_ID_TO_INSTRUCTIONS_MAP[project_id])
319+
assert notes_and_credits == TEST_PROJECT_ID_TO_NOTES_AND_CREDITS_MAP[project_id], \
320+
"'{}' is not equal to '{}'".format(notes_and_credits, TEST_PROJECT_ID_TO_NOTES_AND_CREDITS_MAP[project_id])
321+
assert isinstance(stats['views'], int)
322+
assert stats['views'] > 0
323+
assert isinstance(stats['favorites'], int)
324+
assert stats['favorites'] >= 0
325+
assert isinstance(stats['loves'], int)
326+
assert stats['loves'] >= 0
327+
assert isinstance(scratchwebapi.convertHistoryDatesToDatetime(history['modified']), datetime)
328+
assert isinstance(scratchwebapi.convertHistoryDatesToDatetime(history['shared']), datetime)
382329

383330
def test_can_detect_correct_availability_state_of_project(self):
384331
project_availability_map = {

0 commit comments

Comments
 (0)