def test_add_all_resource_filter_mixed(self):
     date1 = datetime(2019, 1, 1)
     resource_counts1 = {
         u'resource1': 10002,
         u'cresource2': 51,
     }
     date2 = datetime(2020, 1, 1)
     resource_counts2 = {
         u'resource1': 29,
         u'cresource2': 38290,
     }
     monthly_stats = MonthlyStats(resource_id=u'resource1')
     monthly_stats.add_all(date1, resource_counts1)
     monthly_stats.add_all(date2, resource_counts2)
     assert monthly_stats.stats[u'1/2019'][u'research'][u'records'] == 10002
     assert monthly_stats.stats[u'1/2019'][u'research'][
         u'download_events'] == 1
     assert monthly_stats.stats[u'1/2019'][u'collections'][u'records'] == 0
     assert monthly_stats.stats[u'1/2019'][u'collections'][
         u'download_events'] == 0
     assert monthly_stats.stats[u'1/2020'][u'research'][u'records'] == 29
     assert monthly_stats.stats[u'1/2020'][u'research'][
         u'download_events'] == 1
     assert monthly_stats.stats[u'1/2020'][u'collections'][u'records'] == 0
     assert monthly_stats.stats[u'1/2020'][u'collections'][
         u'download_events'] == 0
 def test_month_year_format(self):
     # currently the month/year keys are not zero padded so we might as well test that that is
     # still the case in case a developer gets refactor happy and changes it (I did this so maybe
     # this test is for me...)
     monthly_stats = MonthlyStats()
     for month in range(1, 12):
         date = datetime(2017, month, 1)
         monthly_stats.add_all(date, resource_counts=dict(resource1=10))
         month_year = u'{}/2017'.format(month)
         assert monthly_stats.stats[month_year][u'research'][
             u'records'] == 10
         assert monthly_stats.stats[month_year][u'research'][
             u'download_events'] == 1
 def test_add_all_no_filters_mixed(self):
     date = datetime(2020, 1, 1)
     resource_counts = {
         u'resource1': 10002,
         u'cresource2': 51,
     }
     monthly_stats = MonthlyStats()
     monthly_stats.add_all(date, resource_counts)
     assert monthly_stats.stats[u'1/2020'][u'collections'][u'records'] == 51
     assert monthly_stats.stats[u'1/2020'][u'collections'][
         u'download_events'] == 1
     assert monthly_stats.stats[u'1/2020'][u'research'][u'records'] == 10002
     assert monthly_stats.stats[u'1/2020'][u'research'][
         u'download_events'] == 1
 def test_add_all_complex_filter_mixed(self):
     date = datetime(2019, 6, 1)
     resource_counts = {
         u'resource1': 10,
         u'cresource2': 51,
         u'resource2': 19,
     }
     monthly_stats = MonthlyStats(month=6,
                                  year=2019,
                                  resource_id=u'resource2')
     monthly_stats.add_all(date, resource_counts)
     assert monthly_stats.stats[u'6/2019'][u'research'][u'records'] == 0
     assert monthly_stats.stats[u'6/2019'][u'research'][
         u'download_events'] == 0
     assert monthly_stats.stats[u'6/2019'][u'collections'][u'records'] == 19
     assert monthly_stats.stats[u'6/2019'][u'collections'][
         u'download_events'] == 1
 def test_add(self):
     # check that add just calls add_all
     monthly_stats = MonthlyStats()
     monthly_stats.add_all = MagicMock()
     date = MagicMock()
     resource_id = MagicMock()
     count = MagicMock()
     monthly_stats.add(date, resource_id, count)
     assert monthly_stats.add_all.called
     assert monthly_stats.add_all.call_args == call(date,
                                                    {resource_id: count})