Пример #1
0
    def test_process_deletes(self):
        """
        Test the process_deletes bits.
        """

        # Test process_changes()
        utils.load_test_playgrounds()

        deleted_playgrounds, revision_group = data.process_changes('tests/data/test_deletes.json')

        self.assertEqual(len(deleted_playgrounds), 0)

        # Test process_delete() itself.
        with open('tests/data/test_deletes.json', 'r') as jsonfile:
            test_deletes = json.loads(jsonfile.read())

        playground, revisions = data.process_delete(test_deletes[0])

        expected_id = 1
        expected_revisions = [
            {"field": "active", "from": True, "to": False},
            {"field": "reason", "from": "", "to": "This playground doesn't appear to be accessible in any way whatsoever."}
        ]

        self.assertEqual(playground.id, expected_id)
        self.assertEqual(revisions, expected_revisions)
Пример #2
0
    def test_process_updates_simple(self):
        utils.load_test_playgrounds()

        updated_playgrounds, revision_group = data.process_changes('tests/data/test_updates_simple.json')

        self.assertEqual(len(updated_playgrounds), 1)

        playground = Playground.select().where(Playground.id == updated_playgrounds[0].id)[0]
        self.assertEqual(playground.id, 1)
        self.assertEqual(playground.name, 'NEW NAME')

        revisions = Revision.select().where(Revision.revision_group == revision_group)

        self.assertEqual(revisions.count(), 1)

        revision = revisions[0]
        self.assertEqual(revision.playground.id, playground.id)

        log = revision.get_log()
        self.assertEqual(len(log), 2)
        self.assertEqual(log[0]['field'], 'name')
        self.assertEqual(log[0]['from'], 'Strong Reach Playground')
        self.assertEqual(log[0]['to'], 'NEW NAME')
        self.assertEqual(log[1]['field'], 'smooth-surface-throughout')
        self.assertEqual(log[1]['from'], 1)
        self.assertEqual(log[1]['to'], 0)

        headers = revision.get_headers()
        self.assertEqual(headers['content_length'], '18')
        self.assertEqual(headers['host'], 'localhost')

        cookies = revision.get_cookies()
        self.assertEqual(len(cookies), 0)
Пример #3
0
    def test_remove_from_search_index(self):
        app_config.configure_targets('staging')

        utils.load_test_playgrounds()

        playground = Playground.select()[0]

        sdf = playground.sdf()
        sdf['id'] = 'test_%i' % playground.id
        sdf['fields']['name'] = 'THIS IS NOT A PLAYGROUND NAME axerqwak'
        sdf['fields']['deployment_target'] = 'test'

        response = requests.post('http://%s/2011-02-01/documents/batch' % app_config.CLOUD_SEARCH_DOC_DOMAIN, data=json.dumps([sdf]), headers={ 'Content-Type': 'application/json' })

        self.assertEqual(response.status_code, 200)

        # Monkey patch delete_sdf to so it return test id
        delete_sdf = playground.delete_sdf()
        delete_sdf['id'] = 'test_%i' % playground.id
        delete_sdf['version'] = sdf['version'] + 1

        old_func = playground.delete_sdf
        playground.delete_sdf = lambda: delete_sdf

        playground.remove_from_search_index()

        playground.delete_sdf = old_func

        response = requests.get('http://%s/2011-02-01/search' % app_config.CLOUD_SEARCH_DOMAIN, params={ 'q': 'axerqwak' }, headers={ 'Cache-Control': 'revalidate' })

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json()['hits']['found'], 0)

        app_config.configure_targets(None)
Пример #4
0
    def test_update_two_playgrounds(self):
        utils.load_test_playgrounds()

        response = self.client.post(url_for('update_playground'), data={
            'id': 1,
            'name': 'NEW NAME'
        })

        self.assertEqual(response.status_code, 302)

        redirect_url = '%s/playground/%s.html' % (app_config.S3_BASE_URL, Playground.get(id=1).slug)
        self.assertEqual(response.headers['Location'].split('?')[0], redirect_url)

        response = self.client.post(url_for('update_playground'), data={
            'id': 2,
            'name': 'ANOTHER NEW NAME'
        })

        self.assertEqual(response.status_code, 302)

        redirect_url = '%s/playground/%s.html' % (app_config.S3_BASE_URL, Playground.get(id=2).slug)
        self.assertEqual(response.headers['Location'].split('?')[0], redirect_url)

        with open('data/changes.json') as f:
            updates = json.load(f)

        self.assertEqual(len(updates), 2)
        self.assertEqual(updates[0]['action'], 'update')
        self.assertEqual(updates[0]['playground']['id'], 1)
        self.assertEqual(updates[0]['playground']['name'], 'NEW NAME')
        self.assertEqual(updates[1]['action'], 'update')
        self.assertEqual(updates[1]['playground']['id'], 2)
        self.assertEqual(updates[1]['playground']['name'], 'ANOTHER NEW NAME')
