def test_terms_can_be_added_to_item(item_data): item_id = item_data['id'] # TODO: Replace with Term list() ? item = Item.objects.get(pk=item_id) assert item.terms.count() == 0 for term in (TermFactory() for i in range(2)): items.add_terms(item_id, term.taxonomy.slug, term.name) assert item.terms.count() == 2
def test_add_term_fails_if_item_does_not_exist(): with pytest.raises(TransportException) as excinfo: term = TermFactory() unknown_item_id = 6 # I am a Free Man items.add_terms(unknown_item_id, term.taxonomy.slug, term.name) error = excinfo.value.message assert error['status_code'] == 404 assert error['detail'] == "Message matching query does not exist." # TODO: assert error['detail'] == "Item matching query does not exist." assert error['item_id'] == unknown_item_id
def test_add_term_fails_if_term_does_not_exist(taxonomy, item_data): with pytest.raises(TransportException) as excinfo: items.add_terms( item_data['id'], taxonomy.slug, "unknown term name", ) error = excinfo.value.message assert error['status_code'] == 400 assert error['detail'] == "Term matching query does not exist." assert error['terms']['name'] == "unknown term name"
def test_add_terms_raises_transport_exception_if_taxonomy_absent(): item = items.create({'body': "What is the cuse of ebola?"}) term_names = ['Monrovia', 'age 40-45', 'pertinent'] with pytest.raises(TransportException) as excinfo: items.add_terms(item['id'], 'unknown-slug', term_names) error = excinfo.value.message assert error['status_code'] == 400 assert error['detail'] == "Taxonomy matching query does not exist." assert error['item_id'] == item['id'] assert error['terms']['name'] == term_names assert error['terms']['taxonomy'] == 'unknown-slug'
def test_add_terms_raises_transport_exception_if_item_absent(taxonomy): unknown_item_id = 6 term_names = ['Monrovia', 'age 40-45', 'pertinent'] with pytest.raises(TransportException) as excinfo: items.add_terms(unknown_item_id, taxonomy.slug, term_names) error = excinfo.value.message assert error['status_code'] == 404 assert error['detail'] == "Message matching query does not exist." assert error['item_id'] == unknown_item_id assert error['terms']['name'] == term_names assert error['terms']['taxonomy'] == taxonomy.slug
def test_terms_can_be_removed_from_item(item_data): item_id = item_data["id"] # TODO: Replace with Term list() ? item = Item.objects.get(pk=item_id) assert item.terms.count() == 0 term = TermFactory(name="term to be deleted") items.add_terms(item_id, term.taxonomy.slug, term.name) term2 = TermFactory(name="term not to be deleted") items.add_terms(item_id, term2.taxonomy.slug, term2.name) assert item.terms.count() == 2 response = items.delete_all_terms(item_id, term.taxonomy.slug) assert "id" in response [remaining_term] = item.terms.all() assert remaining_term == term2
def test_multiple_new_terms_applied_to_item(taxonomy): item = items.create({'body': "What is the cuse of ebola?"}) term_names = ['Monrovia', 'age 40-45', 'pertinent'] item = items.add_terms( item['id'], taxonomy.slug, term_names) stored_names = [t['name'] for t in item['terms']] assert sorted(term_names) == sorted(stored_names)