Exemplo n.º 1
0
    def setUp(self):
        filename = os.path.join(os.path.dirname(__file__), "data/C4BR2.tsv")
        rep = report.parse(filename)
        with csvhelper.UnicodeReader(filename, delimiter="\t") as report_reader:
            self.file_content = list(report_reader)

        self.output_content = rep.as_generic()
Exemplo n.º 2
0
    def setUp(self):
        filename = os.path.join(os.path.dirname(__file__), "data/C4JR1mul.csv")
        rep = report.parse(filename)
        with csvhelper.UnicodeReader(filename, delimiter=",") as report_reader:
            self.file_content = list(report_reader)

        self.output_content = rep.as_generic()
Exemplo n.º 3
0
    def test_csv_unicode(self):
        rep = report.parse(os.path.join(os.path.dirname(__file__),
                                        'data/simpleJR1.csv'))

        self.assertTrue(isinstance(rep.pubs[0].title, text_type))
        self.assertTrue(isinstance(rep.pubs[0].publisher, text_type))
        self.assertTrue(isinstance(rep.pubs[0].platform, text_type))
Exemplo n.º 4
0
    def setUp(self):
        self.filename = os.path.join(os.path.dirname(__file__),
                                     'data/simpleJR1.tsv')
        self.rep = report.parse(self.filename)
        with csvhelper.UnicodeReader(self.filename,
                                     delimiter=',') as report_reader:
            self.file_content = list(report_reader)

        self.output_content = self.rep.as_generic()
Exemplo n.º 5
0
 def handle(self, *args, **options):
     data = report.parse(options['file'])
     organization = Organization.objects.get(
         internal_id=options['organization'])
     platform = Platform.objects.get(short_name=options['platform'])
     op, created = OrganizationPlatform.objects.get_or_create(
         platform=platform, organization=organization)
     if created:
         self.stderr.write(
             self.style.SUCCESS(
                 f'Created Organization-Platform connection between {organization} and {platform}'
             ))
     report_type = ReportType.objects.get(short_name=options['report_type'])
     reader = Counter4JR1Report()
     records = reader.read_report(data)
     stats = import_counter_records(report_type, organization, platform,
                                    records)
     self.stderr.write(self.style.WARNING(f'Import stats: {stats}'))
Exemplo n.º 6
0
 def test_import_br2_tsv(self, organizations, report_type_nd, platform):
     rt = report_type_nd(1, dimension_names=['Publisher'])
     from pycounter import report
     data = report.parse('apps/logs/tests/data/counter4_br2.tsv')
     reader = Counter4BR2Report()
     records = reader.read_report(data)
     assert len(records) == 60  # 12 months, 5 titles
     organization = organizations[0]
     import_batch = ImportBatch.objects.create(platform=platform,
                                               organization=organization,
                                               report_type=rt)
     assert AccessLog.objects.count() == 0
     stats = import_counter_records(rt, organization, platform, records,
                                    import_batch)
     assert AccessLog.objects.count() == 60
     assert stats['new logs'] == 60
     values = [
         al['value'] for al in AccessLog.objects.filter(
             target__name='Columbia Electronic Encyclopedia, 6th Edition').
         order_by('date').values()
     ]
     assert len(values) == 12
     assert values == [1, 10, 2, 3, 5, 0, 0, 0, 0, 0, 0, 0]
Exemplo n.º 7
0
def test_bogus_file_type():
    with pytest.raises(pycounter.exceptions.PycounterException):
        report.parse("no_such_file", "qsx")
Exemplo n.º 8
0
 def file_to_input(cls, filename: str):
     return report.parse(filename)
Exemplo n.º 9
0
 def setUp(self):
     self.report = report.parse(
         os.path.join(os.path.dirname(__file__), 'data/C4JR1GOA.csv'))
Exemplo n.º 10
0
def csv_jr1_report_common_data(request):
    return report.parse(
        os.path.join(os.path.dirname(__file__), "data", request.param))
 def setUp(self):
     self.report = report.parse(
         os.path.join(os.path.dirname(__file__), "data/xlsxJR1"))
Exemplo n.º 12
0
 def setUp(self):
     self.report = report.parse(os.path.join(os.path.dirname(__file__),
                                'data/JR1.xlsx'))
Exemplo n.º 13
0
def csv_jr1_report(request):
    """Various CSV format JR1 reports."""
    return report.parse(os.path.join(os.path.dirname(__file__), "data", request.param))
