django-mock-queries
django-mock-queries copied to clipboard
Is it possible to use a m2m field with .set() method?
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'