Ejemplo n.º 1
0
class RecipeRevisionFactory(factory.DjangoModelFactory):
    class Meta:
        model = RecipeRevision

    name = FuzzyUnicode()
    action = factory.SubFactory(ActionFactory)
    recipe = factory.SubFactory(RecipeFactory)
    identicon_seed = FuzzyIdenticonSeed()
    comment = FuzzyUnicode()
    extra_filter_expression = factory.fuzzy.FuzzyChoice(["true", "false"])
    extra_capabilities = []

    @factory.lazy_attribute
    def filter_object_json(self):
        filters = [
            ChannelFilterFactory(),
            LocaleFilterFactory(),
            CountryFilterFactory(),
            StableSampleFilterFactory(),
            BucketSampleFilterFactory(),
        ]
        return json.dumps(filters)

    @factory.post_generation
    def arguments(revision, create, extracted=None, **kwargs):
        arguments_factory = argument_factories.get(revision.action.name)
        if arguments_factory:
            if extracted is None:
                extracted = {}
            revision.arguments = arguments_factory(**kwargs, **extracted)
        elif extracted is not None:
            revision.arguments = {**extracted, **kwargs}
Ejemplo n.º 2
0
class ExtensionFactory(factory.DjangoModelFactory):
    name = FuzzyUnicode()
    xpi = factory.django.FileField(
        from_func=lambda: WebExtensionFileFactory().open())

    class Meta:
        model = Extension
Ejemplo n.º 3
0
class RecipeRevisionFactory(factory.DjangoModelFactory):
    class Meta:
        model = RecipeRevision

    name = FuzzyUnicode()
    action = factory.SubFactory(ActionFactory)
    recipe = factory.SubFactory(RecipeFactory)
Ejemplo n.º 4
0
class RecipeFactory(factory.DjangoModelFactory):
    class Meta:
        model = Recipe

    name = FuzzyUnicode()
    action = factory.SubFactory(ActionFactory)
    enabled = True

    @factory.post_generation
    def countries(self, create, extracted, **kwargs):
        if not create:
            return

        if extracted:
            for country in extracted:
                self.countries.add(country)

    @factory.post_generation
    def locales(self, create, extracted, **kwargs):
        if not create:
            return

        if extracted:
            for locale in extracted:
                self.locales.add(locale)

    @factory.post_generation
    def release_channels(self, create, extracted, **kwargs):
        if not create:
            return

        if extracted:
            for channel in extracted:
                self.release_channels.add(channel)
class ActionFactory(factory.DjangoModelFactory):
    class Meta:
        model = Action

    name = FuzzyUnicode()
    implementation = 'console.log("test");'

    @factory.lazy_attribute
    def implementation_hash(action):
        if action.implementation is not None:
            return sri_hash(action.implementation.encode(), url_safe=True)

    # It is important that the signature be based on the actual data, and not
    # some static value so that tests can make assertions against what data was
    # signed.

    @factory.post_generation
    def signed(self, create, extracted=False, **kwargs):
        if extracted:
            self.signature = SignatureFactory(data=self.canonical_json())
            self.signature.save()
            self.save()
        elif extracted is False:
            self.signature = None
            self.save()
Ejemplo n.º 6
0
class ExtensionFactory(factory.DjangoModelFactory):
    name = FuzzyUnicode()
    xpi = factory.django.FileField(
        from_path=os.path.join(DATA_DIR, "webext-signed.xpi"))

    class Meta:
        model = Extension
Ejemplo n.º 7
0
class ActionFactory(factory.DjangoModelFactory):
    class Meta:
        model = Action

    name = FuzzyUnicode()
    implementation = 'console.log("test");'

    @factory.lazy_attribute
    def implementation_hash(action):
        return hashlib.sha1(action.implementation.encode()).hexdigest()
Ejemplo n.º 8
0
class RecipeRevisionFactory(factory.DjangoModelFactory):
    class Meta:
        model = RecipeRevision

    name = FuzzyUnicode()
    action = factory.SubFactory(ActionFactory)
    recipe = factory.SubFactory(RecipeFactory)
    identicon_seed = FuzzyIdenticonSeed()
    comment = FuzzyUnicode()
    extra_filter_expression = factory.fuzzy.FuzzyChoice(["true", "false"])

    @factory.lazy_attribute
    def filter_object_json(self):
        filters = [
            ChannelFilterFactory(),
            LocaleFilterFactory(),
            CountryFilterFactory(),
            StableSampleFilterFactory(),
            BucketSampleFilterFactory(),
        ]
        return json.dumps(filters)
Ejemplo n.º 9
0
class LocaleFactory(factory.DjangoModelFactory):
    name = FuzzyUnicode()

    class Meta:
        model = Locale
Ejemplo n.º 10
0
class CountryFactory(factory.DjangoModelFactory):
    name = FuzzyUnicode()

    class Meta:
        model = Country
Ejemplo n.º 11
0
class ChannelFactory(factory.DjangoModelFactory):
    name = FuzzyUnicode()

    class Meta:
        model = Channel
Ejemplo n.º 12
0
class ActionFactory(factory.DjangoModelFactory):
    class Meta:
        model = Action

    name = FuzzyUnicode()
    implementation = 'console.log("test");'
Ejemplo n.º 13
0
class ReleaseChannelFactory(factory.DjangoModelFactory):
    class Meta:
        model = ReleaseChannel

    name = FuzzyUnicode()
    slug = factory.LazyAttribute(lambda o: slugify(o.name))
Ejemplo n.º 14
0
class ExtensionFactory(factory.DjangoModelFactory):
    name = FuzzyUnicode()
    xpi = factory.django.FileField()

    class Meta:
        model = Extension