Beispiel #1
0
    def validate_file_field_correct_upload(self, fname):
        print 'test with correct file upload'
        self.pms_form = PmsImportStatementsForm({},
                                                {fname: getattr(self, fname)})
        print '%s file: %s' % (fname, getattr(self, fname))
        print 'run is_valid()...'

        self.assertFalse(fname in self.pms_form.errors.keys())
        print 'without any %s error...\n' % fname

        print '-' * 80 + '\n'
Beispiel #2
0
    def validate_file_field_empty_upload(self, fname):
        print 'test with empty file upload'
        self.pms_form = PmsImportStatementsForm({}, {})
        print 'without setup %s file' % fname
        print 'run is_valid()...'
        self.pms_form.is_valid()

        self.assertTrue(self.pms_form.errors[fname])
        print '%s error: %s\n' % (fname, self.pms_form.errors[fname].as_text())

        print '-' * 80 + '\n'
Beispiel #3
0
    def test_clean_for_same_date(self):
        """
        Test clean method when form is validate for
        make sure file date and all statement filename is same
        which is less than 1 biz day of file date
        """
        wrong_date = '2014-07-20'
        print 'using wrong file date: %s' % wrong_date
        print self.file_data

        self.pms_form = PmsImportStatementsForm({
            'date': wrong_date
        }, self.file_data)

        print 'run is_valid()...\n'
        result = self.pms_form.is_valid()

        print 'result: %s' % result
        self.assertFalse(result)

        errors = self.pms_form.errors.as_text()
        self.assertIn('All date must have (-1 BDay', errors)

        print 'errors text:'
        print errors
Beispiel #4
0
    def test_is_valid(self):
        """
        Test import form is valid working fine
        """
        self.pms_form = PmsImportStatementsForm(self.value_data,
                                                self.file_data)

        print 'file_date: %s' % self.date
        print 'account statement file: %s' % self.account_statement
        print 'position statement file: %s' % self.position_statement
        print 'trade activity file: %s\n' % self.trade_activity

        print 'running form is_valid...'
        result = self.pms_form.is_valid()
        print 'is_valid result: %s' % result
        print self.pms_form.errors
Beispiel #5
0
    def validate_file_field_correct_upload(self, fname):
        print 'test with correct file upload'
        self.pms_form = PmsImportStatementsForm({}, {fname: getattr(self, fname)})
        print '%s file: %s' % (fname, getattr(self, fname))
        print 'run is_valid()...'

        self.assertFalse(fname in self.pms_form.errors.keys())
        print 'without any %s error...\n' % fname

        print '-' * 80 + '\n'
Beispiel #6
0
    def validate_file_field_empty_upload(self, fname):
        print 'test with empty file upload'
        self.pms_form = PmsImportStatementsForm({}, {})
        print 'without setup %s file' % fname
        print 'run is_valid()...'
        self.pms_form.is_valid()

        self.assertTrue(self.pms_form.errors[fname])
        print '%s error: %s\n' % (fname, self.pms_form.errors[fname].as_text())

        print '-' * 80 + '\n'
Beispiel #7
0
    def validate_file_field_with_invalid_filename(self, fname, head_text,
                                                  wrong_fname, error_message):
        """
        Test method for different type of filename
        :param fname: str
        :param head_text: str
        :param wrong_fname: str
        """
        print head_text
        self.pms_form = PmsImportStatementsForm(
            {}, {fname: SimpleUploadedFile(wrong_fname, 'something')})
        print 'without setup %s file' % wrong_fname
        print 'run is_valid()...'
        self.pms_form.is_valid()

        self.assertTrue(self.pms_form.errors[fname])
        print '%s error: %s\n' % (fname, self.pms_form.errors[fname].as_text())

        self.assertIn(error_message, self.pms_form.errors[fname].as_text())

        print '-' * 80 + '\n'
Beispiel #8
0
    def test_is_valid(self):
        """
        Test import form is valid working fine
        """
        self.pms_form = PmsImportStatementsForm(self.value_data, self.file_data)

        print 'file_date: %s' % self.date
        print 'account statement file: %s' % self.account_statement
        print 'position statement file: %s' % self.position_statement
        print 'trade activity file: %s\n' % self.trade_activity

        print 'running form is_valid...'
        result = self.pms_form.is_valid()
        print 'is_valid result: %s' % result
        print self.pms_form.errors
