import factory

from normandy.base.tests import FuzzyUnicode
from normandy.recipes.models import Action, Recipe, RecipeAction


class RecipeFactory(factory.DjangoModelFactory):
    class Meta:
        model = Recipe

    name = FuzzyUnicode()
    enabled = True


class ActionFactory(factory.DjangoModelFactory):
    class Meta:
        model = Action

    name = FuzzyUnicode()
    implementation = FuzzyUnicode(prefix='// ')


class RecipeActionFactory(factory.DjangoModelFactory):
    class Meta:
        model = RecipeAction

    action = factory.SubFactory(ActionFactory)
    recipe = factory.SubFactory(RecipeFactory)

@@ -97,16 +97,24 @@
  Action,
+ Locale,
  Recipe,
@@ -127,16 +127,16 @@
 eAction%0A
-
 %0A%0Aclass 
@@ -264,16 +264,267 @@
 = True%0A%0A
+    @factory.post_generation%0A    def locale(self, create, extracted, **kwargs):%0A        if not create:%0A            return%0A%0A        if extracted and isinstance(extracted, str):%0A            self.locale, _ = Locale.objects.get_or_create(code=extracted)%0A%0A
 %0Aclass A
@@ -829,16 +829,16 @@
 actory)%0A
-
     reci
@@ -868,16 +868,106 @@
 (RecipeFactory)%0A
+%0A%0Aclass LocaleFactory(factory.DjangoModelFactory):%0A    class Meta:%0A        model = Locale%0A

Fix tests to handle Locale as a foreign key.