diff --git a/test/fixtures/__init__.py b/test/fixtures/__init__.py index e69de29..e68d33b 100644 --- a/test/fixtures/__init__.py +++ b/test/fixtures/__init__.py @@ -0,0 +1,5 @@ +def get (request, query): + return { + 'app': 'BadgeKit API', + 'version': '0.x' + } diff --git a/test/fixtures/systems/__init__.py b/test/fixtures/systems/__init__.py index 7e4fe26..1448172 100644 --- a/test/fixtures/systems/__init__.py +++ b/test/fixtures/systems/__init__.py @@ -1,8 +1,10 @@ -import system - def get (request, query): + import chicago + import pittsburgh + return { 'systems': [ - system.get(request, query)['system'] + chicago.get(request, query)['system'], + pittsburgh.get(request, query)['system'], ] } \ No newline at end of file diff --git a/test/fixtures/systems/chicago/__init__.py b/test/fixtures/systems/chicago/__init__.py new file mode 100644 index 0000000..e3cc21f --- /dev/null +++ b/test/fixtures/systems/chicago/__init__.py @@ -0,0 +1,16 @@ +data = { + 'slug': 'chicago', + 'name': 'Chicago', + 'url': 'http://cityofchicago.org', + 'imageUrl': 'http://example.org/test.png', + 'id': 1, + 'email': 'mayor-emanuel@cityofchicago.org', + 'issuers': [], +} + +def get (request, query): + import issuers + + rsp = data.copy() + rsp['issuers'] = issuers.get(request, query)['issuers'] + return {'system': rsp} diff --git a/test/fixtures/systems/chicago/badges/__init__.py b/test/fixtures/systems/chicago/badges/__init__.py new file mode 100644 index 0000000..b82a0a7 --- /dev/null +++ b/test/fixtures/systems/chicago/badges/__init__.py @@ -0,0 +1,75 @@ +def get (request, query): + import badge + import archived + from ..issuers.library.badges import library + from ..issuers.library.programs.mit.badges import scratch + + badges = [ + badge.get(request, query)['badge'], + archived.get(request, query)['badge'], + library.get(request, query)['badge'], + scratch.get(request, query)['badge'], + ] + + if query.get('archived') != 'any': + badges = [badge for badge in badges if not badge['archived']] + + return {'badges': badges} + +def post (request, query): + badge = request['data'] + errors = validateBadge(badge) + if len(errors): + return ({ + 'message': 'Could not validate required fields', + 'code': 'ValidationError', + 'details': [{'field': field, 'value': ''} for field in errors] + }, 400) + + return { + 'status': 'created', + 'badge': { + 'id': 99, + 'slug': badge.get('slug'), + 'name': badge.get('name'), + 'strapline': badge.get('strapline'), + 'earnerDescription': badge.get('earnerDescription'), + 'consumerDescription': badge.get('consumerDescription'), + 'issuerUrl': badge.get('issuerUrl'), + 'rubricUrl': badge.get('rubricUrl'), + 'timeValue': badge.get('timeValue'), + 'timeUnits': badge.get('timeUnits'), + 'limit': badge.get('limit'), + 'unique': badge.get('unique'), + 'created': '2014-06-17T13:14:33.000Z', + 'imageUrl': badge.get('imageUrl'), + 'type': badge.get('type'), + 'archived': False, + 'system': { + 'id': 1, + 'slug': 'chicago', + 'url': 'http://cityofchicago.org', + 'name': 'Chicago', + 'email': 'mayor-emanuel@cityofchicago.org', + 'imageUrl': None, + 'issuers': [] + }, + 'criteriaUrl': badge.get('criteriaUrl'), + 'criteria': [], + 'categories': [], + 'tags': [], + 'milestones': [] + } + } + + +def validateBadge (badge): + missing = [] + for field in required_fields: + if field not in badge: + missing.append(field) + return missing + +required_fields = ('name', 'slug', 'earnerDescription', 'consumerDescription', + 'criteriaUrl', 'unique', 'image', 'type',) + diff --git a/test/fixtures/systems/chicago/badges/archived.py b/test/fixtures/systems/chicago/badges/archived.py new file mode 100644 index 0000000..67da920 --- /dev/null +++ b/test/fixtures/systems/chicago/badges/archived.py @@ -0,0 +1,35 @@ +def get (request, query): + return { + 'badge': { + 'consumerDescription': 'A consumer description of the Archived Badge', + 'rubricUrl': 'http://example.org/archivedRubric', + 'strapline': 'An archived badge', + 'id': 2, + 'archived': True, + 'system': { + 'slug': 'chicago', + 'name': 'Chicago', + 'url': 'http://cityofchicago.org', + 'imageUrl': None, + 'id': 1, + 'email': 'mayor-emanuel@cityofchicago.org', + 'issuers': [] + }, + 'issuerUrl': 'http://example.org/archivedIssuer', + 'criteria': [], + 'type': 'Not too shabby', + 'tags': [], + 'timeUnits': 'hours', + 'unique': 1, + 'slug': 'archived', + 'categories': [], + 'earnerDescription': 'An earner description of the Archived Badge', + 'milestones': [], + 'name': 'Archived Badge', + 'created': '2014-06-17T10:27:42.000Z', + 'imageUrl': 'http://example.org/test.png', + 'timeValue': 5, + 'limit': 2, + 'criteriaUrl': 'http://example.org/archivedCriteria' + } + } diff --git a/test/fixtures/systems/chicago/badges/badge.py b/test/fixtures/systems/chicago/badges/badge.py new file mode 100644 index 0000000..e6ba1ab --- /dev/null +++ b/test/fixtures/systems/chicago/badges/badge.py @@ -0,0 +1,64 @@ +data = { + 'consumerDescription': 'A consumer description of the Chicago Badge', + 'rubricUrl': 'http://example.org/chicagoRubric', + 'strapline': 'A badge for Chicago', + 'id': 1, + 'archived': False, + 'system': { + 'slug': 'chicago', + 'name': 'Chicago', + 'url': 'http://cityofchicago.org', + 'imageUrl': None, + 'id': 1, + 'email': 'mayor-emanuel@cityofchicago.org', + 'issuers': [] + }, + 'issuerUrl': 'http://example.org/chicagoIssuer', + 'criteria': [ + { + 'note': 'Some sort of note', + 'required': 1, + 'id': 1, + 'description': 'Just your basic criterion.' + } + ], + 'type': 'Not too shabby', + 'tags': [], + 'timeUnits': 'minutes', + 'unique': 1, + 'slug': 'badge', + 'categories': [], + 'earnerDescription': 'An earner description of the Chicago Badge', + 'milestones': [], + 'name': 'Chicago Badge', + 'created': '2014-06-17T10:27:42.000Z', + 'imageUrl': 'http://example.org/test.png', + 'timeValue': 10, + 'limit': 5, + 'criteriaUrl': 'http://example.org/chicagoCriteria' +} + +def get (request, query): + return {'badge': data.copy()} + +def put (request, query): + badge = data.copy() + for key, value in request['data'].items(): + badge[key] = value + + return { + 'status': 'updated', + 'badge': badge, + } + +def delete (request, query): + if 'deleted' in data: + raise ImportError('Deleted!') + + badge = data.copy() + data['deleted'] = True + + return { + 'status': 'deleted', + 'badge': badge, + } diff --git a/test/fixtures/systems/chicago/badges/scratch.py b/test/fixtures/systems/chicago/badges/scratch.py new file mode 100644 index 0000000..bf19095 --- /dev/null +++ b/test/fixtures/systems/chicago/badges/scratch.py @@ -0,0 +1 @@ +from ..issuers.library.programs.mit.badges.scratch import * \ No newline at end of file diff --git a/test/fixtures/systems/chicago/issuers/__init__.py b/test/fixtures/systems/chicago/issuers/__init__.py new file mode 100644 index 0000000..5b28058 --- /dev/null +++ b/test/fixtures/systems/chicago/issuers/__init__.py @@ -0,0 +1,8 @@ +def get (request, query): + import library + + return { + 'issuers': [ + library.get(request, query)['issuer'], + ] + } diff --git a/test/fixtures/systems/chicago/issuers/library/__init__.py b/test/fixtures/systems/chicago/issuers/library/__init__.py new file mode 100644 index 0000000..dc3a58c --- /dev/null +++ b/test/fixtures/systems/chicago/issuers/library/__init__.py @@ -0,0 +1,17 @@ +data = { + 'slug': 'library', + 'description': 'Chicago Public Library', + 'programs': [], + 'url': 'http://www.chipublib.org/', + 'imageUrl': 'http://example.org/test.png', + 'id': 1, + 'email': 'eratosthenes@chipublib.org', + 'name': 'Chicago Public Library' +} + +def get (request, query): + import programs + + rsp = data.copy() + rsp['programs'] = programs.get(request, query)['programs'] + return {'issuer': rsp} diff --git a/test/fixtures/systems/chicago/issuers/library/badges/__init__.py b/test/fixtures/systems/chicago/issuers/library/badges/__init__.py new file mode 100644 index 0000000..71a9e71 --- /dev/null +++ b/test/fixtures/systems/chicago/issuers/library/badges/__init__.py @@ -0,0 +1,8 @@ +def get (request, query): + import library + + return { + 'badges': [ + library.get(request, query)['badge'], + ] + } \ No newline at end of file diff --git a/test/fixtures/systems/chicago/issuers/library/badges/library.py b/test/fixtures/systems/chicago/issuers/library/badges/library.py new file mode 100644 index 0000000..5107476 --- /dev/null +++ b/test/fixtures/systems/chicago/issuers/library/badges/library.py @@ -0,0 +1,46 @@ +data = { + 'consumerDescription': 'A consumer description of the Chicago Library Badge', + 'rubricUrl': 'http://example.org/chicaogLibraryRubric', + 'strapline': 'A badge for doing Library in Chicago', + 'id': 5, + 'issuer': { + 'slug': 'chicago-library', + 'description': 'Chicago Public Library', + 'programs': [], + 'url': 'http://www.chipublib.org/', + 'imageUrl': None, + 'id': 1, + 'email': 'eratosthenes@chipublib.org', + 'name': 'Chicago Public Library' + }, + 'archived': False, + 'system': { + 'slug': 'chicago', + 'name': 'Chicago', + 'url': 'http://cityofchicago.org', + 'imageUrl': None, + 'id': 1, + 'email': 'mayor-emanuel@cityofchicago.org', + 'issuers': [] + }, + 'issuerUrl': 'http://example.org/chicagoIssuerUrl', + 'criteria': [], + 'type': 'Not too shabby', + 'tags': [], + 'timeUnits': 'hours', + 'unique': 1, + 'slug': 'chicago-library-badge', + 'categories': [], + 'earnerDescription': 'An earner description of the Chicago Library Badge', + 'milestones': [], + 'name': 'Chicago Library Badge', + 'created': '2014-06-17T10:27:42.000Z', + 'imageUrl': 'http://example.org/test.png', + 'timeValue': 5, + 'limit': 2, + 'criteriaUrl': 'http://example.org/chicagoLibraryCriteria' +} + +def get (request, query): + rsp = data.copy() + return {'badge': rsp} diff --git a/test/fixtures/systems/chicago/issuers/library/programs/__init__.py b/test/fixtures/systems/chicago/issuers/library/programs/__init__.py new file mode 100644 index 0000000..3cea7c8 --- /dev/null +++ b/test/fixtures/systems/chicago/issuers/library/programs/__init__.py @@ -0,0 +1,8 @@ +def get (request, query): + import mit + + return { + 'programs': [ + mit.get(request, query)['program'], + ] + } diff --git a/test/fixtures/systems/chicago/issuers/library/programs/mit/__init__.py b/test/fixtures/systems/chicago/issuers/library/programs/mit/__init__.py new file mode 100644 index 0000000..48e4b40 --- /dev/null +++ b/test/fixtures/systems/chicago/issuers/library/programs/mit/__init__.py @@ -0,0 +1,13 @@ +data = { + 'slug': 'mit', + 'description': 'Create stories, games, and animations. Share with others around the world', + 'url': 'http://scratch.mit.edu/', + 'imageUrl': 'http://example.org/test.png', + 'id': 1, + 'email': 'admin@scratch.mit.edu', + 'name': 'MIT Scratch' +} + +def get (request, query): + rsp = data.copy() + return {'program': rsp} diff --git a/test/fixtures/systems/chicago/issuers/library/programs/mit/badges/__init__.py b/test/fixtures/systems/chicago/issuers/library/programs/mit/badges/__init__.py new file mode 100644 index 0000000..b73d558 --- /dev/null +++ b/test/fixtures/systems/chicago/issuers/library/programs/mit/badges/__init__.py @@ -0,0 +1,8 @@ +def get (request, query): + import scratch + + return { + 'badges': [ + scratch.get(request, query)['badge'], + ] + } \ No newline at end of file diff --git a/test/fixtures/systems/chicago/issuers/library/programs/mit/badges/scratch.py b/test/fixtures/systems/chicago/issuers/library/programs/mit/badges/scratch.py new file mode 100644 index 0000000..6c24820 --- /dev/null +++ b/test/fixtures/systems/chicago/issuers/library/programs/mit/badges/scratch.py @@ -0,0 +1,55 @@ +data = { + 'consumerDescription': 'A consumer description of the Chicago Scratch Badge', + 'rubricUrl': 'http://example.org/chicaogScratchRubric', + 'strapline': 'A badge for doing Scratch in Chicago', + 'id': 4, + 'issuer': { + 'slug': 'library', + 'description': 'Chicago Public Library', + 'programs': [], + 'url': 'http://www.chipublib.org/', + 'imageUrl': None, + 'id': 1, + 'email': 'eratosthenes@chipublib.org', + 'name': 'Chicago Public Library' + }, + 'archived': False, + 'system': { + 'slug': 'chicago', + 'name': 'Chicago', + 'url': 'http://cityofchicago.org', + 'imageUrl': None, + 'id': 1, + 'email': 'mayor-emanuel@cityofchicago.org', + 'issuers': [] + }, + 'issuerUrl': 'http://example.org/chicagoIssuerUrl', + 'program': { + 'slug': 'mit', + 'description': 'Create stories, games, and animations. Share with others around the world', + 'url': 'http://scratch.mit.edu/', + 'imageUrl': None, + 'id': 1, + 'email': 'admin@scratch.mit.edu', + 'name': 'MIT Scratch' + }, + 'criteria': [], + 'type': 'Not too shabby', + 'tags': [], + 'timeUnits': 'hours', + 'unique': 1, + 'slug': 'scratch', + 'categories': [], + 'earnerDescription': 'An earner description of the Chicago Scratch Badge', + 'milestones': [], + 'name': 'Chicago Scratch Badge', + 'created': '2014-06-17T10:27:42.000Z', + 'imageUrl': 'http://example.org/test.png', + 'timeValue': 5, + 'limit': 2, + 'criteriaUrl': 'http://example.org/chicagoScratchCriteria' +} + +def get (request, query): + rsp = data.copy() + return {'badge': rsp} diff --git a/test/fixtures/systems/pittsburgh.py b/test/fixtures/systems/pittsburgh.py new file mode 100644 index 0000000..74825a2 --- /dev/null +++ b/test/fixtures/systems/pittsburgh.py @@ -0,0 +1,13 @@ +data = { + 'slug': 'pittsburgh', + 'name': 'Pittsburgh', + 'url': 'http://pittsburghpa.gov', + 'imageUrl': 'http://example.org/test.png', + 'id': 2, + 'email': 'mayor-ravenstahl@pittsburghpa.gov', + 'issuers': [] +} + +def get (request, query): + rsp = data.copy() + return {'system': rsp} diff --git a/test/fixtures/systems/system/__init__.py b/test/fixtures/systems/system/__init__.py deleted file mode 100644 index 68f4d5e..0000000 --- a/test/fixtures/systems/system/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -import issuers - -def get (request, query): - return { - 'system': { - 'id': 1, - 'slug': 'system', - 'url': '', - 'name': 'Test System', - 'email': None, - 'imageUrl': None, - 'issuers': issuers.get(request, query)['issuers'] - } - } diff --git a/test/fixtures/systems/system/badges/__init__.py b/test/fixtures/systems/system/badges/__init__.py deleted file mode 100644 index 4571006..0000000 --- a/test/fixtures/systems/system/badges/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -single_response = { - 'badges': [ - {'slug': 'test-1', 'name': 'Test Badge 1'}, - ] -} - -all_response = { - 'badges': [ - {'slug': 'test-1', 'name': 'Test Badge 1'}, - {'slug': 'test-2', 'name': 'Test Badge 2'} - ] -} - -def get (request, query): - if query.get('archived') == 'any': - return all_response - return single_response \ No newline at end of file diff --git a/test/fixtures/systems/system/issuers/__init__.py b/test/fixtures/systems/system/issuers/__init__.py deleted file mode 100644 index 5f61053..0000000 --- a/test/fixtures/systems/system/issuers/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -def get (request, query): - return { - 'issuers': [{ - 'id': 1, - 'slug': 'test', - 'url': '', - 'name': 'Test Issuer', - 'description': None, - 'email': None, - 'imageUrl': None, - 'programs': [] - }] - }