Exemple #1
0
def test_convert_from_tags():
    tag_name1 = factories.Tag.stub().name
    tag_name2 = factories.Tag.stub().name
    vocab = factories.Vocabulary(tags=[
        {
            "name": tag_name1
        },
        {
            "name": tag_name2
        },
    ])
    key = "tags"
    data = {
        ("tags", 0, "__extras"): {
            "name": tag_name1,
            "vocabulary_id": vocab["id"],
        },
        ("tags", 1, "__extras"): {
            "name": tag_name2,
            "vocabulary_id": vocab["id"],
        },
    }
    errors = []
    context = {"model": model, "session": model.Session}
    converters.convert_from_tags(vocab["name"])(key, data, errors, context)
    assert tag_name1 in data["tags"]
    assert tag_name2 in data["tags"]
Exemple #2
0
 def test_vocab_does_not_exist(self):
     vocab = factories.Vocabulary(tags=[{"name": "testtag"}])
     tag = vocab["tags"][0]
     with pytest.raises(logic.NotFound):
         helpers.call_action("tag_delete",
                             id=tag["id"],
                             vocabulary_id="not-a-real-id")
Exemple #3
0
def test_free_tags_only():
    tag_name1 = factories.Tag.stub().name
    tag_name2 = factories.Tag.stub().name

    vocab = factories.Vocabulary(tags=[
        {
            "name": tag_name1
        },
        {
            "name": tag_name2
        },
    ])
    key = ("tags", 0, "__extras")
    data = {
        ("tags", 0, "__extras"): {
            "name": tag_name1,
            "vocabulary_id": vocab["id"],
        },
        ("tags", 0, "vocabulary_id"): vocab["id"],
        ("tags", 1, "__extras"): {
            "name": tag_name2,
            "vocabulary_id": None
        },
        ("tags", 1, "vocabulary_id"): None,
    }
    errors = []
    context = {"model": model, "session": model.Session}
    converters.free_tags_only(key, data, errors, context)
    assert len(data) == 2
    assert ("tags", 1, "vocabulary_id") in data.keys()
    assert ("tags", 1, "__extras") in data.keys()
Exemple #4
0
    def test_basic(self):
        vocab = factories.Vocabulary()
        helpers.call_action("vocabulary_delete", id=vocab["id"])

        assert vocab["id"] not in {
            v["name"]
            for v in helpers.call_action("vocabulary_list")
        }
Exemple #5
0
def test_convert_to_tags():
    tag_name = factories.Tag.stub().name
    vocab = factories.Vocabulary(tags=[{"name": tag_name}])
    key = ("vocab_tags", )
    data = {key: tag_name}
    context = {"model": model, "session": model.Session}
    converters.convert_to_tags(vocab["name"])(key, data, [], context)

    assert data[("tags", 0, "name")] == tag_name
    assert data[("tags", 0, "vocabulary_id")] == vocab["id"]
    def test_vocabulary_dictize_not_including_datasets(self):
        """By default datasets should not be included in vocab dicts."""
        vocab_dict = factories.Vocabulary(
            tags=[dict(name="test_tag_1"), dict(name="test_tag_2")])
        factories.Dataset(tags=vocab_dict["tags"])
        vocab_obj = model.Vocabulary.get(vocab_dict["name"])

        vocab_dict = model_dictize.vocabulary_dictize(
            vocab_obj, context={"model": model})

        assert len(vocab_dict["tags"]) == 2
        for tag in vocab_dict["tags"]:
            assert len(tag.get("packages", [])) == 0
    def test_vocabulary_dictize_including_datasets(self):
        """include_datasets=True should include datasets in vocab dicts."""
        vocab_dict = factories.Vocabulary(
            tags=[dict(name="test_tag_1"), dict(name="test_tag_2")])
        factories.Dataset(tags=vocab_dict["tags"])
        vocab_obj = model.Vocabulary.get(vocab_dict["name"])

        vocab_dict = model_dictize.vocabulary_dictize(
            vocab_obj, context={"model": model}, include_datasets=True)

        assert len(vocab_dict["tags"]) == 2
        for tag in vocab_dict["tags"]:
            assert len(tag["packages"]) == 1
Exemple #8
0
    def test_basic(self):
        vocab = factories.Vocabulary()
        helpers.call_action("vocabulary_delete", id=vocab["id"])

        assert helpers.call_action("vocabulary_list") == []