Skip to content

Is it possible to use a m2m field with .set() method? #148

@harry-kim

Description

@harry-kim

I'm trying to mock out and test a m2m field get set in my test.
I'm also using model_bakery for fixtures

The code I want to test is:
provider_currency.supported_countries.set(supported_countries)

And my test code:

    provider_currency = baker.prepare(ProviderCurrency, provider=provider)
    countries = baker.prepare(Country)
    mock_countries = MockSet(countries, model=Country)

    with mocked_relations(ProviderCurrency): 
        provider_currency.supported_countries = mock_countries
        my_method()

It tells me AttributeError: Mock object has no attribute 'set' so it tells me my ProviderCurrency isn't getting returned properly I guess. I tried mocking out ProviderCurrency.objects.get_or_create(), but then I get AttributeError: Mock object has no attribute 'supported_countries'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions