Best Python code snippet using localstack_python
render_test.py
Source:render_test.py
...8class RenderTest(PDFTestCase):9 def setUp(self):10 super(RenderTest, self).setUp()11 self.currency = self.usd12 def render_report(self, show_buyers=True):13 test_buffer = StringIO()14 pdf_report = PDFReport(self.report, self.currency, show_buyers=show_buyers)15 pdf_report.render(test_buffer)16 tmp_file = open('/tmp/report.pdf', 'w')17 tmp_file.write(test_buffer.getvalue())18 tmp_file.close()19 def test_partial_render_no_production(self):20 self.add_grades()21 self.add_sales()22 self.add_expenses()23 self.render_report()24 def test_partial_render_no_sales(self):25 self.add_grades()26 self.add_expenses()27 self.render_report()28 def test_partial_render_no_expense_entries(self):29 self.add_grades()30 self.add_expenses()31 self.report.expenses.all().delete()32 self.render_report()33 def test_full_render(self):34 self.add_grades()35 self.add_productions()36 self.add_sales()37 self.add_expenses()38 self.add_cash_uses()39 self.add_cash_sources()40 self.add_farmer_payments()41 self.report.working_capital = Decimal("11407500")42 self.report.working_capital_repaid = Decimal("128700")43 self.report.miscellaneous_sources = Decimal("0")44 self.report.save()45 self.render_report()46 def test_full_render_no_members(self):47 self.add_grades()48 self.add_productions()49 self.add_sales()50 self.add_expenses()51 self.add_cash_uses()52 self.add_cash_sources()53 self.add_farmer_payments()54 self.rwanda_2010.has_members = False55 self.rwanda_2010.save()56 self.report.working_capital = Decimal("11407500")57 self.report.working_capital_repaid = Decimal("128700")58 self.report.miscellaneous_sources = Decimal("0")59 self.report.save()60 self.render_report()61 def test_full_render_rwf(self):62 self.add_grades()63 self.add_productions()64 self.add_sales()65 self.add_expenses()66 self.add_cash_uses()67 self.add_cash_sources()68 self.add_farmer_payments()69 self.report.working_capital = Decimal("11407500")70 self.report.working_capital_repaid = Decimal("128700")71 self.report.miscellaneous_sources = Decimal("0")72 self.report.save()73 self.currency = self.rwf74 self.render_report()75 def test_gauge_render(self):76 self.add_grades()77 self.add_productions()78 self.add_sales()79 self.add_expenses()80 self.add_cash_uses()81 self.add_cash_sources()82 self.add_farmer_payments()83 self.report.working_capital = Decimal("11407500")84 self.report.working_capital_repaid = Decimal("128700")85 self.report.miscellaneous_sources = Decimal("0")86 self.report.save()87 test_buffer = StringIO()88 pdf_report = PDFReport(self.report, self.currency)89 # create the canvas90 c = pdf_report.create_canvas(test_buffer)91 # test wrap_word92 # with text containing space93 label = "Hello, world"94 pdf_report.wrap_word(c, 0, 0, 100, "left", label)95 # with text without spacing96 label = "blablafoobarbarfoobarfoooooooofoobar"97 pdf_report.wrap_word(c, 0, 0, 100, "left", label)98 # with long text but short length thus 99 label = "bla blasdlskdfjlaskdjf"100 pdf_report.wrap_word(c, 0, 0, 20, "right", label)101 # with text as none102 label = None103 pdf_report.wrap_word(c, 0, 0, 100, "left", label)104 # test gauge rotation method105 # with minimum less than maximum106 pdf_report.gauge_rotation(0,100,86)107 # with minimun greater than maximum108 pdf_report.gauge_rotation(100,0,86)109 # with current value out of min max range110 pdf_report.gauge_rotation(10,100,6)111 pdf_report.gauge_rotation(10,100,110)112 # with equal min max113 pdf_report.gauge_rotation(0,0,0)114 # test draw gauge115 # with one null value between minimum, maximum and current value116 pdf_report.draw_gauge(c,0,0,100,None,0,0,"Hello",9,7)117 # using one country object, will change the name118 # for Rwanda119 pdf_report.lat_to_x(self.rwanda, 1.25458)120 pdf_report.lng_to_y(self.rwanda, 30.25458)121 pdf_report.draw_country_map(c, 0,0,100,self.rwanda, 1.25458, 30.25458)122 pdf_report.report.season.country = self.rwanda123 pdf_report.draw_wetmill_location(c, 0,0)124 # for Kenya125 self.rwanda.name = "Kenya"126 pdf_report.lat_to_x(self.rwanda, 1.25458)127 pdf_report.lng_to_y(self.rwanda, 30.25458)128 pdf_report.draw_country_map(c, 0,0,100,self.rwanda, 1.25458, 30.25458)129 pdf_report.report.season.country = self.rwanda130 pdf_report.draw_wetmill_location(c, 0,0)131 # for Ethiopia132 self.rwanda.name = "Ethiopia"133 pdf_report.lat_to_x(self.rwanda, 1.25458)134 pdf_report.lng_to_y(self.rwanda, 30.25458)135 pdf_report.draw_country_map(c, 0,0,100,self.rwanda, 1.25458, 30.25458)136 pdf_report.report.season.country = self.rwanda137 pdf_report.draw_wetmill_location(c, 0,0)138 # for Tanzania139 self.rwanda.name = "Tanzania"140 pdf_report.lat_to_x(self.rwanda, 1.25458)141 pdf_report.lng_to_y(self.rwanda, 30.25458)142 pdf_report.draw_country_map(c, 0, 0, 100,self.rwanda, 1.25458, 30.25458)143 pdf_report.report.season.country = self.rwanda144 pdf_report.draw_wetmill_location(c, 0, 0)145 # test nice number method146 pdf_report.nice_number(-1, True)147 pdf_report.nice_number(-1, False)148 pdf_report.nice_number(.9, True)149 pdf_report.nice_number(.9, False)150 pdf_report.nice_number(.01, False)151 # test draw y axis152 pdf_report.draw_yaxis(c, 0,0,100,30,0,0,10,True,None)153 # test draw bar chart value method154 pdf_report.draw_bar_value(c, 100, 20, 12, Decimal(25))155 # test draw bar graph method with min, max and value as null156 pdf_report.draw_bar_graph(c, 0, 0, None, None, None, "Something")157 # test draw stacked bar graph with most of values as null158 legend_titles = ["One", "Two", "Three", "Four"]159 wetmill_values = [None, None, None, None]160 tns_values = [None, None, None, None]161 pdf_report.draw_stacked_bar_graph(c, 0, 0, None, wetmill_values, tns_values, "Some title", legend_titles)162 # test draw stacked bar graph with normal values163 wetmill_values = [Decimal(".5"), Decimal(".32"), Decimal(".12"), Decimal(".58")]164 tns_values = [Decimal(".1"), Decimal(".56"), Decimal(".5"), Decimal(".9")]165 pdf_report.draw_stacked_bar_graph(c, 0, 0, 1.5, wetmill_values, tns_values, "Some other title", legend_titles, percentage=True)166 def test_full_render_with_aggregates(self):167 self.add_grades()168 self.add_productions()169 self.add_sales()170 self.add_expenses()171 self.add_cash_uses()172 self.add_cash_sources()173 self.add_farmer_payments()174 self.report.working_capital = Decimal("11407500")175 self.report.working_capital_repaid = Decimal("128700")176 self.report.capacity = Decimal("20000")177 self.report.miscellaneous_sources = Decimal("0")178 self.report.is_finalized = True179 self.report.save()180 self.currency = self.usd181 from aggregates.models import SeasonAggregate182 self.assertEquals(1, SeasonAggregate.calculate_for_season(self.report.season))183 self.render_report()184 def test_full_render_with_aggregates_no_top(self):185 self.add_grades()186 self.add_productions()187 self.add_sales()188 self.add_expenses()189 self.add_cash_uses()190 self.add_cash_sources()191 self.add_farmer_payments()192 # this will make green 15 not a top grade193 self.rwanda_2010.add_grade(self.green15, False)194 self.report.working_capital = Decimal("11407500")195 self.report.working_capital_repaid = Decimal("128700")196 self.report.capacity = Decimal("20000")197 self.report.miscellaneous_sources = Decimal("0")198 self.report.is_finalized = True199 self.report.save()200 self.currency = self.usd201 from aggregates.models import SeasonAggregate202 self.assertEquals(1, SeasonAggregate.calculate_for_season(self.report.season))203 self.render_report()204 def test_full_render_with_collapsed_wetmill_expenses(self):205 self.add_grades()206 self.add_productions()207 self.add_sales()208 self.add_expenses()209 self.add_cash_uses()210 self.add_cash_sources()211 self.add_farmer_payments()212 # this will set the washing station expenses as collapsed213 self.rwanda_2010.add_expense(self.washing_expenses, True)214 self.report.working_capital = Decimal("11407500")215 self.report.working_capital_repaid = Decimal("128700")216 self.report.capacity = Decimal("20000")217 self.report.miscellaneous_sources = Decimal("0")218 self.report.is_finalized = True219 self.report.save()220 self.currency = self.usd221 from aggregates.models import SeasonAggregate222 self.assertEquals(1, SeasonAggregate.calculate_for_season(self.report.season))223 self.render_report()224 def test_full_render_rwf(self):225 self.add_grades()226 self.add_productions()227 self.add_sales()228 self.add_expenses()229 self.add_cash_uses()230 self.add_cash_sources()231 self.add_farmer_payments()232 self.report.working_capital = Decimal("11407500")233 self.report.working_capital_repaid = Decimal("128700")234 self.report.capacity = Decimal("20000")235 self.report.miscellaneous_sources = Decimal("0")236 self.report.is_finalized = True237 self.report.save()238 self.currency = self.rwf239 from aggregates.models import SeasonAggregate240 self.assertEquals(1, SeasonAggregate.calculate_for_season(self.report.season))241 self.render_report()242 def test_full_render_finalized_no_aggs(self):243 self.add_grades()244 self.add_productions()245 self.add_sales()246 self.add_expenses()247 self.add_cash_uses()248 self.add_cash_sources()249 self.add_farmer_payments()250 self.report.working_capital = Decimal("11407500")251 self.report.working_capital_repaid = Decimal("128700")252 self.report.capacity = Decimal("20000")253 self.report.miscellaneous_sources = Decimal("0")254 self.report.is_finalized = True255 self.report.save()256 self.currency = self.rwf257 from aggregates.models import SeasonAggregate258 self.assertEquals(1, SeasonAggregate.calculate_for_season(self.report.season))259 SeasonAggregate.objects.all().delete()260 self.render_report()261 def test_full_render_collapse_washing(self):262 self.add_grades()263 self.add_productions()264 self.add_sales()265 self.add_expenses()266 self.add_cash_uses()267 self.add_cash_sources()268 self.add_farmer_payments()269 self.rwanda_2010.add_expense(self.washing_expenses, True)270 self.report.working_capital = Decimal("11407500")271 self.report.working_capital_repaid = Decimal("128700")272 self.report.miscellaneous_sources = Decimal("0")273 self.report.save()274 self.render_report()275 def test_full_render_ethiopia(self):276 self.setup_ethiopia_season()277 self.add_ethiopia_productions()278 self.add_ethiopia_sales()279 self.add_ethiopia_expenses()280 self.add_ethiopia_cash_uses()281 self.add_cash_sources()282 self.add_farmer_payments()283 self.render_report()284 def test_full_render_ethiopia_hide_buyers(self):285 self.setup_ethiopia_season()286 self.add_ethiopia_productions()287 self.add_ethiopia_sales()288 self.add_ethiopia_expenses()289 self.add_ethiopia_cash_uses()290 self.add_cash_sources()291 self.add_farmer_payments()292 self.render_report(show_buyers=False)293 def test_full_render_misc_revenue(self):294 self.season.has_misc_revenue = True295 self.season.save()296 self.report.miscellaneous_revenue = Decimal("100000")297 self.report.save()298 self.add_grades()299 self.add_productions()300 self.add_sales()301 self.add_expenses()302 self.add_cash_uses()303 self.add_cash_sources()304 self.add_farmer_payments()305 self.render_report()306 def test_render_wrap(self):307 self.add_grades()308 self.add_expenses()309 self.green15.name = "A long grade name that will be forced to wrap"310 self.green15.save()311 self.washing_expenses.name = "This is a really long expense name that will be forced to wrap but man it really needs to be crazy long and needing to be wrapped"312 self.washing_expenses.save()313 self.cherry_advance.name = "CherryAdvanceIsAllOneReallyLongWordWithoutSpacesWhatWillHappenIfitcontinuestobesocrazylongOhMyWhatWillHappen"314 self.cherry_advance.save()315 self.render_report()316 def test_round_value(self):317 test_buffer = StringIO()318 pdf_report = PDFReport(self.report, self.currency)319 self.assertEquals("100.12", pdf_report.round_value(Decimal("100.1203")))320 self.assertEquals("100.13", pdf_report.round_value(Decimal("100.1293")))321 self.assertEquals("None", pdf_report.round_value(None))...
__init__.py
Source:__init__.py
...26import render27import int_to_text28import report_sxw29import printscreen30def render_report(cr, uid, ids, name, data, context=None):31 """32 Helper to call ``ir.actions.report.xml.render_report()``.33 """34 registry = openerp.modules.registry.RegistryManager.get(cr.dbname)35 return registry['ir.actions.report.xml'].render_report(cr, uid, ids, name, data, context)...
report.py
Source:report.py
1# -*- coding: utf-8 -*-2from odoo import report3from ..tools import PerfLogger, profile4native_render_report = report.render_report5def render_report(cr, uid, ids, name, data, context=None):6 logger = PerfLogger()7 logger.on_enter(cr, uid, '/xmlrpc/report', '', 'render_report')8 try:9 res = profile(native_render_report)(cr, uid, ids, name, data, context)10 logger.log_call((ids, name, data, context), res=res)11 return res12 except Exception, e:13 logger.log_call((ids, name, data, context), err=e)14 raise15 finally:16 logger.on_leave()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!