Пример #1
0
    def test_DrawDateSync_ResultHasCorrespondingDrawDateInDrawTable_ResultDrawDateIsSynced(
            self):
        """
        Should sync draw dates from Draw table to results in Result table
        """

        # Add draw date to draw table first
        site_code = '999X'
        reference_number = '12345'

        # Add draw date to Draw table
        Session.add(
            models.Draw(site_code=site_code,
                        reference_number=reference_number,
                        draw_date=datetime.date.today()))
        transaction.commit()

        gpg = self.gpg
        datafile = os.path.join(self.tempdir, 'data')

        io = StringIO()
        print >> io, 'Has 1 result'
        print >> io, '999X 12345                                      P               N  N  N'  # NOQA
        io.flush()
        io.seek(0)
        gpg.encrypt_file(io,
                         str(self.key),
                         passphrase=self.passphrase,
                         output=datafile)
        io.close()

        sys.argv = ['', '-c', self.configfile, datafile]
        scripts.parse.main()

        result = Session.query(models.Result)\
            .filter(models.Result.site_code == site_code)\
            .filter(models.Result.reference_number == reference_number).first()

        # Is there a draw date?
        assert result.draw_date
Пример #2
0
def test_parsefp_duplicate_result():
    """
    Ensure we can detect duplicates
    """
    site_code = 'XXXX'
    reference_number = 'YYYYY'

    # Create a pre-existing result
    Session.add(
        models.Result(site_code=site_code,
                      reference_number=reference_number,
                      nat='N',
                      file='oldfile.txt'))
    Session.flush()

    fp = StringIO()
    print >> fp, 'Line 1'
    print >> fp, (site_code + ' ' + reference_number).ljust(80)
    fp.seek(0)
    results, duplicates = parser.parsefp(fp)
    eq_(len(results), 0)
    eq_(len(duplicates), 1)
Пример #3
0
    def test_FindMissingDraw_MixedResultsMoreAndLessThan6MonthsOldAndAllMissingDrawDates_ReturnListOfValidResults(
            self):
        """
        Should return 3 results out of 5 in a list. These 3 results' test date are less
        than 180 days. All results are missing draw dates.
        """

        missing_draw = []
        current_time = datetime.date.today()
        date1 = current_time - datetime.timedelta(days=30)
        date2 = current_time - datetime.timedelta(days=60)
        date3 = current_time - datetime.timedelta(days=90)
        # Older than 180 days
        date4 = current_time - datetime.timedelta(days=200)
        date5 = current_time - datetime.timedelta(days=300)

        # Add 5 unique results where 5 results are missing their draw date and
        # 3 are less than 6 months old. The other 2 are more than 6 months old.
        site_code = '99X'
        reference_number1 = '11111'
        reference_number2 = '22222'
        reference_number3 = '33333'
        reference_number4 = '44444'
        reference_number5 = '55555'

        Session.add(
            models.Result(site_code=site_code,
                          reference_number=reference_number1,
                          test_date=date1,
                          nat='P',
                          dhiv='N',
                          file='results.txt'))

        Session.add(
            models.Result(site_code=site_code,
                          reference_number=reference_number2,
                          test_date=date2,
                          nat='P',
                          dhiv='N',
                          file='results.txt'))

        Session.add(
            models.Result(site_code=site_code,
                          reference_number=reference_number3,
                          test_date=date3,
                          nat='P',
                          dhiv='N',
                          file='results.txt'))

        Session.add(
            models.Result(site_code=site_code,
                          reference_number=reference_number4,
                          test_date=date4,
                          nat='P',
                          dhiv='N',
                          file='results.txt'))

        Session.add(
            models.Result(site_code=site_code,
                          reference_number=reference_number5,
                          test_date=date5,
                          nat='P',
                          dhiv='N',
                          file='results.txt'))

        transaction.commit()

        missing_draw = scripts.parse.find_missing_draw()

        # Correct number of missing draw date cases?
        assert len(missing_draw) == 3

        # Are they really missing draw dates?
        for x in missing_draw:
            assert not x.draw_date

        results_expiration = current_time - datetime.timedelta(days=180)

        # Are their test dates under 180 days
        for x in missing_draw:
            assert x.test_date > results_expiration
Пример #4
0
    def test_FindMissingDraw_AllResultsMoreThan6MonthsOldAndAllMissingDrawDates_ReturnEmptyListOfResults(
            self):
        """
        Should return an empty list of results because all results' test date is older
        than 180 days. All results are missing draw dates.
        """

        missing_draw = []

        current_time = datetime.date.today()
        date1 = current_time - datetime.timedelta(days=190)
        date2 = current_time - datetime.timedelta(days=200)
        date3 = current_time - datetime.timedelta(days=250)
        date4 = current_time - datetime.timedelta(days=300)
        date5 = current_time - datetime.timedelta(days=350)

        # Add 5 unique results where 5 results are missing their draw date and
        # 5 are more than 6 months old
        site_code = '99X'
        reference_number1 = '11111'
        reference_number2 = '22222'
        reference_number3 = '33333'
        reference_number4 = '44444'
        reference_number5 = '55555'

        Session.add(
            models.Result(site_code=site_code,
                          reference_number=reference_number1,
                          test_date=date1,
                          nat='P',
                          dhiv='N',
                          file='results.txt'))

        Session.add(
            models.Result(site_code=site_code,
                          reference_number=reference_number2,
                          test_date=date2,
                          nat='P',
                          dhiv='N',
                          file='results.txt'))

        Session.add(
            models.Result(site_code=site_code,
                          reference_number=reference_number3,
                          test_date=date3,
                          nat='P',
                          dhiv='N',
                          file='results.txt'))

        Session.add(
            models.Result(site_code=site_code,
                          reference_number=reference_number4,
                          test_date=date4,
                          nat='P',
                          dhiv='N',
                          file='results.txt'))

        Session.add(
            models.Result(site_code=site_code,
                          reference_number=reference_number5,
                          test_date=date5,
                          nat='P',
                          dhiv='N',
                          file='results.txt'))

        transaction.commit()

        missing_draw = scripts.parse.find_missing_draw()

        # Correct number of missing draw date cases?
        assert len(missing_draw) == 0