def test_generate_watched_forks_instances(self): """ This will test that the method is able to return all of the watched forks' instances for a specific organization and not anything else. """ fork1, fork2, fork3 = self._setup_watched_forks() watched_forks = generate_watched_forks_instances(self.organization) # Because the third fork doesn't have any instances, it's not going to be shown in the reports self.assertIsInstance(watched_forks, defaultdict) self.assertEqual(len(watched_forks), 2) # Watched Fork 1 has only two instances self.assertIsInstance(watched_forks[fork1], list) self.assertEqual(len(watched_forks[fork1]), 2) for instance in watched_forks[fork1]: self.assertIsInstance(instance, OpenEdXInstance) # Watched Fork 2 has only one instance self.assertIsInstance(watched_forks[fork2], list) self.assertEqual(len(watched_forks[fork2]), 1) for instance in watched_forks[fork2]: self.assertIsInstance(instance, OpenEdXInstance) # Watched Fork 3 has no instances self.assertIsInstance(watched_forks[fork3], list) self.assertEqual(len(watched_forks[fork3]), 0)
def report(request, organization, year, month): """ Report view """ try: invoice_start_date = timezone.make_aware( datetime(int(year), int(month), 1)) except ValueError: return HttpResponseBadRequest( content='<h1>Bad Request</h1>' '<p>Error when processing given date, consider using parameters within range</p>' ) organization = get_object_or_404(Organization, github_handle=organization) forks_instances = generate_watched_forks_instances(organization) billing_data, total = generate_charges(forks_instances, invoice_start_date) return render(request, 'report.html', context={ 'year': year, 'month': month, 'month_name': calendar.month_name[int(month)], 'organization': organization, 'billing_data': billing_data, 'total': total, })