This commit is contained in:
Andrew Hayward 2014-06-17 15:37:24 +01:00
Родитель a56476fb87
Коммит 0b117736f1
19 изменённых файлов: 377 добавлений и 47 удалений

5
test/fixtures/__init__.py поставляемый
Просмотреть файл

@ -0,0 +1,5 @@
def get (request, query):
return {
'app': 'BadgeKit API',
'version': '0.x'
}

8
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'],
]
}

16
test/fixtures/systems/chicago/__init__.py поставляемый Normal file
Просмотреть файл

@ -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}

75
test/fixtures/systems/chicago/badges/__init__.py поставляемый Normal file
Просмотреть файл

@ -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',)

35
test/fixtures/systems/chicago/badges/archived.py поставляемый Normal file
Просмотреть файл

@ -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'
}
}

64
test/fixtures/systems/chicago/badges/badge.py поставляемый Normal file
Просмотреть файл

@ -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,
}

1
test/fixtures/systems/chicago/badges/scratch.py поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
from ..issuers.library.programs.mit.badges.scratch import *

8
test/fixtures/systems/chicago/issuers/__init__.py поставляемый Normal file
Просмотреть файл

@ -0,0 +1,8 @@
def get (request, query):
import library
return {
'issuers': [
library.get(request, query)['issuer'],
]
}

17
test/fixtures/systems/chicago/issuers/library/__init__.py поставляемый Normal file
Просмотреть файл

@ -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}

Просмотреть файл

@ -0,0 +1,8 @@
def get (request, query):
import library
return {
'badges': [
library.get(request, query)['badge'],
]
}

46
test/fixtures/systems/chicago/issuers/library/badges/library.py поставляемый Normal file
Просмотреть файл

@ -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}

Просмотреть файл

@ -0,0 +1,8 @@
def get (request, query):
import mit
return {
'programs': [
mit.get(request, query)['program'],
]
}

Просмотреть файл

@ -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}

Просмотреть файл

@ -0,0 +1,8 @@
def get (request, query):
import scratch
return {
'badges': [
scratch.get(request, query)['badge'],
]
}

Просмотреть файл

@ -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}

13
test/fixtures/systems/pittsburgh.py поставляемый Normal file
Просмотреть файл

@ -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}

14
test/fixtures/systems/system/__init__.py поставляемый
Просмотреть файл

@ -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']
}
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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': []
}]
}