Beispiel #9
0
    def test_clean_for_same_date(self):
        """
        Test clean method when form is validate for
        make sure file date and all statement filename is same
        which is less than 1 biz day of file date
        """
        wrong_date = '2014-07-20'
        print 'using wrong file date: %s' % wrong_date
        print self.file_data

        self.pms_form = PmsImportStatementsForm({'date': wrong_date},
                                                self.file_data)

        print 'run is_valid()...\n'
        result = self.pms_form.is_valid()

        print 'result: %s' % result
        self.assertFalse(result)

        errors = self.pms_form.errors.as_text()
        self.assertIn('All date must have (-1 BDay', errors)

        print 'errors text:'
        print errors
Beispiel #10
0
    def validate_file_field_with_invalid_filename(self, fname, head_text,
                                                  wrong_fname, error_message):
        """
        Test method for different type of filename
        :param fname: str
        :param head_text: str
        :param wrong_fname: str
        """
        print head_text
        self.pms_form = PmsImportStatementsForm(
            {}, {fname: SimpleUploadedFile(wrong_fname, 'something')})
        print 'without setup %s file' % wrong_fname
        print 'run is_valid()...'
        self.pms_form.is_valid()

        self.assertTrue(self.pms_form.errors[fname])
        print '%s error: %s\n' % (fname, self.pms_form.errors[fname].as_text())

        self.assertIn(error_message, self.pms_form.errors[fname].as_text())

        print '-' * 80 + '\n'
Beispiel #11
0
class TestPmsImportStatementsForm(TestSetUpDB):
    # noinspection PyUnresolvedReferences
    def setUp(self):
        TestSetUpDB.setUp(self)

        self.date = '2014-11-14'
        self.account_statement = SimpleUploadedFile(
            '2014-11-15-AccountStatement.csv',
            open(
                os.path.join(test_path, '2014-11-15',
                             '2014-11-15-AccountStatement.csv')).read())
        self.position_statement = SimpleUploadedFile(
            '2014-11-15-PositionStatement.csv',
            open(
                os.path.join(test_path, '2014-11-15',
                             '2014-11-15-PositionStatement.csv')).read())
        self.trade_activity = SimpleUploadedFile(
            '2014-11-15-TradeActivity.csv',
            open(
                os.path.join(test_path, '2014-11-15',
                             '2014-11-15-PositionStatement.csv')).read())

        self.value_data = dict(date=self.date)

        self.file_data = dict(
            account_statement=self.account_statement,
            position_statement=self.position_statement,
            trade_activity=self.trade_activity)

    def test_is_valid(self):
        """
        Test import form is valid working fine
        """
        self.pms_form = PmsImportStatementsForm(self.value_data,
                                                self.file_data)

        print 'file_date: %s' % self.date
        print 'account statement file: %s' % self.account_statement
        print 'position statement file: %s' % self.position_statement
        print 'trade activity file: %s\n' % self.trade_activity

        print 'running form is_valid...'
        result = self.pms_form.is_valid()
        print 'is_valid result: %s' % result
        print self.pms_form.errors

    def test_clean_for_same_date(self):
        """
        Test clean method when form is validate for
        make sure file date and all statement filename is same
        which is less than 1 biz day of file date
        """
        wrong_date = '2014-07-20'
        print 'using wrong file date: %s' % wrong_date
        print self.file_data

        self.pms_form = PmsImportStatementsForm({
            'date': wrong_date
        }, self.file_data)

        print 'run is_valid()...\n'
        result = self.pms_form.is_valid()

        print 'result: %s' % result
        self.assertFalse(result)

        errors = self.pms_form.errors.as_text()
        self.assertIn('All date must have (-1 BDay', errors)

        print 'errors text:'
        print errors

    def validate_file_field_empty_upload(self, fname):
        print 'test with empty file upload'
        self.pms_form = PmsImportStatementsForm({}, {})
        print 'without setup %s file' % fname
        print 'run is_valid()...'
        self.pms_form.is_valid()

        self.assertTrue(self.pms_form.errors[fname])
        print '%s error: %s\n' % (fname, self.pms_form.errors[fname].as_text())

        print '-' * 80 + '\n'

    def validate_file_field_correct_upload(self, fname):
        print 'test with correct file upload'
        self.pms_form = PmsImportStatementsForm({},
                                                {fname: getattr(self, fname)})
        print '%s file: %s' % (fname, getattr(self, fname))
        print 'run is_valid()...'

        self.assertFalse(fname in self.pms_form.errors.keys())
        print 'without any %s error...\n' % fname

        print '-' * 80 + '\n'

    def validate_file_field_with_invalid_filename(self, fname, head_text,
                                                  wrong_fname, error_message):
        """
        Test method for different type of filename
        :param fname: str
        :param head_text: str
        :param wrong_fname: str
        """
        print head_text
        self.pms_form = PmsImportStatementsForm(
            {}, {fname: SimpleUploadedFile(wrong_fname, 'something')})
        print 'without setup %s file' % wrong_fname
        print 'run is_valid()...'
        self.pms_form.is_valid()

        self.assertTrue(self.pms_form.errors[fname])
        print '%s error: %s\n' % (fname, self.pms_form.errors[fname].as_text())

        self.assertIn(error_message, self.pms_form.errors[fname].as_text())

        print '-' * 80 + '\n'

    def validate_file_field_wrong_filename(self, fname):
        """
        Test file field with wrong filename
        :param fname: str filename
        """
        wrong_fname = getattr(self, fname).name.replace(
            ''.join(map(lambda x: x.capitalize(), fname.split('_'))),
            'wrong-filename')

        self.validate_file_field_with_invalid_filename(
            fname, 'test with wrong filename', wrong_fname,
            'Incorrect filename')

    def validate_file_field_wrong_file_date(self, fname):
        """
        Test file field with wrong file date
        :param fname: str filename
        """
        wrong_fname = getattr(self, fname).name.replace(
            '2014-11-15', '11-15-2014')

        self.validate_file_field_with_invalid_filename(
            fname, 'test with wrong file date...', wrong_fname,
            'Incorrect file date')

    def validate_file_field_wrong_file_ext(self, fname):
        """
        Test file field with wrong file extension
        :param fname: str filename
        """
        wrong_fname = getattr(self, fname).name.replace('csv', 'html')

        self.validate_file_field_with_invalid_filename(
            fname, 'test with wrong file ext...', wrong_fname,
            'Incorrect file extension')

    def test_validate_account_statement(self):
        """
        Test validate account statement file upload field is working
        """
        self.validate_file_field_empty_upload('account_statement')
        self.validate_file_field_correct_upload('account_statement')
        self.validate_file_field_wrong_filename('account_statement')
        self.validate_file_field_wrong_file_date('account_statement')
        self.validate_file_field_wrong_file_ext('account_statement')

    def test_validate_position_statement(self):
        """
        Test validate position statement file upload field is working
        """
        self.validate_file_field_empty_upload('position_statement')
        self.validate_file_field_correct_upload('position_statement')
        self.validate_file_field_wrong_filename('position_statement')
        self.validate_file_field_wrong_file_date('position_statement')
        self.validate_file_field_wrong_file_ext('position_statement')

    def test_validate_trade_activity(self):
        """
        Test validate trade activity file upload field is working
        """
        self.validate_file_field_empty_upload('trade_activity')
        self.validate_file_field_correct_upload('trade_activity')
        self.validate_file_field_wrong_filename('trade_activity')
        self.validate_file_field_wrong_file_date('trade_activity')
        self.validate_file_field_wrong_file_ext('trade_activity')
