Edge case when testing against local database
See original GitHub issueHi,
Firstly, I love the work done on this, it’s a really powerful tool.
I’m running into a problem when testing a salesforce database locally. I believe the tables in the local database has been generated with an integer type for the ID field
For example:
a = Account(id="abc123abc123abc", ...)
a.save()
Would fail, as id has a type mismatch, and is expecting an integer
I believe this is because the SalesforceAutoField
, as given to the id field in the SalesforceModel
has not overriden the get_internal_type()
method, and is defaulting to the integer type, of the parent class AutoField
Doing the following fixed my errors, but I wanted to check with you all first to see if I’m doing something wrong here. or if this should be pull requested?
class SalesforceAutoField(fields.AutoField):
"""
An AutoField that works with Salesforce primary keys.
It is used by SalesforceModel as a custom primary key. It doesn't convert
its value to int.
"""
description = _("Text")
def get_internal_type(self):
return "TextField"
default_error_messages = {
'invalid': _('This value must be a valid Salesforce ID.'),
}
def to_python(self, value):
...
Thanks Elliot
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Are these the sort of edge cases I should think of when using ...
Your tests seem OK, but the phrase "edge case" normally refers to the tests and checks you need to do around the limits...
Read more >Testing against your Production Database System - EF Core
When using a cloud database, it's usually appropriate to test against a local version of the database, both to improve speed and to...
Read more >Edge-case behavior of INSERT...ODKU - Percona
A few weeks back, I was working on a customer issue wherein they were observing database performance that dropped through the floor (to...
Read more >Find, Prioritize and Test Edge Cases - Applause
How does a QA tester identify edge test cases, or find edge case defects? The best advice is you find edge cases by...
Read more >Are (database) integration tests bad?
Write the smallest useful test you can. For this particular case, an in-memory database might help with that.
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 Free
Top 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
@thatguysimon Thanks for your input! 😃
In the end, I came up with a similar solution. Detecting when a test is running, and modifying the ID field type. I use the pytest_configure function in order to do this.
So within my tests folder, I have a conftest.py that looks like this:
In your solution, although this seems incredibly unlikely, and you might never run into it, it might be possible in your solution to generate 2 Account objects with the same ID, given that the ID is generated randomly. To avoid something like that, I generate my Accounts with a factory using a sequence:
That solution is in PR #237
Changelog:
The generator function for salesforce alternate primary key (default is
uuid.uuid4().hex
) is configurable bysettings.SF_ALT_PK
. This can be useful for your case if you want everything 15+3 chars.Please try the new code.