Пример #5
0
    def test_process_deletes(self):
        """
        Test the process_deletes bits.
        """

        # Test process_changes()
        utils.load_test_playgrounds()

        deleted_playgrounds, revision_group = data.process_changes(
            'tests/data/test_deletes.json')

        self.assertEqual(len(deleted_playgrounds), 0)

        # Test process_delete() itself.
        with open('tests/data/test_deletes.json', 'r') as jsonfile:
            test_deletes = json.loads(jsonfile.read())

        playground, revisions = data.process_delete(test_deletes[0])

        expected_id = 1
        expected_revisions = [{
            "field": "active",
            "from": True,
            "to": False
        }, {
            "field":
            "reason",
            "from":
            "",
            "to":
            "This playground doesn't appear to be accessible in any way whatsoever."
        }]

        self.assertEqual(playground.id, expected_id)
        self.assertEqual(revisions, expected_revisions)
Пример #6
0
    def test_playground_exists(self):
        utils.load_test_playgrounds()

        playground = Playground.get(id=1)

        response = self.client.get(url_for("_playground", playground_slug=playground.slug))

        assert playground.display_name in response.data
Пример #7
0
    def test_playground_exists(self):
        utils.load_test_playgrounds()

        playground = Playground.get(id=1)

        response = self.client.get(
            url_for('_playground', playground_slug=playground.slug))

        assert playground.display_name in response.data
Пример #8
0
    def test_process_update_only_one(self):
        utils.load_test_playgrounds()

        updated_playgrounds, revision_group = data.process_changes('tests/data/test_updates_simple.json')

        self.assertEqual(len(updated_playgrounds), 1)

        playground = Playground.select().where(Playground.id != updated_playgrounds[0].id)[0]
        self.assertNotEqual(playground.id, 1)
        self.assertNotEqual(playground.name, 'NEW NAME')
Пример #9
0
    def test_delete_playground(self):
        utils.load_test_playgrounds()

        response = self.client.post(url_for('delete_playground'), data={
            "slug": "strong-reach-playground-bowdon-ga",
            "text": "TEST TEXT FOR REASONING."
        })

        self.assertEqual(response.status_code, 302)
        redirect_url = '%s/playground/%s.html?action=deleting_thanks' % (app_config.S3_BASE_URL, "strong-reach-playground-bowdon-ga")
        self.assertEqual(response.headers['location'], redirect_url)
Пример #10
0
    def test_process_update_only_one(self):
        utils.load_test_playgrounds()

        updated_playgrounds, revision_group = data.process_changes(
            'tests/data/test_updates_simple.json')

        self.assertEqual(len(updated_playgrounds), 1)

        playground = Playground.select().where(
            Playground.id != updated_playgrounds[0].id)[0]
        self.assertNotEqual(playground.id, 1)
        self.assertNotEqual(playground.name, 'NEW NAME')
Пример #11
0
    def test_delete_playground(self):
        utils.load_test_playgrounds()

        response = self.client.post(url_for('delete_playground'),
                                    data={
                                        "slug":
                                        "strong-reach-playground-bowdon-ga",
                                        "text": "TEST TEXT FOR REASONING."
                                    })

        self.assertEqual(response.status_code, 302)
        redirect_url = '%s/playground/%s.html?action=deleting_thanks' % (
            app_config.S3_BASE_URL, "strong-reach-playground-bowdon-ga")
        self.assertEqual(response.headers['location'], redirect_url)
Пример #12
0
    def test_load_playgrounds(self):
        with open('tests/data/test_playgrounds.csv') as f:
            reader = CSVKitDictReader(f)
            rows = list(reader)

        non_duplicate = filter(lambda r: r['Duplicate'] != 'TRUE', rows)

        utils.load_test_playgrounds()

        playgrounds = Playground.select()

        self.assertEqual(len(non_duplicate), playgrounds.count())

        features = PlaygroundFeature.select()

        self.assertEqual(features.count(), 2)
