def test_factories_stack_a_source(identifiers, sources): factory = Factory( data={ "students": { "table": """ | id | first_name | | - | - | | s1 | Buffy | | s2 | Willow | """ } }, sources=sources, ) factory.generate("TestCase") expected = markdown_to_df(""" | id | first_name | | - | - | | {s1} | Buffy | | {s2} | Willow | """.format( s1=identifiers["student"].generate(case="TestCase", named_id="s1")["id"], s2=identifiers["student"].generate(case="TestCase", named_id="s2")["id"], )) actual = sources["students"].data[expected.columns] assert_frame_equal(actual, expected)
def test_factories_stack_sources(identifiers, sources): factory = Factory( data={ "students": { "table": """ | id | organization_id | first_name | | - | - | - | | s1 | o1 | Buffy | | s2 | o1 | Willow | """ }, "organizations": { "table": """ | id | name | | - | - | | o1 | Sunnydale High | """ }, }, sources=sources, ) factory.generate("TestCase") expected_students = markdown_to_df(""" | id | organization_id | first_name | | - | - | - | | {s1} | {o1} | Buffy | | {s2} | {o1} | Willow | """.format( s1=identifiers["student"].generate(case="TestCase", named_id="s1")["id"], s2=identifiers["student"].generate(case="TestCase", named_id="s2")["id"], o1=identifiers["organization"].generate(case="TestCase", named_id="o1")["id"], )) actual_students = sources["students"].data.drop(columns=["external_id"]) expected_organizations = markdown_to_df(""" | id | name | | - | - | | {o1} | Sunnydale High | """.format(o1=identifiers["organization"].generate( case="TestCase", named_id="o1")["id"])) actual_organizations = sources["organizations"].data.drop(columns=["uuid"]) assert_frame_equal(actual_students, expected_students) assert_frame_equal(actual_organizations, expected_organizations)
def test_inheritance_defaults_are_overridden(identifiers, sources): base_factory = Factory( data={ "students": { "table": """ | id | | - | | s1 | """, "values": { "first_name": "Bob" }, } }, sources=sources, ) composite_factory = Factory( data={ "students": { "table": """ | id | | - | | s1 | """, "values": { "last_name": "Loblaw" }, } }, inherit_from=[base_factory], sources=sources, ) composite_factory.generate("TestCase") expected = markdown_to_df(""" | id | first_name | last_name | | - | - | - | | {s1} | Bob | Loblaw | """.format(s1=identifiers["student"].generate(case="TestCase", named_id="s1")["id"])) actual = sources["students"].data.drop( columns=["external_id", "organization_id"]) assert_frame_equal(actual, expected)