Exemplo n.º 1
0
def process_iarc_changes(date=None):
    """
    Queries IARC for recent changes in the past 24 hours (or date provided).

    If date provided use it. It should be in the form YYYY-MM-DD.
    """
    if waffle.switch_is_active('iarc-upgrade-v2'):
        get_rating_changes(date=date)
    else:
        _process_iarc_rating_changes_v1(date=date)
Exemplo n.º 2
0
    def test_with_existing_descriptors_that_should_be_kept(self):
        data = setup_mock_response('GetRatingChanges')
        cert_id = data['CertList'][0]['CertID']
        app = app_factory()
        IARCCert.objects.create(app=app, cert_id=UUID(cert_id))
        RatingDescriptors.objects.create(addon=app, has_classind_violence=True)

        get_rating_changes()

        eq_(UUID(app.iarc_cert.cert_id), UUID(cert_id))
        app = Webapp.objects.get(pk=app.pk)
        # Original descriptor belongs to a rating body that wasn't part of the
        # changes returned by GetRatingChanges for this cert, so it should have
        # been kept.
        self.assertSetEqual(app.rating_descriptors.to_keys(),
                            ['has_classind_violence', 'has_esrb_violence_ref'])
Exemplo n.º 3
0
    def test_with_existing_descriptors_that_should_be_kept(self):
        data = setup_mock_response('GetRatingChanges')
        cert_id = data['CertList'][0]['CertID']
        app = app_factory()
        IARCCert.objects.create(app=app, cert_id=UUID(cert_id))
        RatingDescriptors.objects.create(addon=app, has_classind_violence=True)

        get_rating_changes()

        eq_(UUID(app.iarc_cert.cert_id), UUID(cert_id))
        app = Webapp.objects.get(pk=app.pk)
        # Original descriptor belongs to a rating body that wasn't part of the
        # changes returned by GetRatingChanges for this cert, so it should have
        # been kept.
        self.assertSetEqual(app.rating_descriptors.to_keys(),
                            ['has_classind_violence', 'has_esrb_violence_ref'])
Exemplo n.º 4
0
 def test_with_date(self):
     setup_mock_response('GetRatingChanges')
     expected_start_date = self.days_ago(2)
     expected_end_date = expected_start_date - datetime.timedelta(days=1)
     get_rating_changes(date=expected_start_date)
     eq_(len(responses.calls), 1)
     eq_(responses.calls[0].request.headers.get('StorePassword'),
         settings.IARC_V2_STORE_PASSWORD)
     eq_(responses.calls[0].request.headers.get('StoreID'),
         settings.IARC_V2_STORE_ID)
     eq_(json.loads(responses.calls[0].request.body), {
         'StartDate': expected_start_date.strftime('%Y-%m-%d'),
         'EndDate': expected_end_date.strftime('%Y-%m-%d'),
         'MaxRows': 500,
         'StartRowIndex': 0
     })
Exemplo n.º 5
0
 def test_with_date(self):
     setup_mock_response('GetRatingChanges')
     expected_start_date = self.days_ago(2)
     expected_end_date = expected_start_date - datetime.timedelta(days=1)
     get_rating_changes(date=expected_start_date)
     eq_(len(responses.calls), 1)
     eq_(responses.calls[0].request.headers.get('StorePassword'),
         settings.IARC_V2_STORE_PASSWORD)
     eq_(responses.calls[0].request.headers.get('StoreID'),
         settings.IARC_V2_STORE_ID)
     eq_(json.loads(responses.calls[0].request.body), {
         'StartDate': expected_start_date.strftime('%Y-%m-%d'),
         'EndDate': expected_end_date.strftime('%Y-%m-%d'),
         'MaxRows': 500,
         'StartRowIndex': 0
     })
