Exemple #1
0
    def test_generated_files(self):
        due_date = datetime.datetime(2011, 10, 24)
        sale = self._create_sale(1666, due_date=due_date)
        sale.identifier = 1234
        for p in sale.payments:
            p.identifier = 4321
        generator = NFeGenerator(sale, self.store)

        # If we generate random cnf, the test will always fail
        _get_random_cnf = NFeIdentification._get_random_cnf
        NFeIdentification._get_random_cnf = lambda s: 10000001
        # Mimic today behavior
        _get_today_date = NFeGenerator._get_today_date
        NFeGenerator._get_today_date = lambda s: due_date

        generator.generate()
        NFeIdentification._get_random_cnf = _get_random_cnf
        NFeGenerator._get_today_date = _get_today_date

        basedir = get_tests_datadir('plugins')
        expected = os.path.join(basedir, "nfe-expected.txt")
        output = os.path.join(basedir, "nfe-output.txt")
        if not os.path.isfile(expected):
            with open(expected, 'wb') as fp:
                fp.write(strip_accents(generator._as_txt()))
            return
        with open(output, 'wb') as fp:
            fp.write(strip_accents(generator._as_txt()))

        # Diff and compare
        diff = diff_files(expected, output)
        os.unlink(output)

        self.failIf(diff, '%s\n%s' % ("Files differ, output:", diff))
Exemple #2
0
def compare_files(sfile, basename):
    expected = basename + '-expected.txt'
    output = basename + '-output.txt'

    sfile.write(output)
    expected = get_tests_datadir('plugins', expected)
    diff = diff_files(expected, output)
    os.unlink(output)
    return diff
Exemple #3
0
def compare_sintegra_file(sfile, basename):
    expected = basename + '-expected.txt'
    output = basename + '-output.txt'

    sfile.write(output)
    expected = get_tests_datadir(expected)
    diff = diff_files(expected, output)
    os.unlink(output)
    if diff:
        raise AssertionError('%s\n%s' % ("Files differ, output:", diff))
Exemple #4
0
def compare_sintegra_file(sfile, basename):
    expected = basename + '-expected.txt'
    output = basename + '-output.txt'

    sfile.write(output)
    expected = get_tests_datadir(expected)
    diff = diff_files(expected, output)
    os.unlink(output)
    if diff:
        raise AssertionError('%s\n%s' % ("Files differ, output:", diff))
Exemple #5
0
def compare_invoice_file(invoice, basename):
    expected = basename + '-expected.txt'
    output = basename + '-output.txt'

    fp = open(output, 'w')
    for n, page in enumerate(invoice.generate_pages()):
        fp.write('-- PAGE %d - START ----\n' % (n + 1, ))
        for line in page:
            fp.write(line.tostring())
        fp.write('-- PAGE %d - END ----\n' % (n + 1, ))
    fp.close()
    expected = get_tests_datadir(expected)
    diff = diff_files(expected, output)
    os.unlink(output)
    if diff:
        raise AssertionError('%s\n%s' % ("Files differ, output:", diff))
Exemple #6
0
def compare_invoice_file(invoice, basename):
    expected = basename + '-expected.txt'
    output = basename + '-output.txt'

    fp = open(output, 'w')
    for n, page in enumerate(invoice.generate_pages()):
        fp.write('-- PAGE %d - START ----\n' % (n + 1, ))
        for line in page:
            fp.write(line.tostring())
        fp.write('-- PAGE %d - END ----\n' % (n + 1, ))
    fp.close()
    expected = get_tests_datadir(expected)
    diff = diff_files(expected, output)
    os.unlink(output)
    if diff:
        raise AssertionError('%s\n%s' % ("Files differ, output:", diff))
Exemple #7
0
    def _test_generated_files(self, new_client=None):
        due_date = datetime.datetime(2011, 10, 24, 0, 0, 0, 0)
        sale = self._create_sale(1666, due_date=due_date)
        sale.identifier = 1234
        if new_client:
            sale.client = new_client
        for p in sale.payments:
            p.identifier = 4321
        generator = NFeGenerator(sale, self.store)

        # If we generate random cnf, the test will always fail
        _get_random_cnf = NFeIdentification._get_random_cnf
        NFeIdentification._get_random_cnf = lambda s: 10000001
        # Mimic now_datetime behavior
        _get_now_datetime = NFeGenerator._get_now_datetime
        NFeGenerator._get_now_datetime = lambda s: due_date

        generator.generate()
        NFeIdentification._get_random_cnf = _get_random_cnf
        NFeGenerator._get_now_datetime = _get_now_datetime

        basedir = get_tests_datadir('plugins')

        if new_client is None:
            expected = os.path.join(basedir, "nfe-expected.txt")
        elif isinstance(sale.get_client_role(), Individual):
            expected = os.path.join(basedir, "individual-nfe-expected.txt")
        else:
            expected = os.path.join(basedir, "company-nfe-expected.txt")

        output = os.path.join(basedir, "nfe-output.txt")
        if not os.path.isfile(expected):
            with open(expected, 'wb') as fp:
                fp.write(strip_accents(generator._as_txt()).encode())
            return
        with open(output, 'wb') as fp:
            fp.write(strip_accents(generator._as_txt()).encode())

        # Diff and compare
        diff = diff_files(expected, output)
        os.unlink(output)

        self.assertFalse(diff, '%s\n%s' % ("Files differ, output:", diff))
