Esempio n. 1
0
def test_get_isins_invested_by_should_use_today_if_no_value_present():
    component_under_test = Depotauszuege()

    component_under_test.add(time.today(), '1isin1234567', '1demokonto', 1)
    component_under_test.add(time.today() + timedelta(days=1), '2isin1234567', '2demokonto', 2)

    assert component_under_test.get_isins_invested_by() == ['1isin1234567']
Esempio n. 2
0
def test_get_isins_invested_by_should_filter_invalid_isins():
    component_under_test = Depotauszuege()

    component_under_test.add(time.today(), 'too_long_12342342345', '2demokonto', 222)
    component_under_test.add(time.today(), 'isin_1234567', '1demokonto', 111)
    component_under_test.add(time.today(), 'too_short', '2demokonto', 333)

    assert component_under_test.get_isins_invested_by() == ['isin_1234567']
Esempio n. 3
0
def test_get_isins_invested_by_should_order_by_invested_value():
    component_under_test = Depotauszuege()

    component_under_test.add(time.today(), 'mid_12345678', '2demokonto', 222)
    component_under_test.add(time.today(), 'small_123456', '1demokonto', 111)
    component_under_test.add(time.today(), 'large_123456', '2demokonto', 333)

    assert component_under_test.get_isins_invested_by() == ['large_123456', 'mid_12345678', 'small_123456']
Esempio n. 4
0
def test_get_isins_invested_by_should_filter_out_not_invested_etfs_to_that_time():
    component_under_test = Depotauszuege()

    component_under_test.add(time.today(), '1isin1234567', '1demokonto', 1)
    component_under_test.add(time.today() - timedelta(days=1), '2isin1234567', '2demokonto', 2)
    component_under_test.add(time.today(), '2isin1234567', '2demokonto', 0)

    assert component_under_test.get_isins_invested_by() == ['1isin1234567']
Esempio n. 5
0
def _monatsliste():
    month_map = {
        1: 'Januar',
        2: 'Februar',
        3: 'März',
        4: 'April',
        5: 'Mai',
        6: 'Juni',
        7: 'Juli',
        8: 'August',
        9: 'September',
        10: 'Oktober',
        11: 'November',
        12: 'Dezember'
    }
    aktueller_monat = today().month

    result_list = []

    for monat in range(0, 7):
        monat = 6 - monat

        berechneter_monat = aktueller_monat - monat
        if berechneter_monat < 1:
            berechneter_monat = berechneter_monat + 12
        result_list.append(month_map[berechneter_monat])

    return result_list
Esempio n. 6
0
def _update_data(isin, context):
    try:
        data = etf_data.get_data_for(isin)
        date = datum_to_german(time.today())
        persisted_state.shares_data().save(isin, date, etf_data.SOURCE, data)
        return base_html.set_success_message(context, language.SHARES_DATA_UPDATED.format(isin=isin))
    except:
        traceback.print_exc()
        return base_html.set_error_message(
            context,
            language.SHARES_DATA_NOT_UPDATED.format(isin=isin))
Esempio n. 7
0
def _handle_request(_):
    einzelbuchungen = persisted_state.database_instance().einzelbuchungen
    selector = einzelbuchungen.select()

    context = {
        'zusammenfassung_monatsliste':
        str(_monatsliste()),
        'zusammenfassung_einnahmenliste':
        str(selector.select_einnahmen().inject_zeros_for_last_6_months().
            select_letzte_6_montate().sum_monthly()),
        'zusammenfassung_ausgabenliste':
        str(selector.select_ausgaben().inject_zeros_for_last_6_months().
            select_letzte_6_montate().sum_monthly()),
        'ausgaben_des_aktuellen_monats':
        to_descriptive_list(
            selector.select_year(today().year).select_month(
                today().month).to_list())
    }
    context = {**context, **viewcore.generate_base_context('dashboard')}
    return context
Esempio n. 8
0
def test_refresh_data():
    requester.INSTANCE = RequesterStub(
        {'https://api.etf-data.com/product/DE000A14ND46': DEMO_DATA})

    result = index(PostRequestAction('update_data', {'isin': 'DE000A14ND46'}))
    assert result['message']
    assert result['message_type'] == 'success'
    assert result['message_content'] == language.SHARES_DATA_UPDATED.format(
        isin='DE000A14ND46')
    assert persisted_state.shares_data().get_last_changed_date_for(
        'DE000A14ND46') == datum_to_german(today())
Esempio n. 9
0
 def get_isins_invested_by(self, date=None):
     if not date:
         date = today()
     values = self.content[['Datum', 'Depotwert', 'Wert']].copy()
     values.Depotwert = values.Depotwert.astype(str)
     values = values[values.Depotwert.str.len() == 12]
     values = values[values.Datum <= date]
     values = values.sort_values(by='Datum', ascending=True)
     values = values.groupby('Depotwert').last()
     values = values[values.Wert > 0]
     values = values.sort_values('Wert', ascending=False)
     return values.index.to_list()
