How to avoid Faker('domain_name') having the same domain twice in a row ?
See original GitHub issueI use factory.Faker(“domain_name”) in my factory, is there any way to stop it coming up with the same domain twice ?
I got a unique key error after calling my factory twice:
class SiteFactory(factory.DjangoModelFactory):
class Meta:
model = Site
name = factory.Faker('word')
domain = factory.Faker('domain_name')
self.slovak_site = SiteFactory(id=5)
self.czech_site = SiteFactory(id=6)
Got this unique key error one test run:
DETAIL: Key (domain)=(smith.info) already exists.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How to avoid Faker('domain_name') having the same domain twice ...
I use factory.Faker("domain_name") in my factory, is there any way to stop it coming up with the same domain twice ? I got...
Read more >Faker generates same word 2 times in a row #655 - GitHub
We use faker in our project and generally are happy with it. But from time to time one of our tests fails because...
Read more >using Twice the same FK in the same table with laravel
Found. A problem in one of my var names.
Read more >What happens when a domain name is linked to two different ...
That depends. As mentioned, it's fairly common for a domain to be connected to multiple IP addresses. Do the two IPs serve the...
Read more >Bought the same domain name twice - Web Hosting Talk
1. It is not the case buying the domain 2 times, it is the case when the domain wasn't registered first time. 2....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Do you mean something like
MyFactory.create_batch(2, domain=["example.org", "example.com"])
? If so, then no, that is not possible.What I meant by using
factory.Sequence
was:That yields unique values for domain as long as the sequence is not reset. That does not make domain names as realistic as Faker’s, but they should be good enough for tests and are sure to be unique.
An overkill way to generate unique domain from
Faker().domain_name()
:In the end I made a SiteFactory that handles this, posted below
It does feel like both faker and factoryboy would benefit from being able to handle uniqueness, especially when it comes to fields that are declared unique.