Beispiel #1
0
    def add_releases(self, band,fname):
        #bulk_releases = []
        for release in band['detailed_discography']:
            # Removing 'parsed' key to account for Tobias' horribly architected data.
            release.pop('parsed', None)

            name = release.keys()[0]
            print 'Adding release name: %s' % name
            r = Release(
                band=Band.objects.get(ma_id=band['id']),
                name=name,
                notes=release[name]['album_notes'],
                length=release[name]['length'],
                release_id=release[name]['release_id'],
                release_type=release[name]['type'],
                release_year=release[name]['year']
            )
            print 'The release '+r.band.url
            print 'The file: '+fname
            #try:
            #Release.get(release_id=r.release_id)
            r.save()
            #bulk_releases.append(r)
            self.add_songs(release, r.release_id)
            self.add_release_lineup(release, r.release_id)
Beispiel #2
0
def test_get_releases(client: TestClient, session: db.Session):
    """Releases endpoint must return a list of all releases"""
    master_set = Release(name="Master Set")
    master_set.is_public = True
    session.add(master_set)
    session.commit()
    response = client.get("/v2/releases")
    assert response.status_code == status.HTTP_200_OK
    assert len(response.json()) == 1
Beispiel #3
0
def test_get_releases_public_only(client: TestClient, session: db.Session):
    """Releases list must only include public releases"""
    master_set = Release(name="Master Set")
    master_set.is_public = True
    session.add(master_set)
    session.add(Release(name="Unreleased"))
    session.commit()
    response = client.get("/v2/releases")
    assert response.status_code == status.HTTP_200_OK
    data = response.json()
    assert len(data) == 1
    assert data[0]["stub"] == master_set.stub
Beispiel #4
0
def test_put_releases_bad_release(client: TestClient, session: db.Session):
    """Putting a nonsense stub must work"""
    master_set = Release(name="Master Set")
    master_set.is_public = True
    session.add(master_set)
    session.commit()
    user, token = create_user_token(session)
    response = client.put(
        "/v2/releases/mine",
        json=["fake-set"],
        headers={"Authorization": f"Bearer {token}"},
    )
    assert response.status_code == status.HTTP_200_OK
    data = response.json()
    assert data[0]["stub"] == master_set.stub
    assert data[0]["is_mine"] == False
Beispiel #5
0
def test_patch_release_non_admin(client: TestClient, session: db.Session):
    """Patching a release must require admin access"""
    master_set = Release(name="Master Set")
    session.add(master_set)
    session.commit()
    user, token = create_user_token(session)
    response = client.patch(
        f"/v2/releases/{master_set.stub}",
        json={"is_public": True},
        headers={"Authorization": f"Bearer {token}"},
    )
    assert response.status_code == status.HTTP_403_FORBIDDEN
Beispiel #6
0
    def add_releases(self, band, fname):
        #bulk_releases = []
        for release in band['detailed_discography']:
            # Removing 'parsed' key to account for Tobias' horribly architected data.
            release.pop('parsed', None)

            name = release.keys()[0]
            print 'Adding release name: %s' % name
            r = Release(band=Band.objects.get(ma_id=band['id']),
                        name=name,
                        notes=release[name]['album_notes'],
                        length=release[name]['length'],
                        release_id=release[name]['release_id'],
                        release_type=release[name]['type'],
                        release_year=release[name]['year'])
            print 'The release ' + r.band.url
            print 'The file: ' + fname
            #try:
            #Release.get(release_id=r.release_id)
            r.save()
            #bulk_releases.append(r)
            self.add_songs(release, r.release_id)
            self.add_release_lineup(release, r.release_id)
Beispiel #7
0
def test_patch_release(client: TestClient, session: db.Session):
    """Patching a release to set it public must work"""
    master_set = Release(name="Master Set")
    session.add(master_set)
    session.commit()
    assert master_set.is_public == False
    admin, token = create_admin_token(session)
    response = client.patch(
        f"/v2/releases/{master_set.stub}",
        json={"is_public": True},
        headers={"Authorization": f"Bearer {token}"},
    )
    assert response.status_code == status.HTTP_200_OK
    session.refresh(master_set)
    assert master_set.is_public == True
