def test_get_node_roles(): try: network_name = 'n1' bf_set_network(network_name) assert bf_get_node_roles() == NodeRolesData([]) finally: bf_delete_network(network_name)
def test_get_node_role_dimension(): try: network_name = "n1" bf_set_network(network_name) dim_name = "d1" with raises(HTTPError, match="404"): bf_get_node_role_dimension(dim_name) finally: bf_delete_network(network_name)
def test_put_node_roles(): try: network_name = 'n1' bf_set_network(network_name) node_roles = NodeRolesData([NodeRoleDimension('dim1')]) bf_put_node_roles(node_roles) assert bf_get_node_roles() == node_roles finally: bf_delete_network(network_name)
def test_get_node_role_dimension(): try: network_name = 'n1' bf_set_network(network_name) dim_name = 'd1' with raises(HTTPError, match='404'): bf_get_node_role_dimension(dim_name) finally: bf_delete_network(network_name)
def test_add_node_role_dimension(): try: network_name = 'n1' bf_set_network(network_name) dim_name = 'd1' dim = NodeRoleDimension(dim_name) bf_add_node_role_dimension(dim) assert bf_get_node_role_dimension(dim_name) == dim finally: bf_delete_network(network_name)
def network(): load_questions(_stable_question_dir) load_questions(_experimental_question_dir) try: bf_delete_network(TEST_NETWORK) except Exception: pass bf_set_network(TEST_NETWORK) yield bf_init_snapshot(_test_rig_dir + "/example", name="example") bf_delete_network(TEST_NETWORK)
def network(): load_questions(_stable_question_dir) load_questions(_experimental_question_dir) try: bf_delete_network(TEST_NETWORK) except Exception: pass bf_set_network(TEST_NETWORK) yield bf_init_snapshot(join(_this_dir, "snapshot"), name="snapshot") bf_delete_network(TEST_NETWORK)
def test_add_node_role_dimension(session): try: network_name = "n1" bf_set_network(network_name) dim_name = "d1" rdMap = RoleDimensionMapping("a", [1], {}) dim = NodeRoleDimension(dim_name, roleDimensionMappings=[rdMap]) bf_add_node_role_dimension(dim) assert bf_get_node_role_dimension(dim_name) == dim finally: bf_delete_network(network_name)
def test_add_node_role_dimension(): try: network_name = 'n1' bf_set_network(network_name) dim_name = 'd1' rdMap = RoleDimensionMapping("a", [1], {}, False) dim = NodeRoleDimension(dim_name, roleDimensionMappings=[rdMap]) bf_add_node_role_dimension(dim) assert bf_get_node_role_dimension(dim_name) == dim finally: bf_delete_network(network_name)
def test_set_network(): try: assert bf_set_network("foobar") == "foobar" finally: bf_delete_network("foobar") name = bf_set_network() try: assert name.startswith(Options.default_network_prefix) finally: bf_delete_network(name)
def test_add_node_roles_data(): try: network_name = "n1" bf_set_network(network_name) mappings = [ RoleMapping("mapping1", "(.*)-(.*)", {"type": [1], "index": [2]}, {}) ] roles_data = NodeRolesData(None, ["type", "index"], mappings) bf_put_node_roles(roles_data) assert bf_get_node_roles() == roles_data finally: bf_delete_network(network_name)
def auto_complete_tester(completion_types): try: name = bf_set_network() bf_init_snapshot(join(_this_dir, "snapshot")) for completion_type in completion_types: suggestions = bf_auto_complete(completion_type, ".*") # Not all completion types will have suggestions since this test snapshot only contains one empty config. # If a completion type is unsupported an error is thrown so this will test that no errors are thrown. if len(suggestions) > 0: assert isinstance(suggestions[0], AutoCompleteSuggestion) finally: bf_delete_network(name)
def test_put_node_role_dimension(): try: network_name = 'n1' bf_set_network(network_name) dim_name = 'd1' dim = NodeRoleDimension(dim_name) bf_put_node_role_dimension(dim) assert bf_get_node_role_dimension(dim_name) == dim # put again to check for idempotence bf_put_node_role_dimension(dim) assert bf_get_node_role_dimension(dim_name) == dim finally: bf_delete_network(network_name)
def test_put_reference_book(): try: network_name = "n1" bf_set_network(network_name) book_name = "b1" book = ReferenceBook(book_name) bf_put_reference_book(book) assert bf_get_reference_book(book_name) == book # put again to check for idempotence bf_put_reference_book(book) assert bf_get_reference_book(book_name) == book finally: bf_delete_network(network_name)
def test_put_node_roles(): try: network_name = "n1" bf_set_network(network_name) mapping = RoleMapping( name="mapping", regex="(regex)", roleDimensionGroups={"dim1": [1]} ) node_roles = NodeRolesData( defaultDimension="dim1", roleDimensionOrder=["dim1"], roleMappings=[mapping] ) bf_put_node_roles(node_roles) assert bf_get_node_roles() == node_roles finally: bf_delete_network(network_name)
def test_put_node_role_dimension(session): try: network_name = "n1" bf_set_network(network_name) dim_name = "d1" mapping = RoleDimensionMapping(regex="(regex)") dim = NodeRoleDimension(dim_name, roleDimensionMappings=[mapping]) bf_put_node_role_dimension(dim) assert bf_get_node_role_dimension(dim_name) == dim # put again to check for idempotence bf_put_node_role_dimension(dim) assert bf_get_node_role_dimension(dim_name) == dim finally: bf_delete_network(network_name)
def test_delete_node_role_dimension(): try: network_name = 'n1' bf_set_network(network_name) dim_name = 'd1' dim = NodeRoleDimension(dim_name) bf_add_node_role_dimension(dim) # should not crash bf_get_node_role_dimension(dim_name) bf_delete_node_role_dimension(dim_name) # dimension should no longer exist with raises(HTTPError, match='404'): bf_get_node_role_dimension(dim_name) # second delete should fail with raises(HTTPError, match='404'): bf_delete_node_role_dimension(dim_name) finally: bf_delete_network(network_name)
def test_delete_node_role_dimension(session): try: network_name = "n1" bf_set_network(network_name) dim_name = "d1" mapping = RoleDimensionMapping(regex="(regex)") dim = NodeRoleDimension(name=dim_name, roleDimensionMappings=[mapping]) bf_add_node_role_dimension(dim) # should not crash bf_get_node_role_dimension(dim_name) bf_delete_node_role_dimension(dim_name) # dimension should no longer exist with raises(HTTPError, match="404"): bf_get_node_role_dimension(dim_name) # second delete should fail with raises(HTTPError, match="404"): bf_delete_node_role_dimension(dim_name) finally: bf_delete_network(network_name)
def test_list_networks(): try: name = bf_set_network() assert name in bf_list_networks() finally: bf_delete_network(name)
def network(): name = bf_set_network() yield name # cleanup bf_delete_network(name)
def delete_network(self, network): bf_delete_network(network)