Пример #13
0
    def test_load_playgrounds(self):
        with open('tests/data/test_playgrounds.csv') as f:
            reader = CSVKitDictReader(f)
            rows = list(reader)

        non_duplicate = filter(lambda r: r['Duplicate'] != 'TRUE', rows)

        utils.load_test_playgrounds()

        playgrounds = Playground.select()

        self.assertEqual(len(non_duplicate), playgrounds.count())

        features = PlaygroundFeature.select()

        self.assertEqual(features.count(), 2)
Пример #14
0
    def test_process_updates_features(self):
        utils.load_test_playgrounds()

        PlaygroundFeature.create(
            slug='transfer-stations-to-play-components',
            playground=Playground.get(id=1)
        )

        # JSON adds one feature and removes the one just created
        updated_playgrounds, revision_group = data.process_changes('tests/data/test_updates_features.json')

        features = PlaygroundFeature.select().where(PlaygroundFeature.playground == 1)

        self.assertEqual(features.count(), 1)

        feature = features[0]
        self.assertEqual(feature.slug, 'smooth-surface-throughout')
Пример #15
0
    def test_process_updates_features(self):
        utils.load_test_playgrounds()

        PlaygroundFeature.create(slug='transfer-stations-to-play-components',
                                 playground=Playground.get(id=1))

        # JSON adds one feature and removes the one just created
        updated_playgrounds, revision_group = data.process_changes(
            'tests/data/test_updates_features.json')

        features = PlaygroundFeature.select().where(
            PlaygroundFeature.playground == 1)

        self.assertEqual(features.count(), 1)

        feature = features[0]
        self.assertEqual(feature.slug, 'smooth-surface-throughout')
Пример #16
0
    def test_delete_playground_confirm(self):
        utils.load_test_playgrounds()

        app_config.configure_targets('staging')

        s3 = boto.connect_s3()
        bucket = s3.get_bucket(app_config.S3_BUCKETS[0])
        k = Key(bucket)
        k.key = '%s/playground/%s.html' % (app_config.PROJECT_SLUG, Playground.get(id=1).slug)
        k.set_contents_from_string('foo')

        response = self.client.get(url_for('delete_playground_confirm', playground_slug=Playground.get(id=1).slug))

        self.assertEqual(response.status_code, 200)
        self.assertFalse(Playground.get(id=1).active)

        self.assertIsNone(bucket.get_key(k.key))
        app_config.configure_targets(None)
Пример #17
0
    def test_delete_playground_confirm(self):
        utils.load_test_playgrounds()

        app_config.configure_targets('staging')

        s3 = boto.connect_s3()
        bucket = s3.get_bucket(app_config.S3_BUCKETS[0])
        k = Key(bucket)
        k.key = '%s/playground/%s.html' % (app_config.PROJECT_SLUG,
                                           Playground.get(id=1).slug)
        k.set_contents_from_string('foo')

        response = self.client.get(
            url_for('delete_playground_confirm',
                    playground_slug=Playground.get(id=1).slug))

        self.assertEqual(response.status_code, 200)
        self.assertFalse(Playground.get(id=1).active)

        self.assertIsNone(bucket.get_key(k.key))
        app_config.configure_targets(None)
Пример #18
0
    def test_remove_from_search_index(self):
        app_config.configure_targets('staging')

        utils.load_test_playgrounds()

        playground = Playground.select()[0]

        sdf = playground.sdf()
        sdf['id'] = 'test_%i' % playground.id
        sdf['fields']['name'] = 'THIS IS NOT A PLAYGROUND NAME axerqwak'
        sdf['fields']['deployment_target'] = 'test'

        response = requests.post('http://%s/2011-02-01/documents/batch' %
                                 app_config.CLOUD_SEARCH_DOC_DOMAIN,
                                 data=json.dumps([sdf]),
                                 headers={'Content-Type': 'application/json'})

        self.assertEqual(response.status_code, 200)

        # Monkey patch delete_sdf to so it return test id
        delete_sdf = playground.delete_sdf()
        delete_sdf['id'] = 'test_%i' % playground.id
        delete_sdf['version'] = sdf['version'] + 1

        old_func = playground.delete_sdf
        playground.delete_sdf = lambda: delete_sdf

        playground.remove_from_search_index()

        playground.delete_sdf = old_func

        response = requests.get('http://%s/2011-02-01/search' %
                                app_config.CLOUD_SEARCH_DOMAIN,
                                params={'q': 'axerqwak'},
                                headers={'Cache-Control': 'revalidate'})

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json()['hits']['found'], 0)

        app_config.configure_targets(None)