Exemplo n.º 6
0
    def test_with_existing_cert_valid(self):
        # Set up. app1 has no rating descriptors, app2 has one.
        data = setup_mock_response('GetRatingChanges')
        cert_id_1 = data['CertList'][0]['CertID']
        cert_id_2 = data['CertList'][1]['CertID']
        app1 = app_factory()
        app2 = app_factory()
        IARCCert.objects.create(app=app1, cert_id=UUID(cert_id_1))
        IARCCert.objects.create(app=app2, cert_id=UUID(cert_id_2))
        eq_(RatingDescriptors.objects.filter(addon=app1).count(), 0)
        RatingDescriptors.objects.create(addon=app2, has_esrb_lang=True)
        eq_(app2.rating_descriptors.to_keys(), ['has_esrb_lang'])
        expected_end_date = datetime.datetime.utcnow()
        expected_start_date = expected_end_date - datetime.timedelta(days=1)

        # GetRatingChanges Call.
        res = get_rating_changes()

        # Check that we called IARC as expected.
        eq_(len(responses.calls), 1)
        eq_(responses.calls[0].request.headers.get('StorePassword'),
            settings.IARC_V2_STORE_PASSWORD)
        eq_(responses.calls[0].request.headers.get('StoreID'),
            settings.IARC_V2_STORE_ID)
        eq_(
            json.loads(responses.calls[0].request.body), {
                'StartDate': expected_start_date.strftime('%Y-%m-%d'),
                'EndDate': expected_end_date.strftime('%Y-%m-%d'),
                'MaxRows': 500,
                'StartRowIndex': 0
            })
        eq_(res['Result']['ResponseCode'], 'Success')

        # Check that Cert IDs are still correct.
        eq_(UUID(app1.iarc_cert.cert_id), UUID(cert_id_1))
        eq_(UUID(app2.iarc_cert.cert_id), UUID(cert_id_2))

        # Compare with mock data. Force reload using .objects.get in order to
        # properly reset the related objects caching. App1 should have gained
        # a descriptor, and app2 should have lost its original descriptor and
        # gained a few.
        app1 = Webapp.objects.get(pk=app1.pk)
        app2 = Webapp.objects.get(pk=app2.pk)
        eq_(app1.rating_descriptors.to_keys(), ['has_esrb_violence_ref'])
        self.assertSetEqual(app2.rating_descriptors.to_keys(), [
            'has_classind_violence', 'has_generic_moderate_violence',
            'has_pegi_moderate_violence', 'has_esrb_violence',
            'has_usk_violence'
        ])
        eq_(app1.content_ratings.all()[0].get_rating_class(), ESRB_10)
        eq_(app2.content_ratings.all()[0].get_rating_class(), CLASSIND_12)
Exemplo n.º 7
0
    def test_with_existing_cert_valid(self):
        # Set up. app1 has no rating descriptors, app2 has one.
        data = setup_mock_response('GetRatingChanges')
        cert_id_1 = data['CertList'][0]['CertID']
        cert_id_2 = data['CertList'][1]['CertID']
        app1 = app_factory()
        app2 = app_factory()
        IARCCert.objects.create(app=app1, cert_id=UUID(cert_id_1))
        IARCCert.objects.create(app=app2, cert_id=UUID(cert_id_2))
        eq_(RatingDescriptors.objects.filter(addon=app1).count(), 0)
        RatingDescriptors.objects.create(addon=app2, has_esrb_lang=True)
        eq_(app2.rating_descriptors.to_keys(), ['has_esrb_lang'])
        expected_end_date = datetime.datetime.utcnow()
        expected_start_date = expected_end_date - datetime.timedelta(days=1)

        # GetRatingChanges Call.
        res = get_rating_changes()

        # Check that we called IARC as expected.
        eq_(len(responses.calls), 1)
        eq_(responses.calls[0].request.headers.get('StorePassword'),
            settings.IARC_V2_STORE_PASSWORD)
        eq_(responses.calls[0].request.headers.get('StoreID'),
            settings.IARC_V2_STORE_ID)
        eq_(json.loads(responses.calls[0].request.body), {
            'StartDate': expected_start_date.strftime('%Y-%m-%d'),
            'EndDate': expected_end_date.strftime('%Y-%m-%d'),
            'MaxRows': 500,
            'StartRowIndex': 0
        })
        eq_(res['Result']['ResponseCode'], 'Success')

        # Check that Cert IDs are still correct.
        eq_(UUID(app1.iarc_cert.cert_id), UUID(cert_id_1))
        eq_(UUID(app2.iarc_cert.cert_id), UUID(cert_id_2))

        # Compare with mock data. Force reload using .objects.get in order to
        # properly reset the related objects caching. App1 should have gained
        # a descriptor, and app2 should have lost its original descriptor and
        # gained a few.
        app1 = Webapp.objects.get(pk=app1.pk)
        app2 = Webapp.objects.get(pk=app2.pk)
        eq_(app1.rating_descriptors.to_keys(), ['has_esrb_violence_ref'])
        self.assertSetEqual(
            app2.rating_descriptors.to_keys(),
            ['has_classind_violence', 'has_generic_moderate_violence',
             'has_pegi_moderate_violence', 'has_esrb_violence',
             'has_usk_violence'])
        eq_(app1.content_ratings.all()[0].get_rating_class(), ESRB_10)
        eq_(app2.content_ratings.all()[0].get_rating_class(), CLASSIND_12)
