half of api tests are done

This commit is contained in:
Adickes 2015-10-23 00:56:01 -04:00
parent 176802e474
commit f3654c3458
12 changed files with 2500 additions and 1720 deletions

View file

@ -57,7 +57,7 @@ router.register(r"generation", GenerationResource)
router.register(r"growth-rate", GrowthRateResource)
router.register(r"item", ItemResource)
router.register(r"item-category", ItemCategoryResource)
router.register(r"item-attribute", ItemFlagResource)
router.register(r"item-attribute", ItemAttributeResource)
router.register(r"item-fling-effect", ItemFlingEffectResource)
router.register(r"item-pocket", ItemPocketResource)
router.register(r"language", LanguageResource)

File diff suppressed because it is too large Load diff

View file

@ -53,9 +53,9 @@ admin.site.register(GrowthRateDescription)
admin.site.register(ItemCategory)
admin.site.register(ItemCategoryName)
admin.site.register(ItemFlag)
admin.site.register(ItemFlagMap)
admin.site.register(ItemFlagDescription)
admin.site.register(ItemAttribute)
admin.site.register(ItemAttributeMap)
admin.site.register(ItemAttributeDescription)
admin.site.register(ItemFlavorText)
admin.site.register(ItemFlingEffect)
admin.site.register(ItemFlingEffectDescription)

View file

@ -0,0 +1,81 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('pokemon_v2', '0002_auto_20151016_0523'),
]
operations = [
migrations.CreateModel(
name='ItemAttributeDescription',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('description', models.CharField(default='', max_length=1000)),
('name', models.CharField(max_length=100)),
],
options={
'abstract': False,
},
bases=(models.Model,),
),
migrations.CreateModel(
name='ItemAttributeMap',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('item', models.ForeignKey(related_name='itemattributemap', blank=True, to='pokemon_v2.Item', null=True)),
],
options={
'abstract': False,
},
bases=(models.Model,),
),
migrations.RenameModel(
old_name='ItemFlag',
new_name='ItemAttribute',
),
migrations.RemoveField(
model_name='itemflagdescription',
name='item_flag',
),
migrations.RemoveField(
model_name='itemflagdescription',
name='language',
),
migrations.DeleteModel(
name='ItemFlagDescription',
),
migrations.RemoveField(
model_name='itemflagmap',
name='item',
),
migrations.RemoveField(
model_name='itemflagmap',
name='item_flag',
),
migrations.DeleteModel(
name='ItemFlagMap',
),
migrations.AddField(
model_name='itemattributemap',
name='item_attribute',
field=models.ForeignKey(blank=True, to='pokemon_v2.ItemAttribute', null=True),
preserve_default=True,
),
migrations.AddField(
model_name='itemattributedescription',
name='item_flag',
field=models.ForeignKey(blank=True, to='pokemon_v2.ItemAttribute', null=True),
preserve_default=True,
),
migrations.AddField(
model_name='itemattributedescription',
name='language',
field=models.ForeignKey(related_name='itemattributedescription_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
]

View file

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('pokemon_v2', '0003_auto_20151022_1725'),
]
operations = [
migrations.RenameField(
model_name='itemattributedescription',
old_name='item_flag',
new_name='item_attribute',
),
]