Beispiel #12
0
class TestPmsImportStatementsForm(TestSetUpDB):
    # noinspection PyUnresolvedReferences
    def setUp(self):
        TestSetUpDB.setUp(self)

        self.date = '2014-11-14'
        self.account_statement = SimpleUploadedFile(
            '2014-11-15-AccountStatement.csv',
            open(
                os.path.join(test_path, '2014-11-15',
                             '2014-11-15-AccountStatement.csv')).read())
        self.position_statement = SimpleUploadedFile(
            '2014-11-15-PositionStatement.csv',
            open(
                os.path.join(test_path, '2014-11-15',
                             '2014-11-15-PositionStatement.csv')).read())
        self.trade_activity = SimpleUploadedFile(
            '2014-11-15-TradeActivity.csv',
            open(
                os.path.join(test_path, '2014-11-15',
                             '2014-11-15-PositionStatement.csv')).read())

        self.value_data = dict(date=self.date)

        self.file_data = dict(account_statement=self.account_statement,
                              position_statement=self.position_statement,
                              trade_activity=self.trade_activity)

    def test_is_valid(self):
        """
        Test import form is valid working fine
        """
        self.pms_form = PmsImportStatementsForm(self.value_data,
                                                self.file_data)

        print 'file_date: %s' % self.date
        print 'account statement file: %s' % self.account_statement
        print 'position statement file: %s' % self.position_statement
        print 'trade activity file: %s\n' % self.trade_activity

        print 'running form is_valid...'
        result = self.pms_form.is_valid()
        print 'is_valid result: %s' % result
        print self.pms_form.errors

    def test_clean_for_same_date(self):
        """
        Test clean method when form is validate for
        make sure file date and all statement filename is same
        which is less than 1 biz day of file date
        """
        wrong_date = '2014-07-20'
        print 'using wrong file date: %s' % wrong_date
        print self.file_data

        self.pms_form = PmsImportStatementsForm({'date': wrong_date},
                                                self.file_data)

        print 'run is_valid()...\n'
        result = self.pms_form.is_valid()

        print 'result: %s' % result
        self.assertFalse(result)

        errors = self.pms_form.errors.as_text()
        self.assertIn('All date must have (-1 BDay', errors)

        print 'errors text:'
        print errors

    def validate_file_field_empty_upload(self, fname):
        print 'test with empty file upload'
        self.pms_form = PmsImportStatementsForm({}, {})
        print 'without setup %s file' % fname
        print 'run is_valid()...'
        self.pms_form.is_valid()

        self.assertTrue(self.pms_form.errors[fname])
        print '%s error: %s\n' % (fname, self.pms_form.errors[fname].as_text())

        print '-' * 80 + '\n'

    def validate_file_field_correct_upload(self, fname):
        print 'test with correct file upload'
        self.pms_form = PmsImportStatementsForm({},
                                                {fname: getattr(self, fname)})
        print '%s file: %s' % (fname, getattr(self, fname))
        print 'run is_valid()...'

        self.assertFalse(fname in self.pms_form.errors.keys())
        print 'without any %s error...\n' % fname

        print '-' * 80 + '\n'

    def validate_file_field_with_invalid_filename(self, fname, head_text,
                                                  wrong_fname, error_message):
        """
        Test method for different type of filename
        :param fname: str
        :param head_text: str
        :param wrong_fname: str
        """
        print head_text
        self.pms_form = PmsImportStatementsForm(
            {}, {fname: SimpleUploadedFile(wrong_fname, 'something')})
        print 'without setup %s file' % wrong_fname
        print 'run is_valid()...'
        self.pms_form.is_valid()

        self.assertTrue(self.pms_form.errors[fname])
        print '%s error: %s\n' % (fname, self.pms_form.errors[fname].as_text())

        self.assertIn(error_message, self.pms_form.errors[fname].as_text())

        print '-' * 80 + '\n'

    def validate_file_field_wrong_filename(self, fname):
        """
        Test file field with wrong filename
        :param fname: str filename
        """
        wrong_fname = getattr(self, fname).name.replace(
            ''.join(map(lambda x: x.capitalize(), fname.split('_'))),
            'wrong-filename')

        self.validate_file_field_with_invalid_filename(
            fname, 'test with wrong filename', wrong_fname,
            'Incorrect filename')

    def validate_file_field_wrong_file_date(self, fname):
        """
        Test file field with wrong file date
        :param fname: str filename
        """
        wrong_fname = getattr(self,
                              fname).name.replace('2014-11-15', '11-15-2014')

        self.validate_file_field_with_invalid_filename(
            fname, 'test with wrong file date...', wrong_fname,
            'Incorrect file date')

    def validate_file_field_wrong_file_ext(self, fname):
        """
        Test file field with wrong file extension
        :param fname: str filename
        """
        wrong_fname = getattr(self, fname).name.replace('csv', 'html')

        self.validate_file_field_with_invalid_filename(
            fname, 'test with wrong file ext...', wrong_fname,
            'Incorrect file extension')

    def test_validate_account_statement(self):
        """
        Test validate account statement file upload field is working
        """
        self.validate_file_field_empty_upload('account_statement')
        self.validate_file_field_correct_upload('account_statement')
        self.validate_file_field_wrong_filename('account_statement')
        self.validate_file_field_wrong_file_date('account_statement')
        self.validate_file_field_wrong_file_ext('account_statement')

    def test_validate_position_statement(self):
        """
        Test validate position statement file upload field is working
        """
        self.validate_file_field_empty_upload('position_statement')
        self.validate_file_field_correct_upload('position_statement')
        self.validate_file_field_wrong_filename('position_statement')
        self.validate_file_field_wrong_file_date('position_statement')
        self.validate_file_field_wrong_file_ext('position_statement')

    def test_validate_trade_activity(self):
        """
        Test validate trade activity file upload field is working
        """
        self.validate_file_field_empty_upload('trade_activity')
        self.validate_file_field_correct_upload('trade_activity')
        self.validate_file_field_wrong_filename('trade_activity')
        self.validate_file_field_wrong_file_date('trade_activity')
        self.validate_file_field_wrong_file_ext('trade_activity')