Exemplo n.º 8
0
    def test_with_existing_cert_valid(self):
        data = setup_mock_response('GetRatingChanges')
        cert_id_1 = data['CertList'][0]['CertID']
        cert_id_2 = data['CertList'][1]['CertID']
        app1 = app_factory()
        app2 = app_factory()
        IARCCert.objects.create(app=app1, cert_id=UUID(cert_id_1))
        IARCCert.objects.create(app=app2, cert_id=UUID(cert_id_2))
        eq_(RatingDescriptors.objects.filter(addon=app1).count(), 0)
        RatingDescriptors.objects.create(addon=app2, has_esrb_lang=True)
        eq_(app2.rating_descriptors.to_keys(), ['has_esrb_lang'])
        expected_start_date = datetime.datetime.utcnow()
        expected_end_date = expected_start_date - datetime.timedelta(days=1)

        res = get_rating_changes()

        eq_(len(responses.calls), 1)
        eq_(responses.calls[0].request.url,
            urljoin(settings.IARC_V2_SERVICE_ENDPOINT, 'GetRatingChanges'))
        eq_(
            json.loads(responses.calls[0].request.body), {
                'StartDate': expected_start_date.strftime('%Y-%m-%d'),
                'EndDate': expected_end_date.strftime('%Y-%m-%d'),
                'MaxRows': 500,
                'StartRowIndex': 0
            })

        eq_(UUID(app1.iarc_cert.cert_id), UUID(cert_id_1))
        eq_(UUID(app2.iarc_cert.cert_id), UUID(cert_id_2))

        # Compare with mock data. Force reload using .objects.get in order to
        # properly reset the related objects caching.
        app1 = Webapp.objects.get(pk=app1.pk)
        app2 = Webapp.objects.get(pk=app2.pk)
        eq_(app1.rating_descriptors.to_keys(), ['has_esrb_violence_ref'])
        eq_(app2.rating_descriptors.to_keys(),
            ['has_classind_violence', 'has_esrb_violence', 'has_usk_violence'])
        eq_(res['Result']['ResponseCode'], 'Success')
        eq_(app1.content_ratings.all()[0].get_rating_class(), ESRB_10)
        eq_(app2.content_ratings.all()[0].get_rating_class(), CLASSIND_12)
Exemplo n.º 9
0
    def test_with_existing_cert_valid(self):
        data = setup_mock_response('GetRatingChanges')
        cert_id_1 = data['CertList'][0]['CertID']
        cert_id_2 = data['CertList'][1]['CertID']
        app1 = app_factory()
        app2 = app_factory()
        IARCCert.objects.create(app=app1, cert_id=UUID(cert_id_1))
        IARCCert.objects.create(app=app2, cert_id=UUID(cert_id_2))
        eq_(RatingDescriptors.objects.filter(addon=app1).count(), 0)
        RatingDescriptors.objects.create(addon=app2, has_esrb_lang=True)
        eq_(app2.rating_descriptors.to_keys(), ['has_esrb_lang'])
        expected_start_date = datetime.datetime.utcnow()
        expected_end_date = expected_start_date - datetime.timedelta(days=1)

        res = get_rating_changes()

        eq_(len(responses.calls), 1)
        eq_(responses.calls[0].request.url,
            urljoin(settings.IARC_V2_SERVICE_ENDPOINT, 'GetRatingChanges'))
        eq_(json.loads(responses.calls[0].request.body), {
            'StartDate': expected_start_date.strftime('%Y-%m-%d'),
            'EndDate': expected_end_date.strftime('%Y-%m-%d'),
            'MaxRows': 500,
            'StartRowIndex': 0
        })

        eq_(UUID(app1.iarc_cert.cert_id), UUID(cert_id_1))
        eq_(UUID(app2.iarc_cert.cert_id), UUID(cert_id_2))

        # Compare with mock data. Force reload using .objects.get in order to
        # properly reset the related objects caching.
        app1 = Webapp.objects.get(pk=app1.pk)
        app2 = Webapp.objects.get(pk=app2.pk)
        eq_(app1.rating_descriptors.to_keys(), ['has_esrb_violence_ref'])
        eq_(app2.rating_descriptors.to_keys(),
            ['has_classind_violence', 'has_esrb_violence', 'has_usk_violence'])
        eq_(res['Result']['ResponseCode'], 'Success')
        eq_(app1.content_ratings.all()[0].get_rating_class(), ESRB_10)
        eq_(app2.content_ratings.all()[0].get_rating_class(), CLASSIND_12)
Exemplo n.º 10
0
 def test_no_existing_certs_doesnt_raise_an_error(self):
     setup_mock_response('GetRatingChanges')
     res = get_rating_changes()
     eq_(res['Result']['ResponseCode'], 'Success')
Exemplo n.º 11
0
 def test_no_existing_certs_doesnt_raise_an_error(self):
     setup_mock_response('GetRatingChanges')
     res = get_rating_changes()
     eq_(res['Result']['ResponseCode'], 'Success')