예제 #1
0
def test_exact_match_first():
    query_t = Query(Collection.ABILITY).exact_match_first(True)
    query_f = Query(Collection.ABILITY).exact_match_first(False)

    assert query_t.parameters == {
        "c:exactMatchFirst": ["true"],
    }
    assert query_f.parameters == {
        "c:exactMatchFirst": ["false"],
    }
예제 #2
0
def test_retry():
    query_t = Query(Collection.ABILITY).retry(True)
    query_f = Query(Collection.ABILITY).retry(False)

    assert query_t.parameters == {
        "c:retry": ["true"],
    }
    assert query_f.parameters == {
        "c:retry": ["false"],
    }
예제 #3
0
def test_timing():
    query_t = Query(Collection.ABILITY).timing(True)
    query_f = Query(Collection.ABILITY).timing(False)

    assert query_t.parameters == {
        "c:timing": ["true"],
    }
    assert query_f.parameters == {
        "c:timing": ["false"],
    }
예제 #4
0
def test_include_null():
    query_t = Query(Collection.ABILITY).include_null(True)
    query_f = Query(Collection.ABILITY).include_null(False)

    assert query_t.parameters == {
        "c:includeNull": ["true"],
    }
    assert query_f.parameters == {
        "c:includeNull": ["false"],
    }
예제 #5
0
def test_equality():
    query1 = Query(Collection.ABILITY).retry(False)
    query2 = Query(Collection.ABILITY).retry(False)

    assert query1 == query2

    query1 = query1.lang("en")

    assert query1 != query2

    assert query1 != object()
예제 #6
0
def test_query():
    query = Query(
        Collection.ABILITY,
        endpoint="someendpoint",
        service_id="someserviceid",
        namespace=Namespace.PS2_V2,
    )

    assert query._get_url(
        Verb.GET) == "someendpoint/s:someserviceid/get/ps2:v2/ability"
    assert (query._get_url(
        Verb.COUNT) == "someendpoint/s:someserviceid/count/ps2:v2/ability")
예제 #7
0
def test_filter():
    query = (Query(Collection.ABILITY).filter("fieldname",
                                              "fieldvalue").filter(
                                                  "anotherfieldname",
                                                  "anotherfieldvalue",
                                                  SearchModifier.STARTS_WITH))

    assert query.parameters == {
        "fieldname": ["fieldvalue"],
        "anotherfieldname": ["^anotherfieldvalue"],
    }
예제 #8
0
def test_factory():
    query: Query = Query(Collection.ABILITY).retry(False)

    factory: Callable[[], Query] = query.get_factory()
    new_query: Query = factory()

    assert new_query == query

    query = query.exact_match_first(True)

    assert new_query != query
예제 #9
0
def test_show():
    query = Query(Collection.ABILITY).show("field1", "field2")

    assert query.parameters == {
        "c:show": ["field1,field2"],
    }
예제 #10
0
def test_service_id():
    query = Query(Collection.ABILITY)
    assert query.service_id == "example"

    query.set_service_id("someserviceid")
    assert query.service_id == "someserviceid"
예제 #11
0
weapon_datasheet_join_factory: Callable[[], Join] = (Join(
    Collection.WEAPON_DATASHEET).on("item_id").to("item_id").inject_at(
        "weapon_datasheet").get_factory())

# Query
trac_5_query: Query = (Query(Collection.ITEM).lang("en").filter(
    "name.en", "TRAC-5").join(item_to_weapon_join_factory().nest(
        weapon_join_factory().nest(weapon_to_fire_group_join_factory().nest(
            fire_group_join_factory().nest(
                fire_group_to_fire_mode_join_factory().nest(
                    fire_mode_join_factory().nest(
                        player_state_group_join_factory()).nest(
                            fire_mode_to_projectile_join_factory().nest(
                                projectile_join_factory()))))))
    )).join(item_to_weapon_join_factory().nest(weapon_join_factory().nest(
        weapon_to_fire_group_join_factory().nest(
            fire_group_join_factory().nest(
                fire_group_to_fire_mode_join_factory().nest(
                    fire_mode_join_factory().nest(
                        fire_mode_to_damage_direct_effect_join_factory()))))
    ))).join(item_to_weapon_join_factory().nest(weapon_join_factory().nest(
        weapon_to_fire_group_join_factory().nest(fire_group_join_factory(
        ).nest(fire_group_to_fire_mode_join_factory().nest(
            fire_mode_join_factory().nest(
                fire_mode_to_damage_indirect_effect_join_factory()))))))).join(
                    item_attachment_join_factory()).join(
                        weapon_datasheet_join_factory()))

# Execute query and print results
if __name__ == "__main__":
    import json
예제 #12
0
from ps2_census import Collection, Query

from .joins import (
    fire_group_to_fire_mode_join_factory,
    fire_mode_join_factory,
    fire_mode_to_ability_join_factory,
    fire_mode_to_damage_direct_effect_join_factory,
    fire_mode_to_damage_indirect_effect_join_factory,
    fire_mode_to_projectile_join_factory,
    player_state_group_join_factory,
    projectile_join_factory,
)

