コード例 #1
0
 def setUp(self):
     self.path_to_template_file = 'invoicegenerator/generator/rml/rg.rml'
     self.lines = DEFAULT_CONFIG + [
         "rml_template='%s'" % self.path_to_template_file,
     ]
     ConfigStore.read_configuration(self.lines)
     self.billing_address = Address(name="", street="", zipcode="", city="")
     self.invoice = Invoice(invoice_date="19.08.2011",
                            billing_address=self.billing_address)
     self.generator = RMLGenerator(self.invoice)
コード例 #2
0
    def __init__(self, invoice):
        self.invoice = invoice
        self.invoice_datetime = ConfigStore.parse_date(
            self.invoice.invoice_date)
        self.config = ConfigStore.get_configuration(when=self.invoice_datetime)

        self.translation = Translations.load('locale',
                                             locales=[self.invoice.language],
                                             domain='pyinvoice')
        self.ugettext = self.translation.ugettext
        self.format = Format(locale=self.invoice.language)
コード例 #3
0
 def test_inherit_not_present(self):
     """Test that values which are not present in any configuration will
     cause a KeyError as normal."""
     config = ConfigStore.get_configuration()
     try:
         config["doesnotexist"]
         self.fail("Invalid key did not raise a KeyError")
     except KeyError, e:
         print e
コード例 #4
0
 def test_get_by_date(self):
     """Test that a configuration without valid_from is being considered 
     valid from 0 to the next configuration with this field."""
     data = [
         ("bar", 1),
         ("foo", 10),
     ]
     for data_string, day in data:
         some_date = date(year=1980, month=1, day=day)
         config = ConfigStore.get_configuration(when=some_date)
         self.assertEqual(data_string, config["data"])
コード例 #5
0
 def test_get_by_date(self):
     "Test that configurations can be retrieved by data"
     data = [
         ("foo", 1),
         ("foo", 2),
         ("foo", 5),
         ("bar", 7),
         ("doe", 20),
         ("doe", 28),
     ]
     for data_string, day in data:
         some_date = date(year=1980, month=1, day=day)
         config = ConfigStore.get_configuration(when=some_date)
         self.assertEqual(data_string, config["data"])
コード例 #6
0
 def tearDown(self):
     ConfigStore.reset()
コード例 #7
0
 def test_inherit(self):
     """Test that values are inherited from older configurations if the 
     requested field is not present in the current configuration."""
     config = ConfigStore.get_configuration()
     self.assertEqual("bar", config["data"])
     self.assertEqual("doe", config["data2"])
コード例 #8
0
 def setUp(self):
     self.lines = \
         ["[bar]", "valid_from='06.01.1980'", "data='bar'", "bardata='abc'",
          "[foo]", "valid_from='01.01.1980'", "data='foo'", "data2='doe'", ]
     ConfigStore.read_configuration(self.lines)
コード例 #9
0
 def setUp(self):
     self.lines = \
         ["[bar]", "data='bar'",
          "[foo]", "valid_from='10.01.1980'", "data='foo'", ]
     ConfigStore.read_configuration(self.lines)
コード例 #10
0
 def test_datesorting(self):
     "Test that the read sections are ordered by date."
     data = ["foo", "bar", "doe"]
     for i, config in enumerate(ConfigStore.get_configurations()):
         self.assertEqual(data[i], config["data"])
コード例 #11
0
 def test_getconfig(self):
     """Test that the newest configuration is returned if no date was 
     specified."""
     config = ConfigStore.get_configuration()
     self.assertEqual("doe", config["data"])
コード例 #12
0
        invoice_number = int(invoice_number)
        return "invoice%05d" % invoice_number
    except ValueError:
        return "invoice-%s" % str(invoice_number)


if __name__ == "__main__":
    parser = OptionParser()
    parser.add_option("--with-logo",
                      dest="with_logo",
                      action="store_true",
                      default=False,
                      help="embed logo in the PDF")
    (options, args) = parser.parse_args()

    if args == []:
        print_usage()
        sys.exit(0)

    user_basedir = "userdata"
    basedir = os.path.join(user_basedir, "output")
    basename = invoice_file_name(args[0])

    config_filename = os.path.join(user_basedir, "invoicing_data.conf")
    ConfigStore.read_configuration(config_filename)

    datafile = os.path.join(user_basedir, "invoice_data", basename + ".xml")
    invoice = InvoiceParser.parse(content=file(datafile).read())
    generator = RMLGenerator(invoice)
    generator.build(basedir, basename, options.with_logo)