Exemplo n.º 1
0
class TestImportPosition(TestCase):
    def setUp(self):
        oc = OpenCSV(f=test_file)
        position, overall = oc.get_symbol_lines()

        self.ip = ImportPosition(date=test_date, position=position, overall=overall)

    def tearDown(self):
        del self.ip

    def test_save_position(self):
        self.ip.save_position()

        positions = Position.objects.all()
        print 'Total position in db: %d\n' % len(positions)
        print 'Display all positions...'
        for p in positions:
            print p

        self.assertEqual(len(positions), 19)

        print '\n' + '-' * 100 + '\n'

        instruments = InstrumentPos.objects.all()
        print 'Total instruments in db: %d\n' % len(instruments)
        print 'Display all instruments...'
        for i in instruments:
            print i

        self.assertEqual(len(instruments), 19)

        print '\n' + '-' * 100 + '\n'

        stocks = StockPos.objects.all()
        print 'Total stocks in db: %d\n' % len(stocks)
        print 'Display all stocks...'
        for s in stocks:
            print s

        self.assertEqual(len(stocks), 19)

        print '\n' + '-' * 100 + '\n'

        options = OptionPos.objects.all()
        print 'Total options in db: %d\n' % len(options)
        print 'Display all options...'
        for o in options:
            print o

    def test_save_overall(self):
        self.ip.save_overall()

        print 'option row count in db: %d\n' % len(OverallPos.objects.all())
        print 'Overall Data:'
        print OverallPos.objects.get(id=1)

        self.assertEqual(len(OverallPos.objects.all()), 1)
Exemplo n.º 2
0
    def setUp(self):
        for f, d in [(test_file, test_date), (test_file2, test_date2)]:
            oc = OpenCSV(f=f)
            position, overall = oc.get_symbol_lines()
            ip = ImportPosition(date=d, position=position, overall=overall)
            ip.save_overall()
            ip.save_position()

            del oc, ip

        #self.cv = ViewControl(date='2001-01-01')
        self.cv = ViewControl(date=test_date)
Exemplo n.º 3
0
def position_import_single(request, date=None):
    """
    import one day position files
    after import it move file into imported folder
    """
    # get date path
    path = ''
    for f in OpenDir().get_files():
        if f['Date'] == date:
            path = f['Path']
            break

    # after open date, then subtract one day
    date = datetime.strptime(date, '%Y-%m-%d') - timedelta(days=1)
    date = date.strftime('%Y-%m-%d')

    if path:
        position, overall = OpenCSV(f=path).get_symbol_lines()

        #instrument_count, option_count = 0, 0

        # save position and overall
        import_pos = ImportPosition(date=date, position=position, overall=overall)
        instrument_count, option_count = import_pos.save_position()
        import_pos.save_overall()

        # move save files into imported folder
        imported_folder = path.split('\\')
        imported_folder.insert(-1, 'imported')
        imported_folder = '\\'.join(imported_folder)
        rename(path, imported_folder)

        parameters = {'found': True, 'date': date, 'path': path.split('\\')[-1],
                      'instrument_count': instrument_count,
                      'option_count': option_count}

    else:
        # file not found
        parameters = {'found': False, 'date': date, 'path': path.split('\\')[-1],
                      'instrument_count': 0,
                      'option_count': 0}

    return render(request, 'pms/import/import_done.html', parameters)
Exemplo n.º 4
0
    def setUp(self):
        oc = OpenCSV(f=test_file)
        position, overall = oc.get_symbol_lines()

        self.ip = ImportPosition(date=test_date, position=position, overall=overall)