import pytest
import Advert
import json


def test_ok():
    input_json = """{
    "title": "python",
    "price": 10,
    "location": {
        "address": "город Москва, Лесная, 7",
        "metro_stations": ["Белорусская"]
        }
    }"""
    actual = Advert.get_obj_from_json(json.loads(input_json), Advert.Advert)
    expected_address = "город Москва, Лесная, 7"
    assert actual.location.address == expected_address


def test_ok_without_price_in_json():
    input_json = """{
    "title": "python",
    "location": {
        "address": "город Москва, Лесная, 7",
        "metro_stations": ["Белорусская"]
        }
    }"""
    actual = Advert.get_obj_from_json(json.loads(input_json), Advert.Advert)
    expected_price = 0
    assert actual.price == expected_price


def test_fail_invalid_price_scan():
    input_json = """{
    "title": "python",
    "price": -10,
    "location": {
        "address": "город Москва, Лесная, 7",
        "metro_stations": ["Белорусская"]
        }
    }"""
    with pytest.raises(ValueError):
        Advert.get_obj_from_json(json.loads(input_json), Advert.Advert)


def test_fail_invalid_price_set():
    input_json = """{
    "title": "python",
    "price": 10,
    "location": {
        "address": "город Москва, Лесная, 7",
        "metro_stations": ["Белорусская"]
        }
    }"""

    adv = Advert.get_obj_from_json(json.loads(input_json), Advert.Advert)
    with pytest.raises(ValueError):
        adv.price = -1

import pytest
import Advert
import json


def test_ok():
    input_json = """{
    "title": "python",
    "price": 10,
    "location": {
        "address": "город Москва, Лесная, 7",
        "metro_stations": ["Белорусская"]
        }
    }"""
    actual = Advert.get_obj_from_json(json.loads(input_json), Advert.Advert)
    expected_address = "город Москва, Лесная, 7"
    assert actual.location.address == expected_address


def test_ok_without_price_in_json():
    input_json = """{
    "title": "python",
    "location": {
        "address": "город Москва, Лесная, 7",
        "metro_stations": ["Белорусская"]
        }
    }"""
    actual = Advert.get_obj_from_json(json.loads(input_json), Advert.Advert)
    expected_price = 0
    assert actual.price == expected_price


def test_fail_invalid_price_scan():
    input_json = """{
    "title": "python",
    "price": -10,
    "location": {
        "address": "город Москва, Лесная, 7",
        "metro_stations": ["Белорусская"]
        }
    }"""
    with pytest.raises(ValueError):
        Advert.get_obj_from_json(json.loads(input_json), Advert.Advert)


def test_fail_invalid_price_set():
    input_json = """{
    "title": "python",
    "price": 10,
    "location": {
        "address": "город Москва, Лесная, 7",
        "metro_stations": ["Белорусская"]
        }
    }"""

    adv = Advert.get_obj_from_json(json.loads(input_json), Advert.Advert)
    with pytest.raises(ValueError):
        adv.price = -1

{     "title": "python",     "price": 10,     "location": {         "address": "город Москва, Лесная, 7",         "metro_stations": ["Белорусская"]         }     } {     "title": "python",     "location": {         "address": "город Москва, Лесная, 7",         "metro_stations": ["Белорусская"]         }     } {     "title": "python",     "price": -10,     "location": {         "address": "город Москва, Лесная, 7",         "metro_stations": ["Белорусская"]         }     } {     "title": "python",     "price": 10,     "location": {         "address": "город Москва, Лесная, 7",         "metro_stations": ["Белорусская"]         }     }