Beispiel #1
0
def index():
    """
    Playgrounds index page.
    """
    context = make_context()
    metros = app_config.METRO_AREAS

    for metro in metros:
        metro['playground_count'] = Playground.select().where(Playground.zip_code << metro['zip_codes']).count()

    context['playground_count'] = intcomma(Playground.select().count())

    context['metros'] = metros

    return render_template('index.html', **context)
Beispiel #2
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)
Beispiel #3
0
    def test_process_inserts(self):
        models.delete_tables()
        models.create_tables()

        new_playgrounds, revision_group = data.process_changes('tests/data/test_inserts.json')

        self.assertEqual(len(new_playgrounds), 1)

        playground = Playground.select().where(Playground.id == new_playgrounds[0].id)[0]
        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), 1)
        self.assertEqual(log[0]['field'], 'name')
        self.assertEqual(log[0]['from'], '')
        self.assertEqual(log[0]['to'], 'NEW NAME')

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

        cookies = revision.get_cookies()
Beispiel #4
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)
Beispiel #5
0
    def test_process_inserts(self):
        models.delete_tables()
        models.create_tables()

        new_playgrounds, revision_group = data.process_changes(
            'tests/data/test_inserts.json')

        self.assertEqual(len(new_playgrounds), 1)

        playground = Playground.select().where(
            Playground.id == new_playgrounds[0].id)[0]
        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), 1)
        self.assertEqual(log[0]['field'], 'name')
        self.assertEqual(log[0]['from'], '')
        self.assertEqual(log[0]['to'], 'NEW NAME')

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

        cookies = revision.get_cookies()
Beispiel #6
0
def index():
    """
    Playgrounds index page.
    """
    context = make_context()
    metros = app_config.METRO_AREAS

    for metro in metros:
        metro['playground_count'] = Playground.select().where(
            Playground.zip_code << metro['zip_codes']).count()

    context['playground_count'] = intcomma(Playground.select().count())

    context['metros'] = metros

    return render_template('index.html', **context)
Beispiel #7
0
def index():
    """
    Playgrounds index page.
    """
    context = make_context()
    context['playground_count'] = intcomma(Playground.select().count())

    return render_template('index.html', **context)
Beispiel #8
0
def index():
    """
    Playgrounds index page.
    """
    context = make_context()
    context['playground_count'] = intcomma(Playground.select().count())

    return render_template('index.html', **context)
Beispiel #9
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')
Beispiel #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')
Beispiel #11
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)
Beispiel #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)
Beispiel #13
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)
Beispiel #14
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)
Beispiel #15
0
import app_config
from models import Playground

SEARCH_DISTANCE = 0.001

matched = set()

def print_playground(playground):
    print '%s: http://%s/%s/playground/%s' % (
        playground.name or 'unnamed',
        app_config.PRODUCTION_S3_BUCKETS[0],
        app_config.PROJECT_SLUG,
        playground.slug
    )

for playground in Playground.select():
    if playground.id in matched:
        continue

    lat = playground.latitude
    lng = playground.longitude

    if not lat or not lng:
        continue

    nearby = Playground.select().where(
        Playground.latitude.between(
            lat - SEARCH_DISTANCE, lat + SEARCH_DISTANCE
        ),
        Playground.longitude.between(
            lng - SEARCH_DISTANCE, lng + SEARCH_DISTANCE