Open agritheory opened 7 months ago
I create a script to help organize this data and its sources. Currently it only examines the contexts of tests/fixtures.py
which will be a good start but not enough in the long run. It also doesn't currently include all the repos we want to consolidate, (Cloud Storage, Electronic Payments, US Regional, Autoreader, etc)
#!/usr/bin/python
import json
from rich.console import Console
from rich.table import Table
from rich import inspect
import requests
repo_config = [
("beam", "https://github.com/agritheory/beam", "version-14"),
("check_run", "https://github.com/agritheory/check_run", "tax_payable"),
("inventory_tools", "https://github.com/agritheory/inventory_tools", "version-14"),
# ("us_regional", "https://github.com/agritheory/us_regional", "version-15"), # need to refactor to use pygithub to access private repos
]
fixtures_data = {}
def get_fixtures_data(repo, branch="version-14"):
repo_string = f'{repo[1].replace("https://github.com/", "https://raw.githubusercontent.com/")}/{branch}/{repo[0]}/tests/fixtures.py'
fixtures_text = requests.get(repo_string).text
exec(fixtures_text)
for key, value in vars().items():
if key in ('repo', 'branch', 'fixtures_text', 'repo_string'):
continue
if not fixtures_data.get(key):
fixtures_data[key] = {}
fixtures_data[key][repo[0]] = value
def diff_fixtures():
console = Console()
output = {}
for fixture, repos in fixtures_data.items():
output[fixture] = {}
for repo_name, values in repos.items():
for value in values:
if type(value) == str:
continue
if isinstance(value, tuple):
value = list(value)
output[fixture][repo_name] = json.dumps(values, indent=2)
for key, value in output.items():
print(key, value.keys(), [len(v) for v in value.values()])
for fixture, repos in output.items():
table = Table(show_header=True, header_style="bold magenta", title=fixture)
for repo_name, values in repos.items():
table.add_column(repo_name)
table.add_row(*list(repos.values()))
console.print(table)
if __name__ == "__main__":
for repo in repo_config:
get_fixtures_data(repo)
diff_fixtures()
OK, looking at the fixtures list, some things should be extracted out:
@agritheory I'd also look at Electronic Payments for Payment Terms Templates - we added a few for the Billed as Agreed feature
@agritheory Across our repos, while creating test data I noticed we are creating either of the two companies Ambrosia Pie Company or Chelsea Fruit Co. How should we standardize this in test_utils?
@MyuddinKhatri I think we want the setup functions to allow for passing a "shortlist". I imagine the function signature like this:
def create_suppliers(settings, shortlist=None):
...
# logic to check if the shortlist exists, and the name/PK/identifier of the record matches, create it
# example use
create_suppliers(settings, shortlist=["AgriTheory"])
@MyuddinKhatri I think we want the setup functions to allow for passing a "shortlist". I imagine the function signature like this:
def create_suppliers(settings, shortlist=None): ... # logic to check if the shortlist exists, and the name/PK/identifier of the record matches, create it # example use create_suppliers(settings, shortlist=["AgriTheory"])
Here, shortlist represents a company?
@MyuddinKhatri This example is for a supplier. An example for companies would be:
create_company(settings, shortlist=["Chelsea Fruit Co"])
@agritheory In us_regional while creating employee records it also creates i9 records do we want to bring fixtures for i9 as well?
@MyuddinKhatri No, the I9 features are specific to US Regional and should remain there
Refactor tests in other repos to install with this data, either via python or directly imported json
In the future we'll want to be able to do the same for js/ts projects, so we want to have the records serialized to json
This should be delivered as one pull request per fixture type (for example "suppliers") so that we can discuss as appropriate.