fire_group_query_factory: Callable[[], Query] = (
    Query(Collection.FIRE_GROUP).lang("en").sort(
        ("fire_group_id", 1)).join(fire_group_to_fire_mode_join_factory().nest(
            fire_mode_join_factory().nest(
                player_state_group_join_factory()))).join(
                    fire_group_to_fire_mode_join_factory().nest(
                        fire_mode_join_factory().nest(
                            fire_mode_to_damage_direct_effect_join_factory())))
    .join(fire_group_to_fire_mode_join_factory().nest(fire_mode_join_factory(
    ).nest(fire_mode_to_damage_indirect_effect_join_factory()))).join(
        fire_group_to_fire_mode_join_factory().nest(
            fire_mode_join_factory().nest(
                fire_mode_to_ability_join_factory()))).join(
                    fire_group_to_fire_mode_join_factory().nest(
                        fire_mode_join_factory().nest(
                            fire_mode_to_projectile_join_factory().nest(
                                projectile_join_factory())))).get_factory())
예제 #13
0
def test_has():
    query = Query(Collection.ABILITY).has("field1", "field2")

    assert query.parameters == {
        "c:has": ["field1,field2"],
    }
예제 #14
0
def test_tree():
    tree = Tree("somefield")
    query = Query(Collection.ABILITY).tree(tree)

    assert query.parameters == {"c:tree": [str(tree)]}
예제 #15
0
def test_multi_join():
    join_1 = Join(Collection.ACHIEVEMENT)
    join_2 = Join(Collection.CHARACTER)
    query = Query(Collection.ABILITY).join(join_1).join(join_2)

    assert query.parameters == {"c:join": [str(join_1), str(join_2)]}
예제 #16
0
def test_join():
    join = Join(Collection.ACHIEVEMENT)
    query = Query(Collection.ABILITY).join(join)

    assert query.parameters == {"c:join": [str(join)]}
예제 #17
0
def test_lang():
    query = Query(Collection.ABILITY).lang("en")

    assert query.parameters == {
        "c:lang": ["en"],
    }
예제 #18
0
def test_sort():
    query = Query(Collection.ABILITY).sort(("field1", 1), ("field2", -1))

    assert query.parameters == {
        "c:sort": ["field1:1,field2:-1"],
    }
예제 #19
0
def test_limit_per_db():
    query = Query(Collection.ABILITY).limit_per_db(100)

    assert query.parameters == {"c:limitPerDB": ["100"]}
예제 #20
0
from ps2_census import Collection, Join, Query
from ps2_census.enums import Faction
from slugify import slugify

from utils import batch

ACTIVITY_PERIOD: int = 12 * 60 * 60

character_events_query_factory: Callable[[], Query] = Query(
    Collection.CHARACTERS_EVENT).join(
        Join(Collection.ACHIEVEMENT).on("achievement_id").to("achievement_id").
        inject_at("achievement")).join(
            Join(Collection.CHARACTER).outer(0).on("character_id").
            to("character_id").inject_at("character")).join(
                Join(Collection.CHARACTER).on("attacker_character_id").
                to("character_id").inject_at("attacker_character")).join(
                    Join(Collection.ITEM).on("attacker_weapon_id").
                    to("item_id").inject_at("attacker_weapon_item")).join(
                        Join(Collection.VEHICLE).on("attacker_vehicle_id").to(
                            "vehicle_id").inject_at("vehicle")).sort(
                                ("timestamp", -1)).get_factory()

outfit_members_query_factory: Callable[[], Query] = (Query(
    Collection.OUTFIT).join(
        Join(Collection.OUTFIT_MEMBER).on("outfit_id").to("outfit_id").
        outer(0).list(1).inject_at("members").nest(
            Join(Collection.CHARACTER).on("character_id").to("character_id").
            outer(0).inject_at("character"))).get_factory())

예제 #21
0
def test_limit():
    query = Query(Collection.ABILITY).limit(100)

    assert query.parameters == {"c:limit": ["100"]}
예제 #22
0
def test_distinct():
    query = Query(Collection.ABILITY).distinct("somefield")

    assert query.parameters == {"c:distinct": ["somefield"]}
예제 #23
0
def test_start():
    query = Query(Collection.ABILITY).start(100)

    assert query.parameters == {"c:start": ["100"]}
예제 #24
0
from typing import Callable

from ps2_census import Collection, Query

from .joins import (
    item_attachment_join_factory,
    item_to_weapon_join_factory,
    weapon_datasheet_join_factory,
    weapon_join_factory,
    weapon_to_fire_group_join_factory,
)

weapon_query_factory: Callable[[], Query] = (Query(
    Collection.ITEM).lang("en").sort(("item_id", 1)).join(
        item_to_weapon_join_factory().nest(weapon_join_factory().nest(
            weapon_to_fire_group_join_factory()))).join(
                item_attachment_join_factory()).join(
                    weapon_datasheet_join_factory()).get_factory())