Пример #1
0
def test_base_market_url_provided(monkeypatch, mocked_session):
    m = mock.Mock()
    m.return_value = mocked_session
    monkeypatch.setattr(Session, "get", m)
    offer = market.get_market_offers(Session(), [14])
    print(m.call_args.args)
    assert market.BASE_MARKET_URL in m.call_args.args[0]
Пример #2
0
def test_overrides_base_market_url(monkeypatch, mocked_session):
    override_url = "http://sample.com?"
    m = mock.Mock()
    m.return_value = mocked_session
    monkeypatch.setattr(Session, "get", m)
    offer = market.get_market_offers(Session(), [14], override_url)
    print(m.call_args.args)
    assert override_url in m.call_args.args[0]
Пример #3
0
def test_absolute_value_of_ints(monkeypatch, mocked_session):
    monkeypatch.setattr(Session, "get", lambda a, b: mocked_session)
    offer = market.get_market_offers(Session(), [-14, -15])
    for k in offer:
        print(k)
        for k, v in offer[k].__dict__.items():
            print("Key is ", k, " and value is ", v)
    # Since session is immutable from file, id given and found are different
    assert offer[14].id == 1462
    assert offer[15].id == 1462
Пример #4
0
def test_bad_url(monkeypatch, mocked_session):
    monkeypatch.setattr(Session, "get", lambda a, b: mocked_session)
    with raises(ValueError):
        market.get_market_offers(Session(), [], "http://sample.com")
Пример #5
0
def test_empty_ids_fails(monkeypatch, mocked_session):
    monkeypatch.setattr(Session, "get", lambda a, b: mocked_session)
    with raises(ValueError):
        market.get_market_offers(Session(), [])
Пример #6
0
def test_none_fails(monkeypatch, mocked_session):
    monkeypatch.setattr(Session, "get", lambda a, b: mocked_session)
    with raises(TypeError):
        market.get_market_offers(Session(), None)
Пример #7
0
def generate_email():
    """
    Run from command line via python -c "from urdailyemail import email; email.generate_email()"
    """
    with Session() as session:
        # Set up database and session initialization
        url = "https://ohbucketmybucket.s3-us-west-1.amazonaws.com/collection.sqlite"
        # file_path = Path(os.environ["USERPROFILE"] +
        #                  "\Desktop\database\collection.sqlite")
        file_path = os.environ["DB_FILE_PATH"]
        with get(url) as response, open(file_path, 'wb') as out_file:
            out_file.write(response.content)
        api.connect_and_initialize_database("sqlite", str(Path(file_path)))
        api.session_connect_to_ur(session, os.environ["UR_USER"],
                                  os.environ["UR_PASS"])

        # Get purchases from database to check against
        full_purchases = api.get_history_from_database()
        purchases = list(
            islice((purchase for purchase in full_purchases),
                   int(os.environ["PURCHASE_COUNT"])))

        # Get market offers for purchases
        offers = market.get_market_offers(
            session, [purchase.id for purchase in purchases])

        # Get black market flash mission
        try:
            missions = api.convert_missions(
                api.get_missions_list(session, "black market"))
            bm_missions = [
                mission for mission in missions
                if "BLACK MARKET" in mission.name
            ]
            bm_char_offers = {}
            for bm_mission in bm_missions:
                bm_mission_character = re.search('\\d(.+)(\\W)>',
                                                 bm_mission.name)
                if bm_mission_character:
                    bm_mission_character = str(
                        bm_mission_character.group(1)).strip()
                else:
                    logging.error("Failed to process %s", bm_mission.name)
                try:
                    bm_offers = market.get_market_offers(
                        session, [bm_mission_character])
                    bm_char_offers[
                        bm_mission.name] = bm_offers[bm_mission_character]
                except Exception as exception:
                    logging.error(
                        "Failed while generating black market offers: %s",
                        str(exception))
        except Exception as exception:
            logging.exception(f"62 - {exception}")
            bm_missions = [api.get_missions_list(session, "black market").text]
            bm_char_offers = None

        # Create table for email
        table_rows = create_table_rows(purchases, offers)
        mission_table = create_market_mission_table(bm_missions,
                                                    bm_char_offers)
        final_content = create_table(table_rows, mission_table)
        _send_email(final_content)
    return "OK"