Пример #19
0
    def test_update_two_playgrounds(self):
        utils.load_test_playgrounds()

        response = self.client.post(url_for('update_playground'),
                                    data={
                                        'id': 1,
                                        'name': 'NEW NAME'
                                    })

        self.assertEqual(response.status_code, 302)

        redirect_url = '%s/playground/%s.html' % (app_config.S3_BASE_URL,
                                                  Playground.get(id=1).slug)
        self.assertEqual(response.headers['Location'].split('?')[0],
                         redirect_url)

        response = self.client.post(url_for('update_playground'),
                                    data={
                                        'id': 2,
                                        'name': 'ANOTHER NEW NAME'
                                    })

        self.assertEqual(response.status_code, 302)

        redirect_url = '%s/playground/%s.html' % (app_config.S3_BASE_URL,
                                                  Playground.get(id=2).slug)
        self.assertEqual(response.headers['Location'].split('?')[0],
                         redirect_url)

        with open('data/changes.json') as f:
            updates = json.load(f)

        self.assertEqual(len(updates), 2)
        self.assertEqual(updates[0]['action'], 'update')
        self.assertEqual(updates[0]['playground']['id'], 1)
        self.assertEqual(updates[0]['playground']['name'], 'NEW NAME')
        self.assertEqual(updates[1]['action'], 'update')
        self.assertEqual(updates[1]['playground']['id'], 2)
        self.assertEqual(updates[1]['playground']['name'], 'ANOTHER NEW NAME')
Пример #20
0
    def test_prepare_email(self):
        utils.load_test_playgrounds()

        playground = Playground.get(id=1)

        log = '''[{
            "field": "name",
            "from": "%s",
            "to": "Test Playground"
        }]''' % playground.name

        Revision(action='update',
                 timestamp=time.mktime(
                     datetime.datetime.now(pytz.utc).timetuple()),
                 playground=playground,
                 log=log,
                 headers='',
                 cookies='',
                 revision_group=1).save()

        body = app._prepare_email(1)

        self.assertTrue(body.find(playground.name) >= 0)
Пример #21
0
    def test_prepare_email(self):
        utils.load_test_playgrounds()

        playground = Playground.get(id=1)

        log = '''[{
            "field": "name",
            "from": "%s",
            "to": "Test Playground"
        }]''' % playground.name

        Revision(
            action='update',
            timestamp=time.mktime(datetime.datetime.now(pytz.utc).timetuple()),
            playground=playground,
            log=log,
            headers='',
            cookies='',
            revision_group=1
        ).save()

        body = app._prepare_email(1)

        self.assertTrue(body.find(playground.name) >= 0)
Пример #22
0
    def test_process_updates_simple(self):
        utils.load_test_playgrounds()

        updated_playgrounds, revision_group = data.process_changes(
            'tests/data/test_updates_simple.json')

        self.assertEqual(len(updated_playgrounds), 1)

        playground = Playground.select().where(
            Playground.id == updated_playgrounds[0].id)[0]
        self.assertEqual(playground.id, 1)
        self.assertEqual(playground.name, 'NEW NAME')

        revisions = Revision.select().where(
            Revision.revision_group == revision_group)

        self.assertEqual(revisions.count(), 1)

        revision = revisions[0]
        self.assertEqual(revision.playground.id, playground.id)

        log = revision.get_log()
        self.assertEqual(len(log), 2)
        self.assertEqual(log[0]['field'], 'name')
        self.assertEqual(log[0]['from'], 'Strong Reach Playground')
        self.assertEqual(log[0]['to'], 'NEW NAME')
        self.assertEqual(log[1]['field'], 'smooth-surface-throughout')
        self.assertEqual(log[1]['from'], 1)
        self.assertEqual(log[1]['to'], 0)

        headers = revision.get_headers()
        self.assertEqual(headers['content_length'], '18')
        self.assertEqual(headers['host'], 'localhost')

        cookies = revision.get_cookies()
        self.assertEqual(len(cookies), 0)