def test_no_repeated_sort(self): """ Check that the sort_order keys across the entire topic tree have no repetition. This means that we can use sort_order both locally and globally to sort nodes. """ data = retrieve_kalite_data(force=True) sorts = set([node.get("sort_order") for node in data]) assert len(data) == len(sorts)
def test_returns_something_in_production_json(self): """ Since we know that test_given_list_returns_only_videos works, then we only need to check that we return something for the actual contents.json to make sure we're reading the right attributes. """ data = retrieve_kalite_data() assert _get_video_ids(data)
def test_all_nodes_have_parent_values(self): nodes = convert_dicts_to_models(retrieve_kalite_data()) db = SqliteDatabase(":memory:") save_models(list(nodes), db) new_nodes = list(populate_parent_foreign_keys(nodes)) for node in new_nodes: if node.title != "Khan Academy": # aron: maybe there's a better way to find the root node? assert node.parent and isinstance(node.parent, Item)
def setup(self): with vcr.use_cassette( "tests/fixtures/cassettes/kalite/node_data.json.yml"): node_data = retrieve_kalite_data() self.assess_node = next(node for node in node_data if node.get("all_assessment_items")) self.assessment_item = self.assess_node.get( "all_assessment_items")[0].get("id")
def test_translates_selected_fields(self): node_data = retrieve_kalite_data() node_dict = {node.get("path"): node for node in node_data} catalog = generate_catalog() translated_nodes = translate_nodes(node_data, catalog) for node in translated_nodes: for field in NODE_FIELDS_TO_TRANSLATE: translated_fieldval = node.get(field, "") untranslated_fieldval = node_dict[node.get("path")].get(field, "") assert translated_fieldval == catalog.get(untranslated_fieldval, untranslated_fieldval)
def test_translates_selected_fields(self): node_data = retrieve_kalite_data() node_dict = {node.get("path"): node for node in node_data} catalog = generate_catalog() translated_nodes = translate_nodes(node_data, catalog) for node in translated_nodes: for field in NODE_FIELDS_TO_TRANSLATE: translated_fieldval = node.get(field, "") untranslated_fieldval = node_dict[node.get("path")].get( field, "") assert translated_fieldval == catalog.get( untranslated_fieldval, untranslated_fieldval)
def test_translate_nodes(self): node_data = retrieve_kalite_data() translated_node_data = translate_nodes( node_data, self.ka_catalog, ) for translated_node, untranslated_node in zip(translated_node_data, node_data): for field in NODE_FIELDS_TO_TRANSLATE: untranslated_fieldval = untranslated_node.get(field) translated_fieldval = translated_node.get(field) assert (translated_fieldval == self.ka_catalog.get( untranslated_fieldval, untranslated_fieldval))
def test_translate_nodes(self): node_data = retrieve_kalite_data() translated_node_data = translate_nodes( node_data, self.ka_catalog, ) for translated_node, untranslated_node in zip(translated_node_data, node_data): for field in NODE_FIELDS_TO_TRANSLATE: untranslated_fieldval = untranslated_node.get(field) translated_fieldval = translated_node.get(field) assert (translated_fieldval == self.ka_catalog.get( untranslated_fieldval, untranslated_fieldval) )
def _get_all_video_ids(): """ Test utility function so we only need to generate the list of video ids once, and then assign that to an instance variable. We wrap it as a function instead of assigning the value of retrieve_kalite_content_data directly so we can use the cassette system to cache the results, avoiding an expensive http request. """ content_data = retrieve_kalite_data() ids = _get_video_ids(content_data) # return a tuple, to make sure it gets never modified. ids_tuple = tuple(ids) # just take the first 10 ids -- don't run too many return ids_tuple[:10]
def test_raises_no_errors_on_actual_data(self): nodes = retrieve_kalite_data() new_nodes = list(convert_dicts_to_models(nodes))
def test_returns_dict(self): data = retrieve_kalite_data(force=True) assert isinstance(data, list)
def setup(self): with vcr.use_cassette( "tests/fixtures/cassettes/kalite/node_data.json.yml"): self.nodes = retrieve_kalite_data()
def generate_node_list(): return retrieve_kalite_data()
def setup(self): self.exercise_data = retrieve_kalite_data() self.khan_exercises = [e.get("id") for e in self.exercise_data if not e.get("uses_assessment_items")\ and e.get("kind") == "Exercise"] self.khan_exercises.sort()
def setup(self): with vcr.use_cassette("tests/fixtures/cassettes/kalite/node_data.json.yml"): self.nodes = retrieve_kalite_data()
def setup(self): with vcr.use_cassette("tests/fixtures/cassettes/kalite/node_data.json.yml"): node_data = retrieve_kalite_data() self.assess_node = next(node for node in node_data if node.get("all_assessment_items")) self.assessment_item = self.assess_node.get("all_assessment_items")[0].get("id")