Beispiel #8
0
def test_get_releases_legacy(client: TestClient, session: db.Session):
    """Releases list must only show legacy releases when they are requested"""
    master_set = Release(name="Master Set")
    master_set.is_public = True
    session.add(master_set)
    core_set = Release(name="Core Set")
    core_set.is_legacy = True
    core_set.is_public = True
    session.add(core_set)
    session.commit()
    response = client.get("/v2/releases")
    assert response.status_code == status.HTTP_200_OK
    data = response.json()
    assert len(data) == 1
    assert data[0]["stub"] == master_set.stub
    response = client.get("/v2/releases", params={"show_legacy": True})
    assert response.status_code == status.HTTP_200_OK
    data = response.json()
    assert len(data) == 1
    assert data[0]["stub"] == core_set.stub
Beispiel #9
0
def test_get_releases_mine(client: TestClient, session: db.Session):
    """Releases list must mark which releases are in the user's collection"""
    master_set = Release(name="Master Set")
    master_set.is_public = True
    session.add(master_set)
    first_expansion = Release(name="First Expansion")
    first_expansion.is_public = True
    session.add(first_expansion)
    session.commit()
    user, token = create_user_token(session)
    session.add(UserRelease(release_id=master_set.id, user_id=user.id))
    session.commit()
    response = client.get(
        "/v2/releases",
        headers={"Authorization": f"Bearer {token}"},
    )
    assert response.status_code == status.HTTP_200_OK
    data = response.json()
    assert data[0]["stub"] == master_set.stub
    assert data[0]["is_mine"] == True
    assert data[1]["is_mine"] == False
Beispiel #10
0
def test_put_releases(client: TestClient, session: db.Session):
    """Putting my releases must work"""
    master_set = Release(name="Master Set")
    master_set.is_public = True
    session.add(master_set)
    first_expansion = Release(name="First Expansion")
    first_expansion.is_public = True
    session.add(first_expansion)
    session.commit()
    user, token = create_user_token(session)
    assert (session.query(UserRelease).filter(
        UserRelease.user_id == user.id).count() == 0)
    response = client.put(
        "/v2/releases/mine",
        json=[master_set.stub],
        headers={"Authorization": f"Bearer {token}"},
    )
    assert response.status_code == status.HTTP_200_OK
    data = response.json()
    assert data[0]["stub"] == master_set.stub
    assert data[0]["is_mine"] == True
    assert data[1]["is_mine"] == False