View file

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('pokemon_v2', '0004_auto_20151022_1729'),
]
operations = [
migrations.RemoveField(
model_name='itemflingeffectdescription',
name='effect',
),
migrations.AddField(
model_name='itemflingeffectdescription',
name='description',
field=models.CharField(default='', max_length=1000),
preserve_default=True,
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('pokemon_v2', '0005_auto_20151022_1917'),
]
operations = [
migrations.AlterField(
model_name='berryfirmnessname',
name='berry_firmness',
field=models.ForeignKey(related_name='berryfirmnessname', blank=True, to='pokemon_v2.BerryFirmness', null=True),
preserve_default=True,
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('pokemon_v2', '0006_auto_20151023_0135'),
]
operations = [
migrations.AddField(
model_name='berry',
name='name',
field=models.CharField(default='name', max_length=100),
preserve_default=False,
),
]

View file

@ -587,7 +587,7 @@ class ItemFlingEffect(HasName):
pass
class ItemFlingEffectDescription(HasFlingEffect, HasLanguage, HasEffect):
class ItemFlingEffectDescription(IsDescription, HasFlingEffect):
pass
@ -611,18 +611,18 @@ class ItemFlavorText(HasItem, HasVersionGroup, IsFlavorText):
pass
class ItemFlag(HasName):
class ItemAttribute(HasName):
pass
class ItemFlagDescription(IsDescription, HasName):
class ItemAttributeDescription(IsDescription, HasName):
item_flag = models.ForeignKey(ItemFlag, blank=True, null=True)
item_attribute = models.ForeignKey(ItemAttribute, blank=True, null=True)
class ItemFlagMap(HasItem):
class ItemAttributeMap(HasItem):
item_flag = models.ForeignKey(ItemFlag, blank=True, null=True)
item_attribute = models.ForeignKey(ItemAttribute, blank=True, null=True)
class ItemGameIndex(HasItem, HasGeneration, HasGameIndex):
@ -675,10 +675,10 @@ class BerryFirmness(HasName):
class BerryFirmnessName(IsName):
berry_firmness = models.ForeignKey(BerryFirmness, blank=True, null=True)
berry_firmness = models.ForeignKey(BerryFirmness, blank=True, null=True, related_name="%(class)s")
class Berry(HasItem, HasNature):
class Berry(HasName, HasItem, HasNature):
berry_firmness = models.ForeignKey(BerryFirmness, blank=True, null=True)

View file

@ -78,10 +78,10 @@ class ItemCategorySummarySerializer(serializers.HyperlinkedModelSerializer):
model = ItemCategory
fields = ('name', 'url')
class ItemFlagSummarySerializer(serializers.HyperlinkedModelSerializer):
class ItemAttributeSummarySerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = ItemFlag
model = ItemAttribute
fields = ('name', 'url')
class ItemFlingEffectSummarySerializer(serializers.HyperlinkedModelSerializer):
@ -110,20 +110,10 @@ class BerryFirmnessSummarySerializer(serializers.HyperlinkedModelSerializer):
class BerrySummarySerializer(serializers.HyperlinkedModelSerializer):
name = serializers.SerializerMethodField('get_berry_name')
class Meta:
model = Berry
fields = ('url', 'name')
def get_berry_name(self,obj):
item = Item.objects.get(id=obj.item.id)
serializer = ItemSummarySerializer(item, context=self.context)
name = serializer.data['name']
return name[:name.index('-')]
class EggGroupSummarySerializer(serializers.HyperlinkedModelSerializer):
class Meta:
@ -512,74 +502,69 @@ class ItemCategoryDetailSerializer(serializers.ModelSerializer):
fields = ('id', 'name', 'pocket', 'names')
###########################
# ITEM FLAG SERIALIZERS #
###########################
################################
# ITEM ATTRIBUTE SERIALIZERS #
################################
# Calling these Attributes instead of Flags cause I think that just makes more sense
# Probably should change the names of the models as well. Work To Do.
class ItemFlagDescriptionSerializer(serializers.ModelSerializer):
class ItemAttributeDescriptionSerializer(serializers.ModelSerializer):
language = LanguageSummarySerializer()
class Meta:
model = ItemFlagDescription
model = ItemAttributeDescription
fields = ('name', 'description', 'language')
class ItemFlagDetailSerializer(serializers.ModelSerializer):
class ItemAttributeDetailSerializer(serializers.ModelSerializer):
names = serializers.SerializerMethodField('get_flag_names')
descriptions = serializers.SerializerMethodField('get_flag_descriptions')
names = serializers.SerializerMethodField('get_attribute_names')
descriptions = serializers.SerializerMethodField('get_attribute_descriptions')
class Meta:
model = ItemFlag
model = ItemAttribute
fields = ('id', 'name', 'names', 'descriptions')
def get_flag_names(self, obj):
def get_attribute_names(self, obj):
item_flag = ItemFlagDescription.objects.filter(item_flag_id=obj)
serializer = ItemFlagDescriptionSerializer(item_flag, many=True, context=self.context)
item_attribute = ItemAttributeDescription.objects.filter(item_attribute_id=obj)
serializer = ItemAttributeDescriptionSerializer(item_attribute, many=True, context=self.context)
data = serializer.data
print data
for flag in data:
del flag['description']
for attribute in data:
del attribute['description']
return data
def get_flag_descriptions(self, obj):
def get_attribute_descriptions(self, obj):
item_flag = ItemFlagDescription.objects.filter(item_flag_id=obj)
serializer = ItemFlagDescriptionSerializer(item_flag, many=True, context=self.context)
item_attribute = ItemAttributeDescription.objects.filter(item_attribute_id=obj)
serializer = ItemAttributeDescriptionSerializer(item_attribute, many=True, context=self.context)
data = serializer.data
for flag in data:
del flag['name']
for attribute in data:
del attribute['name']
return data
class ItemFlagMapSerializer(serializers.ModelSerializer):
class ItemAttributeMapSerializer(serializers.ModelSerializer):
attribute = ItemFlagSummarySerializer(source='item_flag')
item = ItemSummarySerializer()
attribute = ItemAttributeSummarySerializer(source='item_attribute')
class Meta:
model = ItemFlagMap
fields = ('attribute',)
model = ItemAttributeMap
fields = ('item', 'attribute',)
###########################
# ITEM FLAG SERIALIZERS #
###########################
###################################
# ITEM FLING EFFECT SERIALIZERS #
###################################
class ItemFlingEffectDescriptionSerializer(serializers.ModelSerializer):
language = LanguageSummarySerializer()
description = serializers.CharField(source="effect")
class Meta:
model = ItemFlingEffectDescription
@ -588,7 +573,7 @@ class ItemFlingEffectDescriptionSerializer(serializers.ModelSerializer):
class ItemFlingEffectDetailSerializer(serializers.ModelSerializer):
descriptions = ItemCategoryNameSerializer(many=True, read_only=True, source="itemflingeffectdescription")
descriptions = ItemFlingEffectDescriptionSerializer(many=True, read_only=True, source="itemflingeffectdescription")
class Meta:
model = ItemFlingEffect
@ -635,7 +620,7 @@ class ItemDetailSerializer(serializers.ModelSerializer):
descriptions = ItemDescriptionSerializer(many=True, read_only=True, source="itemdescription")
flavor_text_entries = ItemFlavorTextSerializer(many=True, read_only=True, source="itemflavortext")
category = ItemCategorySummarySerializer(source="item_category")
attributes = ItemFlagMapSerializer(many=True, read_only=True, source="itemflagmap")
attributes = serializers.SerializerMethodField("get_item_attributes")
fling_effect = ItemFlingEffectSummarySerializer(source="item_fling_effect")
class Meta:
@ -653,6 +638,22 @@ class ItemDetailSerializer(serializers.ModelSerializer):
'flavor_text_entries'
)
def get_item_attributes(self, obj):
item_attribute_maps = ItemAttributeMap.objects.filter(item=obj)
serializer = ItemAttributeMapSerializer(item_attribute_maps, many=True, context=self.context)
data = serializer.data
attributes = []
for map in data:
attribute = OrderedDict()
attribute['name'] = map['attribute']['name']
attribute['url'] = map['attribute']['url']
attributes.append(attribute)
return attributes
########################
@ -703,7 +704,6 @@ class BerryFirmnessDetailSerializer(serializers.ModelSerializer):
class BerryDetailSerializer(serializers.ModelSerializer):
item = ItemSummarySerializer()
name = serializers.SerializerMethodField('get_berry_name')
nature = NatureSummarySerializer()
nature_power = serializers.IntegerField(source='natural_gift_power')
firmness = BerryFirmnessSummarySerializer(source="berry_firmness")
@ -724,14 +724,6 @@ class BerryDetailSerializer(serializers.ModelSerializer):
'soil_dryness'
)
def get_berry_name(self,obj):
item = Item.objects.get(id=obj.item.id)
serializer = ItemSummarySerializer(item, context=self.context)
name = serializer.data['name']
return name[:name.index('-')]
###########################
@ -803,6 +795,7 @@ class TypeDetailSerializer(serializers.ModelSerializer):
"""
generation = GenerationSummarySerializer()
names = AbilityNameSerializer(many=True, read_only=True, source="typename")
move_damage_class = MoveDamageClassSummarySerializer()
damage_relations = serializers.SerializerMethodField('get_type_relationships')
class Meta:

File diff suppressed because it is too large Load diff

View file

@ -129,11 +129,11 @@ class ItemCategoryResource(PokeapiCommonViewset):
list_serializer_class = ItemCategorySummarySerializer
class ItemFlagResource(PokeapiCommonViewset):
class ItemAttributeResource(PokeapiCommonViewset):
queryset = ItemFlag.objects.all()
serializer_class = ItemFlagDetailSerializer
list_serializer_class = ItemFlagSummarySerializer
queryset = ItemAttribute.objects.all()
serializer_class = ItemAttributeDetailSerializer
list_serializer_class = ItemAttributeSummarySerializer
class ItemFlingEffectResource(PokeapiCommonViewset):