Exemple #8
0
    def _test_generated_files(self, new_client=None):
        due_date = datetime.datetime(2011, 10, 24, 0, 0, 0, 0)
        sale = self._create_sale(1666, due_date=due_date)
        sale.identifier = 1234
        if new_client:
            sale.client = new_client
        for p in sale.payments:
            p.identifier = 4321
        generator = NFeGenerator(sale, self.store)

        # If we generate random cnf, the test will always fail
        _get_random_cnf = NFeIdentification._get_random_cnf
        NFeIdentification._get_random_cnf = lambda s: 10000001
        # Mimic now_datetime behavior
        _get_now_datetime = NFeGenerator._get_now_datetime
        NFeGenerator._get_now_datetime = lambda s: due_date

        generator.generate()
        NFeIdentification._get_random_cnf = _get_random_cnf
        NFeGenerator._get_now_datetime = _get_now_datetime

        basedir = get_tests_datadir('plugins')

        if new_client is None:
            expected = os.path.join(basedir, "nfe-expected.txt")
        elif isinstance(sale.get_client_role(), Individual):
            expected = os.path.join(basedir, "individual-nfe-expected.txt")
        else:
            expected = os.path.join(basedir, "company-nfe-expected.txt")

        output = os.path.join(basedir, "nfe-output.txt")
        if not os.path.isfile(expected):
            with open(expected, 'wb') as fp:
                fp.write(strip_accents(generator._as_txt()))
            return
        with open(output, 'wb') as fp:
            fp.write(strip_accents(generator._as_txt()))

        # Diff and compare
        diff = diff_files(expected, output)
        os.unlink(output)

        self.failIf(diff, '%s\n%s' % ("Files differ, output:", diff))
Exemple #9
0
    def _diff_expected(self, report_class, expected_name, *args, **kwargs):
        basedir = get_tests_datadir('reporting')
        expected = os.path.join(basedir, '%s.html' % expected_name)
        output = os.path.join(basedir, '%s-tmp.html' % expected_name)

        def save_report(filename, *args, **kwargs):
            report = report_class(filename, *args, **kwargs)
            report.adjust_for_test()
            report.save_html(filename)

        if not os.path.isfile(expected):
            save_report(expected, *args, **kwargs)
            return

        save_report(output, *args, **kwargs)

        # Diff and compare
        diff = diff_files(expected, output)
        os.unlink(output)

        self.failIf(diff, '%s\n%s' % ("Files differ, output:", diff))
Exemple #10
0
            value = getattr(model, col.name, None)
            if isinstance(value, datetime.datetime):
                # Strip hours/minutes/seconds so today() works
                value = datetime.datetime(value.year,
                                          value.month,
                                          value.day)

            self.output += '  %s: %r\n' % (col.name, value)
        self.output += '\n'


# FIXME: To be able to create ui tests outside stoq, we need to be able
# to get tests data dir from there. Maybe we should use
# provide_utility/get_utility?
stoq_dir = get_tests_datadir('ui')


class GUITest(DomainTest):
    @classmethod
    def setUpClass(cls):
        pass

    @classmethod
    def tearDownClass(cls):
        pass

    def setUp(self):
        from stoqlib.database.runtime import new_store
        self.store = new_store()
        self.fake.set_store(self.store)
Exemple #11
0
 def _get_expected(self, filename, generated):
     fname = get_tests_datadir(filename + '.pdf.html')
     if not os.path.exists(fname):
         open(fname, 'w').write(open(generated).read())
     return fname
Exemple #12
0
 def _get_expected(self, filename, content):
     fname = get_tests_datadir(filename)
     if not os.path.exists(fname):
         open(fname, 'w').write(content)
     return fname
Exemple #13
0
                if value in ns:
                    self.output += '  %s: %s\n' % (col.name, ns[value])
                continue

            value = getattr(model, col.name, None)
            if isinstance(value, datetime.datetime):
                # Strip hours/minutes/seconds so today() works
                value = datetime.datetime(value.year,
                                          value.month,
                                          value.day)

            self.output += '  %s: %r\n' % (col.name, value)
        self.output += '\n'


stoq_dir = get_tests_datadir('ui')


class GUITest(DomainTest):
    def setUp(self):
        self._unhandled_exceptions = []
        self._old_hook = sys.excepthook
        sys.excepthook = self._except_hook
        test_system_notifier.reset()
        DomainTest.setUp(self)

    def tearDown(self):
        sys.excepthook = self._old_hook
        DomainTest.tearDown(self)

        messages = test_system_notifier.reset()
Exemple #14
0
 def _get_expected(self, filename, generated):
     fname = get_tests_datadir(filename + '.pdf.html')
     if not os.path.exists(fname):
         open(fname, 'w').write(open(generated).read())
     return fname
Exemple #15
0
 def _get_expected(self, filename, content):
     fname = get_tests_datadir(filename)
     if not os.path.exists(fname):
         open(fname, 'w').write(content)
     return fname