Beispiel #11
0
def create_cards_for_decks(session: db.Session):
    """This utility function populates a set of cards appropriate for testing deck building"""
    # First create our two releases
    master_set = Release("Master Set")
    master_set.is_public = True
    expansion = Release("Expansion")
    expansion.is_public = True
    session.add(master_set)
    session.add(expansion)
    session.commit()
    # Then create two Phoenixborns (with uniques), and 18 other cards spanning all card types
    #  (to ensure that we can filter by release, preconstructed decks, etc.)
    card_dicts = [
        {
            "name": "One Phoenixborn",
            "card_type": "Phoenixborn",
            "release": master_set,
            "text": "Command Strike: [[side]] - 2 [[basic]]: Do stuff.",
            "effect_magic_cost": "2 [[basic]]",
            "battlefield": 4,
            "life": 20,
            "spellboard": 5,
        },
        {
            "name": "One Conjuration A",
            "card_type": "Conjuration",
            "release": master_set,
            "placement": "Battlefield",
            "text": "* Consume: Do stuff.",
            "life": 4,
            "attack": "X",
            "copies": 1,
            "recover": 3,
            "phoenixborn": "One Phoenixborn",
        },
        {
            "name": "Summon One Conjuration A",
            "card_type": "Ready Spell",
            "release": master_set,
            "placement": "Spellboard",
            "cost": ["[[main]]"],
            "text": "[[main]] - [[exhaust]] - 1 [[charm:power]] - 1 [[natural:power]]: Place a [[One Conjuration A]] conjuration onto your battlefield.",
            "phoenixborn": "One Phoenixborn",
        },
        {
            "name": "One Conjuration B",
            "card_type": "Conjuration",
            "release": master_set,
            "placement": "Battlefield",
            "text": "Unit Guard: Do stuff.",
            "attack": 0,
            "life": 2,
            "recover": 0,
            "copies": 2,
        },
        {
            "name": "Summon One Conjuration B",
            "card_type": "Ready Spell",
            "release": master_set,
            "placement": "Spellboard",
            "cost": ["[[main]]", "1 [[charm:class]]"],
            "text": "[[main]] - [[exhaust]] - 1 [[natural:class]]: Place a [[One Conjuration B]] conjuration onto your battlefield.",
        },
        {
            "name": "One Ready Spell A",
            "card_type": "Ready Spell",
            "release": master_set,
            "placement": "Spellboard",
            "cost": ["[[main]]"],
            "text": "[[side]] - [[exhaust]] - 2 [[charm:class]]: Do stuff.",
        },
        {
            "name": "One Ready Spell B",
            "card_type": "Ready Spell",
            "release": master_set,
            "placement": "Spellboard",
            "cost": ["[[side]]", "1 [[basic]]"],
            "text": "[[main]] - [[exhaust]] - 1 [[natural:class]] or 1 [[sympathy:class]]: Do stuff.",
        },
        {
            "name": "One Action Spell A",
            "card_type": "Action Spell",
            "release": master_set,
            "placement": "Discard",
            "cost": ["[[main]]", "2 [[natural:power]]"],
            "text": "Do stuff.",
        },
        {
            "name": "One Action Spell B",
            "card_type": "Action Spell",
            "release": master_set,
            "placement": "Discard",
            "cost": ["[[main]]", "1 [[charm:class]]", "1 [[basic]]"],
            "text": "Do stuff.",
        },
        {
            "name": "One Action Spell C",
            "card_type": "Action Spell",
            "release": master_set,
            "placement": "Discard",
            "cost": ["[[main]]", "1 [[charm:class]]", "1 [[basic]]"],
            "text": "Do stuff.",
        },
        {
            "name": "One Reaction Spell",
            "card_type": "Reaction Spell",
            "release": master_set,
            "placement": "Discard",
            "cost": ["1 [[charm:power]]"],
            "text": "You may play this spell after an opponent targets a unit you control with a spell, ability, or dice power. Do stuff.",
        },
        {
            "name": "One Alteration Spell",
            "card_type": "Alteration Spell",
            "release": master_set,
            "placement": "Unit",
            "cost": ["[[side]]", "1 [[natural:class]]"],
            "text": "This unit now has the following ability:\n\n* Armored 1: Do stuff.",
            "life": "+1",
        },
        {
            "name": "One Ally",
            "card_type": "Ally",
            "release": master_set,
            "placement": "Battlefield",
            "cost": ["[[main]]", "1 [[charm:class]]"],
            "text": "Song of Sorrow: [[side]] - [[exhaust]]: Do stuff.",
            "attack": 1,
            "life": 1,
            "recover": 1,
        },
        # And define cards for a single expansion
        {
            "name": "Two Conjured Alteration Spell",
            "card_type": "Conjured Alteration Spell",
            "release": expansion,
            "placement": "Unit",
            "life": "+1",
            "copies": 5,
            "phoenixborn": "Two Phoenixborn",
        },
        {
            "name": "Two Phoenixborn",
            "text": "Ice Buff: [[side]] - [[exhaust]]: Attach an [[Two Conjured Alteration Spell]] conjured alteration spell to a target unit you control.",
            "card_type": "Phoenixborn",
            "release": expansion,
            "battlefield": 6,
            "life": 17,
            "spellboard": 4,
        },
        {
            "name": "Two's Reaction Spell",
            "card_type": "Reaction Spell",
            "release": expansion,
            "placement": "Discard",
            "cost": ["2 [[basic]]"],
            "text": "You may play this spell after a unit you control is dealt damage by a unit's attack. Prevent that damage from being received. Destroy that target attacking unit.",
            "phoenixborn": "Two Phoenixborn",
        },
        {
            "name": "Two Conjuration A",
            "card_type": "Conjuration",
            "release": expansion,
            "placement": "Battlefield",
            "text": "* Skin Morph 2: Do stuff.",
            "attack": 3,
            "life": 2,
            "recover": 0,
            "copies": 3,
        },
        {
            "name": "Summon Two Conjuration A",
            "card_type": "Ready Spell",
            "release": expansion,
            "placement": "Spellboard",
            "cost": ["[[main]]"],
            "text": "[[main]] - [[exhaust]] - 2 [[natural:class]] - 1 [[basic]]: Place an [[Two Conjuration A]] conjuration onto your battlefield.\n\nFocus 2: Do stuff.",
        },
        {
            "name": "Two Conjuration D",
            "card_type": "Conjuration",
            "release": expansion,
            "placement": "Battlefield",
            "text": "* Inheritance 1: Do stuff.",
            "attack": 3,
            "life": 2,
            "recover": 0,
            "copies": 6,
        },
        {
            "name": "Two Conjuration C",
            "card_type": "Conjuration",
            "release": expansion,
            "placement": "Battlefield",
            "text": "Blossom: [[main]]: Place up to 2 [[Two Conjuration D]] conjurations onto your battlefield.",
            "attack": 0,
            "life": 2,
            "recover": 0,
            "copies": 3,
        },
        {
            "name": "Two Conjuration B",
            "card_type": "Conjuration",
            "release": expansion,
            "placement": "Battlefield",
            "text": "* Germinate: When this unit is destroyed, place a [[Two Conjuration C]] conjuration onto your battlefield.",
            "attack": 2,
            "life": 1,
            "recover": 0,
            "copies": 3,
        },
        {
            "name": "Summon Two Conjuration B",
            "card_type": "Ready Spell",
            "release": expansion,
            "placement": "Spellboard",
            "cost": ["[[main]]"],
            "text": "[[main]] - [[exhaust]] - 1 [[natural:class]] - 1 [[sympathy:class]]: Place an [[Two Conjuration B]] conjuration onto your battlefield.\n\nFocus 1: Do stuff.",
        },
        {
            "name": "Two Ready Spell",
            "card_type": "Ready Spell",
            "release": expansion,
            "placement": "Spellboard",
            "cost": ["[[main]]"],
            "text": "[[main]] - [[exhaust]] - 1 [[natural:class]]: Do stuff.",
        },
        {
            "name": "Two Reaction Spell",
            "card_type": "Reaction Spell",
            "release": expansion,
            "placement": "Discard",
            "cost": ["1 [[natural:class]]"],
            "text": "You may play this spell after a unit with a life value of 2 or less comes into play. Destroy that target unit.",
        },
        {
            "name": "Two Alteration Spell",
            "card_type": "Alteration Spell",
            "release": expansion,
            "placement": "Unit",
            "cost": ["[[main]]", "1 [[natural:class]]"],
            "text": "* When attaching this spell, place 3 status tokens on this spell. Discard this spell when it no longer has any status tokens on it. As long as this spell is attached to this unit, this unit is considered to be exhausted. This unit now has the following ability:\n\n* Thaw: [[side]]: Remove 1 status token from a Deep Freeze alteration spell attached to this unit.",
        },
        {
            "name": "Two Action Spell",
            "card_type": "Action Spell",
            "release": expansion,
            "placement": "Discard",
            "cost": ["[[main]]", "2 [[natural:class]]"],
            "text": "Deal 2 damage to a target unit. Remove 2 status tokens from that unit.",
        },
        {
            "name": "Two Ally A",
            "card_type": "Ally",
            "release": expansion,
            "placement": "Battlefield",
            "cost": ["[[main]]", "2 [[natural:class]]"],
            "text": "* Armored 1: After this unit is dealt damage, prevent 1 damage from being received.",
            "attack": 3,
            "life": 1,
            "recover": 1,
        },
        {
            "name": "Two Ally B",
            "card_type": "Ally",
            "release": expansion,
            "placement": "Battlefield",
            "cost": ["[[main]]", "1 [[sympathy:class]]", "1 [[basic]]"],
            "text": "* Last Orders 1: When this unit is destroyed, you may spend 1 [[basic]] to do stuff.\n\n* Inheritance 1: Do stuff.",
            "attack": 2,
            "life": 2,
            "recover": 1,
        },
        {
            "name": "Two Ally C",
            "card_type": "Ally",
            "release": expansion,
            "placement": "Battlefield",
            "cost": ["[[main]]", "2 [[natural:class]]"],
            "text": "Slumbering 1: Do stuff.",
            "attack": 4,
            "life": 4,
            "recover": 2,
        },
    ]
    # Create our cards
    for card_dict in card_dicts:
        create_card(session, **card_dict)