Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
harry-kim opened this issue Sep 20, 2021 · 0 comments
Open

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

harry-kim opened this issue Sep 20, 2021 · 0 comments

Comments

@harry-kim
Copy link
Contributor

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant