Пример #1
0
 def test_legend_by_is_a_str(self):
     series_input = \
       {'avg_price': { 
          'source': SalesHistory.objects.all(),
          'func': Avg('price'),
          'categories': [
            'bookstore__city__state', 
            'bookstore__city__city'],
          'legend_by': 'book__genre__name',
          'top_n_per_cat': 5,
          'field_aliases': {
            'bookstore__city__state': 'state',
            'bookstore__city__city': 'city',
            'book__genre__name': 'name'}}}
     series_cleaned = \
       {'avg_price': { 
          'source': SalesHistory.objects.all(),
          'func': Avg('price'),
          'categories': [
            'bookstore__city__state', 
            'bookstore__city__city'],
          'legend_by': ['book__genre__name'],
          'top_n_per_cat': 5,
          'field_aliases': {
            'bookstore__city__state': 'state',
            'bookstore__city__city': 'city',
            'book__genre__name': 'name'}}}
     self.assertOptionDictsEqual(clean_pdps(series_input),
                                series_cleaned)
Пример #2
0
 def test_legend_by_is_a_str(self):
     series_input = {
         "avg_price": {
             "source": SalesHistory.objects.all(),
             "func": Avg("price"),
             "categories": ["bookstore__city__state", "bookstore__city__city"],
             "legend_by": "book__genre__name",
             "top_n_per_cat": 5,
             "field_aliases": {
                 "bookstore__city__state": "state",
                 "bookstore__city__city": "city",
                 "book__genre__name": "name",
             },
         }
     }
     series_cleaned = {
         "avg_price": {
             "source": SalesHistory.objects.all(),
             "func": Avg("price"),
             "categories": ["bookstore__city__state", "bookstore__city__city"],
             "legend_by": ["book__genre__name"],
             "top_n_per_cat": 5,
             "field_aliases": {
                 "bookstore__city__state": "state",
                 "bookstore__city__city": "city",
                 "book__genre__name": "name",
             },
         }
     }
     self.assertOptionDictsEqual(clean_pdps(series_input), series_cleaned)
Пример #3
0
    def test_source_a_model(self):
                
        series_input = \
          [{'options': 
             {'source': SalesHistory,
              'categories': 'bookstore__city__state',
              'legend_by': 'book__genre__name',
              'top_n_per_cat': 2},
            'terms': {
              'avg_price': Avg('price'),
              'avg_price_all': {
                'func': Avg('price'),
                'legend_by': None}}}]

        series_cleaned = \
          {'avg_price': {
            'source': SalesHistory.objects.all(),
            'func': Avg('price'),
            'categories': ['bookstore__city__state'],
            'legend_by': ['book__genre__name'],
            'top_n_per_cat': 2,
            'field_aliases': {
              'bookstore__city__state': 'state',
              'book__genre__name': 'name'}},
           'avg_price_all': {
             'func': Avg('price'),
             'source': SalesHistory.objects.all(),
             'categories': ['bookstore__city__state'],
             'legend_by': (),
             'top_n_per_cat': 2,
             'field_aliases': {
               'bookstore__city__state': 'state'}}}
        
        self.assertOptionDictsEqual(clean_pdps(series_input),
                                   series_cleaned)
Пример #4
0
    def test_categories_a_str(self):

        series_input = [
            {
                "options": {},
                "terms": {
                    "avg_price": {
                        "source": SalesHistory.objects.all(),
                        "categories": "bookstore__city__state",
                        "func": Avg("price"),
                        "top_n_per_cat": 3,
                    }
                },
            }
        ]

        series_cleaned = {
            "avg_price": {
                "source": SalesHistory.objects.all(),
                "func": Avg("price"),
                "categories": ["bookstore__city__state"],
                "legend_by": (),
                "top_n_per_cat": 3,
                "field_aliases": {"bookstore__city__state": "state"},
            }
        }

        self.assertOptionDictsEqual(clean_pdps(series_input), series_cleaned)
Пример #5
0
 def test_no_legend_by(self):
     series_input = \
       {'avg_price': {
          'source': SalesHistory.objects.all(),
          'func': Avg('price'),
          'categories': [
            'bookstore__city__state',
            'bookstore__city__city'],
          'top_n_per_cat': 5,
          'field_aliases': {
            'bookstore__city__state': 'state',
            'bookstore__city__city': 'city'}}}
     series_cleaned = \
       {'avg_price': {
          'source': SalesHistory.objects.all(),
          'func': Avg('price'),
          'categories': [
            'bookstore__city__state',
            'bookstore__city__city'],
          'legend_by': (),
          'top_n_per_cat': 5,
          'field_aliases': {
            'bookstore__city__state': 'state',
            'bookstore__city__city': 'city'}}}
     self.assertOptionDictsEqual(clean_pdps(series_input), series_cleaned)
Пример #6
0
    def test_source_a_model(self):
        series_input = \
          [{'options':
             {'source': SalesHistory,
              'categories': 'bookstore__city__state',
              'legend_by': 'book__genre__name',
              'top_n_per_cat': 2},
            'terms': {
              'avg_price': Avg('price'),
              'avg_price_all': {
                'func': Avg('price'),
                'legend_by': None}}}]

        series_cleaned = \
          {'avg_price': {
            'source': SalesHistory.objects.all(),
            'func': Avg('price'),
            'categories': ['bookstore__city__state'],
            'legend_by': ['book__genre__name'],
            'top_n_per_cat': 2,
            'field_aliases': {
              'bookstore__city__state': 'state',
              'book__genre__name': 'name'}},
           'avg_price_all': {
             'func': Avg('price'),
             'source': SalesHistory.objects.all(),
             'categories': ['bookstore__city__state'],
             'legend_by': (),
             'top_n_per_cat': 2,
             'field_aliases': {
               'bookstore__city__state': 'state'}}}

        self.assertOptionDictsEqual(clean_pdps(series_input), series_cleaned)
Пример #7
0
    def test_multiple_dicts(self):

        series_input = [
            {
                "options": {
                    "source": SalesHistory.objects.all(),
                    "categories": "bookstore__city__state",
                    "legend_by": "book__genre__name",
                    "top_n_per_cat": 2,
                },
                "terms": {"avg_price": Avg("price")},
            },
            {
                "options": {
                    "source": SalesHistory.objects.filter(price__gte=10),
                    "categories": "bookstore__city__city",
                    "top_n_per_cat": 2,
                },
                "terms": {"avg_price_high": {"func": Avg("price"), "legend_by": None}},
            },
        ]

        series_cleaned = {
            "avg_price": {
                "source": SalesHistory.objects.all(),
                "func": Avg("price"),
                "categories": ["bookstore__city__state"],
                "legend_by": ["book__genre__name"],
                "top_n_per_cat": 2,
                "field_aliases": {"bookstore__city__state": "state", "book__genre__name": "name"},
            },
            "avg_price_high": {
                "func": Avg("price"),
                "source": SalesHistory.objects.filter(price__gte=10),
                "categories": ["bookstore__city__city"],
                "legend_by": (),
                "top_n_per_cat": 2,
                "field_aliases": {"bookstore__city__city": "city"},
            },
        }

        self.assertOptionDictsEqual(clean_pdps(series_input), series_cleaned)
Пример #8
0
    def test_opts_empty(self):
        series_input = \
          [{'options': {},
            'terms': {
              'avg_price': {
                'source': SalesHistory.objects.all(),
                'categories': ['bookstore__city__state'],
                'func': Avg('price'),
                'top_n_per_cat':3}}}]

        series_cleaned = \
          {'avg_price': {
            'source': SalesHistory.objects.all(),
            'func': Avg('price'),
            'categories': ['bookstore__city__state'],
            'legend_by': (),
            'top_n_per_cat': 3,
            'field_aliases': {
              'bookstore__city__state': 'state'}}}

        self.assertOptionDictsEqual(clean_pdps(series_input),
                                    series_cleaned)