Пример #1
0
 def setUp(self, datetime_mock):
     self.mock_today = date(2017, 1, 31)
     datetime_mock.today = Mock(return_value=self.mock_today)
     self.sponsor = Sponsor.objects.create(name="Sponsor 1",
                                           updated_date=self.mock_today)
     self.due_trial = makeTrial(self.sponsor,
                                results_due=True,
                                has_results=False,
                                updated_date=self.mock_today)
     self.reported_trial = makeTrial(
         self.sponsor,
         results_due=True,
         has_results=True,
         # The following has the effect of setting
         # `previous_status` to `overdue` and status to `reported`
         status=Trial.STATUS_OVERDUE,
         reported_date=date(2016, 12, 1),
         updated_date=self.mock_today)
     self.due_but_no_longer_act_trial = makeTrial(
         self.sponsor,
         results_due=True,
         has_results=False,
         previous_status=Trial.STATUS_OVERDUE,
         status=Trial.STATUS_NO_LONGER_ACT,
         updated_date=self.mock_today)
     self.old_no_longer_act_trial = makeTrial(
         self.sponsor,
         results_due=True,
         has_results=False,
         previous_status=Trial.STATUS_OVERDUE,
         status=Trial.STATUS_NO_LONGER_ACT,
         updated_date=date(2016, 1, 1))
     set_current_rankings()
 def setUp(self, datetime_mock):
     self.mock_today = date(2017, 1, 31)
     datetime_mock.today = Mock(return_value=self.mock_today)
     self.sponsor = Sponsor.objects.create(
         name="Sponsor 1",
         updated_date=self.mock_today)
     set_current_rankings()
Пример #3
0
 def setUp(self, datetime_mock):
     datetime_mock.today = Mock(return_value=date(2017, 1, 31))
     self.sponsor = Sponsor.objects.create(name="Sponsor 1")
     self.due_trial = makeTrial(self.sponsor,
                                results_due=True,
                                has_results=False)
     self.reported_trial = makeTrial(self.sponsor,
                                     results_due=True,
                                     has_results=True,
                                     reported_date=date(2016, 12, 1))
     set_current_rankings()
def simulateImport(test_trials):
    """Do the same as the import script, but for an array of tuples
    """
    for update_date, trial in test_trials.items():
        Sponsor.objects.all().update(updated_date=update_date)
        for sponsor, due, reported in trial:
            makeTrial(sponsor,
                      results_due=due,
                      has_results=reported,
                      reported_date=update_date)
        set_current_rankings()
        Trial.objects.all().delete()  # this is what the import process does
 def test_single_variable(self, twitter_mock):
     self.due_trial = makeTrial(
         self.sponsor,
         results_due=True,
         has_results=False,
         updated_date=self.mock_today)
     set_current_rankings()
     api = MagicMock(twitter.api.Api, name='api')
     twitter_mock.Api.return_value = api
     out = StringIO()
     call_command('tweet_today', stdout=out)
     api.PostUpdate.assert_called_with(
         'Since our last update, 1 trial became overdue. 0% of all due '
         'trials have reported their results.  '
         'https://fdaaa.trialstracker.net/')
Пример #6
0
 def test_performance_no_results(self):
     Sponsor.objects.create(name="xyz", slug="xyz")
     set_current_rankings()
     client = APIClient()
     response = client.get('/api/performance/', {
         'sponsor': 'xyz'
     },
                           format='json').json()
     self.assertEqual(
         response, {
             'due': 0,
             'reported': 0,
             'overdue_today': 0,
             'late_today': 0,
             'days_late': None,
             'on_time_today': 0,
             'fines_str': '$0'
         })
Пример #7
0
 def _makeRankingsForDate(self, target_date):
     with patch('frontend.trial_computer.date') as datetime_mock:
         self.mock_today = target_date
         datetime_mock.today = Mock(return_value=self.mock_today)
         self.sponsor1 = _make_sponsor_with_date(1, self.mock_today)
         self.sponsor2 = _make_sponsor_with_date(2, self.mock_today)
         self.due_trial = makeTrial(self.sponsor1,
                                    registry_id='due trial',
                                    results_due=True,
                                    has_results=False,
                                    updated_date=self.mock_today)
         self.reported_trial = makeTrial(self.sponsor2,
                                         registry_id='reported trial',
                                         results_due=True,
                                         has_results=True,
                                         reported_date=date(2016, 12, 1),
                                         updated_date=self.mock_today)
         set_current_rankings()
 def test_all_variables(self, twitter_mock):
     self.due_trial = makeTrial(
         self.sponsor,
         results_due=True,
         has_results=False,
         updated_date=self.mock_today)
     self.invisible_ongoing_trial = makeTrial(
         self.sponsor,
         results_due=True,
         has_results=False,
         previous_status=Trial.STATUS_ONGOING,
         status=Trial.STATUS_NO_LONGER_ACT,
         updated_date=self.mock_today)
     self.invisible_overdue_trial = makeTrial(
         self.sponsor,
         results_due=True,
         has_results=False,
         previous_status=Trial.STATUS_OVERDUE,
         status=Trial.STATUS_NO_LONGER_ACT,
         updated_date=self.mock_today)
     self.reported_trial = makeTrial(
         self.sponsor,
         results_due=True,
         has_results=True,
         reported_date=date(2016, 12, 1),
         updated_date=self.mock_today)
     for _ in range(3):
         self.late_trial = makeTrial(
             self.sponsor,
             results_due=True,
             has_results=True,
             reported_date=date(2017, 12, 1),
             updated_date=self.mock_today)
     set_current_rankings()
     api = MagicMock(twitter.api.Api, name='api')
     twitter_mock.Api.return_value = api
     out = StringIO()
     call_command('tweet_today', stdout=out)
     api.PostUpdate.assert_called_with(
         'Since our last update, 1 trial became overdue, and 3 trials '
         'reported late. 1 trial reported its results on time. 80% of '
         'all due trials have reported their results.  '
         'https://fdaaa.trialstracker.net/')
    def test_today_counts(self):
        # save all the Trials with a new date to simulate an import run
        new_date = date.today() + datetime.timedelta(days=1)
        for trial in Trial.objects.all():
            trial.updated_date = new_date
            trial.sponsor.updated_date = new_date
            trial.save()
            trial.sponsor.save()
        # now alter a couple so we have new "today" state changes
        TrialQA.objects.create(submitted_to_regulator=date(2017, 1, 1),
                               trial_id=self.cancelled_trial.id)
        TrialQA.objects.create(submitted_to_regulator=date(2016, 1, 1),
                               trial_id=self.due_trial.id)
        set_current_rankings()

        self.assertCountEqual(Trial.objects.no_longer_overdue_today(),
                              [self.due_trial, self.cancelled_trial])
        self.assertCountEqual(Trial.objects.late_today(),
                              [self.cancelled_trial])
        self.assertCountEqual(Trial.objects.on_time_today(), [self.due_trial])