def test_content():
    set_up()

    depotwerte = persisted_state.database_instance().depotwerte
    depotwerte.add(name='large_etf', isin='1isin6789012', typ=depotwerte.TYP_ETF)
    depotwerte.add(name='small_etf', isin='2isin6789012', typ=depotwerte.TYP_ETF)

    persisted_state.database_instance().depotauszuege.add(depotwert='1isin6789012', datum=today(), konto='', wert=900)
    persisted_state.database_instance().depotauszuege.add(depotwert='2isin6789012', datum=today(), konto='', wert=100)

    persisted_state.shares_data().save(
        isin='1isin6789012',
        source='',
        date=datum_to_string(today()),
        data={
            SharesInfo.REGIONEN: {
                'DEU': 0.40,
                'USA': 0.60
            },
            SharesInfo.SEKTOREN: {
                sectors.BASISKONSUMGUETER: 50,
                sectors.ENERGIE: 50
            },
            SharesInfo.KOSTEN: 0.20
        }
    )
    persisted_state.shares_data().save(
        isin='2isin6789012',
        source='',
        date=datum_to_string(today()),
        data={
            SharesInfo.REGIONEN: {
                'NOR': 0.10,
                'DEU': 0.90
            },
            SharesInfo.SEKTOREN: {
                sectors.BASISKONSUMGUETER: 50,
                sectors.IMMOBILIEN: 50
            },
            SharesInfo.KOSTEN: 1.5,
        }
    )

    result = index(GetRequest())

    assert result['regions'] == {
                                    'header': ['Gesamt',
                                               'large_etf (1isin6789012)',
                                               'small_etf (2isin6789012)'],
                                    'data': [
                                        ['United States',
                                         {'euro': 5.4,
                                          'euro_str': '5.40',
                                          'percent': 0.54,
                                          'percent_str': '0.54'},
                                         {'euro': 5.4,
                                          'euro_str': '5.40',
                                          'percent': 0.6,
                                          'percent_str': '0.60'},
                                         {'euro': 0,
                                          'euro_str': '0,00',
                                          'percent': 0,
                                          'percent_str': '0,00'}],
                                        ['Germany',
                                         {'euro': 4.5,
                                          'euro_str': '4.50',
                                          'percent': 0.45,
                                          'percent_str': '0.45'},
                                         {'euro': 3.6,
                                          'euro_str': '3.60',
                                          'percent': 0.4,
                                          'percent_str': '0.40'},
                                         {'euro': 0.9,
                                          'euro_str': '0.90',
                                          'percent': 0.9,
                                          'percent_str': '0.90'}],
                                        ['Norway',
                                         {'euro': 0.1,
                                          'euro_str': '0.10',
                                          'percent': 0.01,
                                          'percent_str': '0.01'},
                                         {'euro': 0,
                                          'euro_str': '0,00',
                                          'percent': 0,
                                          'percent_str': '0,00'},
                                         {'euro': 0.1,
                                          'euro_str': '0.10',
                                          'percent': 0.1,
                                          'percent_str': '0.10'}]],
                                   }

    assert result['sectors'] == {
        'data': [[
            'Basiskonsumgüter',
            {'euro': 500.0,
             'euro_str': '500.00',
             'percent': 50.0,
             'percent_str': '50.00'},
            {'euro': 450.0,
             'euro_str': '450.00',
             'percent': 50,
             'percent_str': '50.00'},
            {'euro': 50.0,
             'euro_str': '50.00',
             'percent': 50,
             'percent_str': '50.00'}],
            ['Energie',
             {'euro': 450.0,
              'euro_str': '450.00',
              'percent': 45.0,
              'percent_str': '45.00'},
             {'euro': 450.0,
              'euro_str': '450.00',
              'percent': 50,
              'percent_str': '50.00'},
             {'euro': 0,
              'euro_str': '0,00',
              'percent': 0,
              'percent_str': '0,00'}],
           ['Immobilien',
            {'euro': 50.0,
             'euro_str': '50.00',
             'percent': 5.0,
             'percent_str': '5.00'},
            {'euro': 0,
             'euro_str': '0,00',
             'percent': 0,
             'percent_str': '0,00'},
            {'euro': 50.0,
             'euro_str': '50.00',
             'percent': 50,
             'percent_str': '50.00'}]],
        'header': ['Gesamt', 'large_etf (1isin6789012)', 'small_etf (2isin6789012)']}
    assert result['costs'] == {
        'data': [{'costs_eur': '1.80',
                  'costs_percent': '0.20',
                  'name': 'large_etf (1isin6789012)'},
                 {'costs_eur': '1.50',
                  'costs_percent': '1.50',
                  'name': 'small_etf (2isin6789012)'}],
        'gesamt': {'costs_eur': '3.30',
                   'costs_percent': '0.33',
                   'name': 'Gesamt'},
    }
Esempio n. 11
0
 def test_today_with_subbed_today_should_return_stubbed_date(self):
     time.stub_today_with(datum('01.01.2012'))
     assert time.today() == datum('01.01.2012')
     time.reset_viewcore_stubs()
Esempio n. 12
0
 def test_today_with_resetted_stub_should_return_today(self):
     time.stub_today_with(datum('01.01.2012'))
     time.reset_viewcore_stubs()
     assert time.today() == datetime.now().date()
     assert time.now().date() == datetime.now().date()