コード例 #1
0
    def setUp(self):
        raw_data = [{
                 "fob_price":"3.12345678",
                 "landed_price":"4.98765432",
                 "country":"South Africa"}]

        self.formulation_table = FormulationTable(raw_data)
        rows = self.formulation_table.rows
        self.first_row = rows[self.FIRST_ROW]
コード例 #2
0
    def setUp(self):
        raw_data = [{
                 "fob_price":"3.12345678",
                 "landed_price":"4.98765432",
                 "country":"South Africa"}]

        self.formulation_table = FormulationTable(raw_data)
        rows = self.formulation_table.rows
        self.first_row = rows[self.FIRST_ROW]
コード例 #3
0
class FormulationTableTest(TableTestCase):
    FIRST_ROW = 0
    
    COUNTRY_COLUMN = 0
    FOB_PRICE_COLUMN = 1
    LANDED_PRICE_COLUMN = 2
    
    def setUp(self):
        raw_data = [{
                 "fob_price":"3.12345678",
                 "landed_price":"4.98765432",
                 "country":"South Africa"}]

        self.formulation_table = FormulationTable(raw_data)
        rows = self.formulation_table.rows
        self.first_row = rows[self.FIRST_ROW]
    
    def test_country_stored_in_first_column(self):
        country = self.get_nth_value(self.first_row, self.COUNTRY_COLUMN)
        
        self.assertEquals("South Africa", country)

    def test_fob_price_stored_in_second_column(self):
        fob_price = float(self.get_nth_value(self.first_row, self.FOB_PRICE_COLUMN))
        
        self.assertAlmostEquals(3.123, fob_price)

    def test_landed_price_stored_in_third_column(self):
        landed_price = float(self.get_nth_value(self.first_row, self.LANDED_PRICE_COLUMN))
        
        self.assertAlmostEquals(4.988, landed_price)

    def test_html_includes_table(self):
        html = self.formulation_table.as_html()
        self.assertTrue(self.contains(html, "<table>"))
        self.assertTrue(self.contains(html, "</table>"))

    def test_ordered_by_landed_price(self):
        order_by = self.formulation_table.order_by
        expected_order = ('landed_price',)
        self.assertEquals(expected_order, order_by)
コード例 #4
0
def formulation(request, formulation_id, backend_name="django"):
    backend = get_backend(backend_name)

    drug_searcher = DrugSearcher(backend)
    rows = drug_searcher.get_prices_for_formulation_with_id(formulation_id)

    # Don't like that, but results is being changed in the constructor of the table.
    rows_graph = deepcopy(rows)

    formulation_name = drug_searcher.get_formulation_name_with_id(
        formulation_id)
    formulation_msh = drug_searcher.get_formulation_msh_with_id(formulation_id)

    formulation_table = FormulationTable(rows)
    formulation_graph = FormulationGraph(rows_graph, formulation_msh)

    search_form = SearchForm()

    products_href = reverse('formulation_products',
                            args=[str(formulation_id), backend_name])
    formulation_tab = get_formulation_tab(None)
    similar_products_tab = get_similar_products_tab(products_href)
    menu = Menu([formulation_tab, similar_products_tab])

    price_popups = []
    for price_fields in rows:
        price_popups.append(PricePopup(price_fields))

    return render_to_response(
        'formulation.html', {
            'formulation_table': formulation_table,
            'formulation_graph': formulation_graph,
            'formulation_msh': formulation_msh,
            'price_popups': price_popups,
            'menu': menu,
            'search_form': search_form,
            'sub_title': "Formulation",
            'sub_sub_title': formulation_name
        }, RequestContext(request))