Exemplo n.º 14
0
def test_unicode_fields(filename, attribute):
    """All parsers should return text fields as unicode"""
    rep = report.parse(os.path.join(os.path.dirname(__file__), "data", filename))
    assert isinstance(getattr(rep.pubs[0], attribute), text_type)
Exemplo n.º 15
0
    def setUp(self):
        self.filename = os.path.join(os.path.dirname(__file__),
                                     "data/C4BR1.tsv")
        self.rep = report.parse(self.filename)

        self.output_content = self.rep.as_generic()
Exemplo n.º 16
0
 def setUp(self):
     self.report = report.parse(
         os.path.join(os.path.dirname(__file__), "data/xlsxJR1")
     )
Exemplo n.º 17
0
 def setUp(self):
     self.report = report.parse(os.path.join(os.path.dirname(__file__),
                                             'data/C4JR1_bad.csv'))
Exemplo n.º 18
0
 def setUp(self):
     self.report = report.parse(os.path.join(os.path.dirname(__file__),
                                             'data/simpleJR1.csv'))
Exemplo n.º 19
0
 def setUp(self):
     self.report = report.parse(
         os.path.join(os.path.dirname(__file__), 'data/JR1_bad.xlsx'))
Exemplo n.º 20
0
 def setUp(self):
     self.filename = os.path.join(os.path.dirname(__file__),
                                  'data/simpleJR1.tsv')
     self.rep = report.parse(self.filename)
Exemplo n.º 21
0
def csv_jr1_report_common_data(request):
    """JR1 reports with shared common data we can make assertions about."""
    return report.parse(os.path.join(os.path.dirname(__file__), "data", request.param))
Exemplo n.º 22
0
def jr1_report(request):
    return report.parse(
        os.path.join(os.path.dirname(__file__), "data", request.param))
Exemplo n.º 23
0
def jr1_report_xlsx(request):
    """Excel formatted JR1 reports."""
    return report.parse(os.path.join(os.path.dirname(__file__), "data", request.param))
Exemplo n.º 24
0
 def setUp(self):
     self.report = report.parse(
         os.path.join(os.path.dirname(__file__), 'data/simpleJR1.tsv'))
Exemplo n.º 25
0
 def setUp(self):
     self.filename = os.path.join(os.path.dirname(__file__), "data/simpleJR1.tsv")
     self.rep = report.parse(self.filename)
Exemplo n.º 26
0
 def setUp(self):
     self.report = report.parse(os.path.join(os.path.dirname(__file__),
                                             'data/tsvC4JR1'))
Exemplo n.º 27
0
 def setUp(self):
     self.report = report.parse(
         os.path.join(os.path.dirname(__file__), "data/C4JR1my.csv")
     )
Exemplo n.º 28
0
def csv_jr1_report_std(request):
    """Standard (non-GOA) JR1 reports."""
    return report.parse(os.path.join(os.path.dirname(__file__), "data", request.param))
Exemplo n.º 29
0
def test_counter3_deprecation():
    with pytest.warns(DeprecationWarning):
        report.parse(
            os.path.join(os.path.dirname(__file__), "data/simpleJR1.csv"))
Exemplo n.º 30
0
def csv_jr1_r4_report(request):
    """Revision 4 JR1 reports."""
    return report.parse(os.path.join(os.path.dirname(__file__), "data", request.param))
Exemplo n.º 31
0
 def setUp(self):
     self.report = report.parse(
         os.path.join(os.path.dirname(__file__), "data/C4JR1my.csv"))
Exemplo n.º 32
0
def csv_jr1_r4_report(request):
    return report.parse(os.path.join(os.path.dirname(__file__), "data", request.param))
Exemplo n.º 33
0
    def setUp(self):
        self.filename = os.path.join(os.path.dirname(__file__), "data/C4BR1.tsv")
        self.rep = report.parse(self.filename)

        self.output_content = self.rep.as_generic()
Exemplo n.º 34
0
def parsedata(filename):
    """Helper function returns a report from a filename relative to data directory."""
    return report.parse(
        os.path.join(os.path.dirname(__file__), "data", filename))
Exemplo n.º 35
0
def csv_jr1_report(request):
    return report.parse(os.path.join(os.path.dirname(__file__),
                                     'data', request.param))