Exemplo n.º 1
0
def test_create_update_item_single():
    """
    GIVEN database that has a different record and sub and spec id
    WHEN create_update_item is called on Spec with the sub, spec id
    THEN an new item is created with the sub and spec id and updated_at with the
        current time
    AND another similar record with updated_at set to latest
    """
    initial_item_name = "name 1"
    initial_item = factory.SpecFactory(
        sub="sub 1", name=initial_item_name, id=initial_item_name
    )
    initial_item.save()
    sub = "sub 2"
    name = "name 2"
    version = "version 2"
    model_count = 21

    models.Spec.create_update_item(
        sub=sub, name=name, version=version, model_count=model_count
    )

    items = list(
        models.Spec.query(
            sub,
            (models.Spec.updated_at_id.startswith("0")),
        )
    )
    assert len(items) == 1
    [item] = items
    assert item.sub == sub
    assert item.name == name
    assert int(item.updated_at) == pytest.approx(time.time(), abs=10)

    items = list(
        models.Spec.query(
            sub,
            models.Spec.updated_at_id.startswith(f"{models.Spec.UPDATED_AT_LATEST}#"),
        )
    )
    assert len(items) == 1
    [item] = items
    assert item.sub == sub
    assert item.name == name
    assert int(item.updated_at) == pytest.approx(time.time(), abs=10)

    items = list(models.Spec.scan())
    assert len(items) == 3
Exemplo n.º 2
0
def test_item_to_info(title, description, expected_spec_info):
    """
    GIVEN title and description
    WHEN Spec is constructed with the title and description
    THEN the expected spec info is returned.
    """
    item = factory.SpecFactory(title=title, description=description)
    expected_spec_info["name"] = item.name
    expected_spec_info["id"] = item.id
    expected_spec_info["version"] = item.version
    expected_spec_info["model_count"] = item.model_count
    expected_spec_info["updated_at"] = int(item.updated_at)

    spec_info = models.Spec.item_to_info(item)

    assert spec_info == expected_spec_info
Exemplo n.º 3
0
"""Tests for the models."""

import pytest
from open_alchemy.package_database import factory, models

LIST_SPECS_TESTS = [
    pytest.param([], "sub 1", [], id="empty"),
    pytest.param(
        [
            factory.SpecFactory(
                sub="sub 1",
                updated_at_id=(f"{models.Spec.UPDATED_AT_LATEST}#name 1"),
            )
        ],
        "sub 2",
        [],
        id="single sub miss",
    ),
    pytest.param(
        [factory.SpecFactory(
            sub="sub 1",
            updated_at_id="11#",
        )],
        "sub 1",
        [],
        id="single updated_at_id miss",
    ),
    pytest.param(
        [
            factory.SpecFactory(
                sub="sub 1",
Exemplo n.º 4
0
"""Tests for the models get_item."""

import pytest
from open_alchemy.package_database import exceptions, factory, models

GET_ITEM_MISS_TESTS = [
    pytest.param([], "sub 1", "name 1", id="empty"),
    pytest.param(
        [
            factory.SpecFactory(
                sub="sub 1",
                name="name 1",
                id="name 1",
                updated_at_id=f"{models.Spec.UPDATED_AT_LATEST}#name 1",
            )
        ],
        "sub 2",
        "name 1",
        id="single sub miss",
    ),
    pytest.param(
        [
            factory.SpecFactory(
                sub="sub 1",
                name="name 1",
                id="name 1",
                updated_at_id=f"{models.Spec.UPDATED_AT_LATEST}#name 1",
            )
        ],
        "sub 1",
        "name 2",
Exemplo n.º 5
0
"""Tests for the models."""

import pytest
from open_alchemy.package_database import factory, models

COUNT_CUSTOMER_MODELS_TESTS = [
    pytest.param([], "sub 2", 0, id="empty"),
    pytest.param(
        [factory.SpecFactory(sub="sub 1")],
        "sub 1",
        0,
        id="single item sub miss",
    ),
    pytest.param(
        [factory.SpecFactory(sub="sub 1", updated_at_id="11#spec 1")],
        "sub 1",
        0,
        id="single item sub hit updated_at miss",
    ),
    pytest.param(
        [
            factory.SpecFactory(
                sub="sub 1",
                updated_at_id=f"{models.Spec.UPDATED_AT_LATEST}#spec 1",
                model_count=12,
            )
        ],
        "sub 1",
        12,
        id="single item sub hit updated_at hit",
    ),
Exemplo n.º 6
0
"""Tests for the models."""

import pytest
from open_alchemy.package_database import factory, models

DELETE_ITEM_TESTS = [
    pytest.param([], "sub 1", "name 1", 0, id="empty"),
    pytest.param(
        [
            factory.SpecFactory(
                sub="sub 1",
                name="name 1",
                id="name 1",
                id_updated_at="name 1#11",
            )
        ],
        "sub 2",
        "name 1",
        1,
        id="single sub miss",
    ),
    pytest.param(
        [
            factory.SpecFactory(
                sub="sub 1",
                name="name 1",
                id="name 1",
                id_updated_at="name 1#11",
            )
        ],
        "sub 1",
"""Tests for the models."""

import pytest
from open_alchemy.package_database import exceptions, factory, models

GET_LATEST_VERSION_NOT_FOUND_TESTS = [
    pytest.param([], "sub 1", "name 1", id="empty"),
    pytest.param(
        [
            factory.SpecFactory(
                sub="sub 2",
                name="name 1",
                id="name 1",
                updated_at_id=f"{models.Spec.UPDATED_AT_LATEST}#",
            )
        ],
        "sub 1",
        "name 1",
        id="single item sub miss",
    ),
    pytest.param(
        [
            factory.SpecFactory(
                sub="sub 1",
                name="name 2",
                id="name 2",
                updated_at_id=f"{models.Spec.UPDATED_AT_LATEST}#",
            )
        ],
        "sub 1",
        "name 1",
Exemplo n.º 8
0
"""Tests for the models."""

import pytest
from open_alchemy.package_database import factory, models

LIST_VERSIONS_TESTS = [
    pytest.param([], "sub 1", "name 1", [], id="empty"),
    pytest.param(
        [
            factory.SpecFactory(
                sub="sub 1",
                updated_at="11",
                id_updated_at="name 1#11",
                updated_at_id="11#name 1",
            )
        ],
        "sub 2",
        "name 1",
        [],
        id="single sub miss",
    ),
    pytest.param(
        [
            factory.SpecFactory(
                sub="sub 1",
                updated_at="11",
                id_updated_at="name 1#11",
                updated_at_id="11#name 1",
            )
        ],
        "sub 1",
Exemplo n.º 9
0
"""Tests for the models."""

import pytest
from open_alchemy.package_database import factory, models

DELETE_ALL_TESTS = [
    pytest.param([], "sub 1", 0, id="empty"),
    pytest.param([factory.SpecFactory(sub="sub 1")],
                 "sub 2",
                 1,
                 id="single sub miss"),
    pytest.param([factory.SpecFactory(sub="sub 1")],
                 "sub 1",
                 0,
                 id="single sub hit"),
    pytest.param(
        [
            factory.SpecFactory(sub="sub 1"),
            factory.SpecFactory(sub="sub 2"),
        ],
        "sub 3",
        2,
        id="multiple sub miss",
    ),
    pytest.param(
        [
            factory.SpecFactory(sub="sub 1"),
            factory.SpecFactory(sub="sub 2"),
        ],
        "sub 1",
        1,