Skip to content
Permalink
Browse files

added a RANDOM_SEED as env-level seed for the data faker (#2541)

* added a RANDOM_SEED as env-level seed for the data faker
* doc update to mention said var
* updated news faker to tap into settings.RANDOM_SEED
* random seed added to travis, removed --seed in script section
* bypass random seed during 'manage test'
* make percy/cypress a peerdepencency and only install during travis run
  • Loading branch information...
Pomax committed Jan 30, 2019
1 parent 40a5408 commit 4903cb8d19024d1337722b910982f334254e80ae
@@ -11,6 +11,8 @@ install:
- nvm use --lts=carbon
- npm install -g npm@latest # Needed to use npm ci
- npm ci # use package-lock.json
- npm i cypress@3.1.4 # version also noted in package.json -> peerDependencies
- npm i @percy/cypress@0.2.3 # version also noted in package.json -> peerDependencies
- pipenv run python network-api/manage.py collectstatic --no-input
before_script:
- psql -c 'create database network;' -U postgres
@@ -19,29 +21,30 @@ script:
- npm test
- pipenv run flake8 tasks.py network-api/
- pipenv run coverage run --source './network-api/networkapi' network-api/manage.py test networkapi
- pipenv run python network-api/manage.py load_fake_data --seed 1
- pipenv run python network-api/manage.py load_fake_data
- npm run percy
after_success:
- coveralls
env:
global:
- ALLOWED_HOSTS=localhost
- CONTENT_TYPE_NO_SNIFF=True
- CORS_WHITELIST="*"
- DATABASE_URL=postgres://postgres@localhost:5432/network
- DEBUG=True
- DJANGO_SECRET_KEY=secret
- DATABASE_URL=postgres://postgres@localhost:5432/network
- USE_S3=False
- CORS_WHITELIST="*"
- XSS_PROTECTION=True
- CONTENT_TYPE_NO_SNIFF=True
- SET_HSTS=False
- SSL_REDIRECT=False
- X_FRAME_OPTIONS=DENY
- ALLOWED_HOSTS=localhost
- NETWORK_SITE_URL=https://foundation.mozilla.org
- PULSE_API_DOMAIN=https://network-pulse-api-production.herokuapp.com
- PULSE_DOMAIN=www.mozillapulse.org
- NETWORK_SITE_URL=https://foundation.mozilla.org
- TARGET_DOMAIN=foundation.mozilla.org
- RANDOM_SEED=530910203
- SET_HSTS=False
- SHOW_TAKEOVER=false
- SSL_REDIRECT=False
- TARGET_DOMAIN=foundation.mozilla.org
- USE_CLOUDINARY=false
- USE_S3=False
- X_FRAME_OPTIONS=DENY
- XSS_PROTECTION=True
matrix:
secure: mC4GYW8PC98k8BDqNoQDBAWkM90sRbe8yHfEhelL5YkvZC3ORZR8cbqzkAieShWf3upOc+xFMD3m8bsLvJGisg/CHm+j4f5d0shz0Sv5YG7Ru95TW4Hj/0H9QTlHG4OZ12hZ6ZD9k7xQdPL9CkKVordIQMH883UYdao9Tl5Y9i01uPpdAH/1mF6xpNHbVC6LjUv2zstoXqFCyABXaK2U3FqdymVhT1e99GlgVGteYTzsVEdv9AbhOaXH1U+0NLFOBhFVm1ub7zIZBrWgdZKStOiOlXdb14/oLw0criiOAULKBbN7WoKE3ZZTO5BR89+ZkOt7bH8gt9QCOTQ2JrhF00pIM7BoYxoWq6fLqsLdN0tJQ27QDlmH8PwOrJ6AqPKCj6wGBAjuNtLLu3QpsTeT0gJYGip3/aB9ktUFEPpGWjw7JMSvYGNvMAl+0tTiSL3sqxeyyBKvqQ8WH4bGtNRBDfrAmrxAcX4hCZCKgxsB9WiTSFnXdCb6axgmew1V3uMGUeQHcKaM7C8K2hrxnvUF/yeGuwJAgtFha9dn0AuG4ZarcEHmuVA6Wg+QAX1Niz885WecZuMlyguyuFGX3Bmz/Aa9jIvcTD+WOHiw3f6nNEoxJe3hkKKv5Sguq4j2gMoK/0fQ3AcnU4EYdUVoMJ/RgWN5ROowA+AwMy7GMTqOV+8=
cache:
@@ -77,6 +77,8 @@ You can generate a specific set of fake model data by entering a seed value

- `pipenv run python network-api/manage.py --delete --seed VALUE`

Alternatively, the seed value can be specified through the use of the `RANDOM_SEED` environment variable.

If a seed is not provided, a pseudorandom one will be generated and logged to the console. You can share this value with others if you need them to generate the same set of data that you have.

#### Landing Page and Campaign links
@@ -1,3 +1,4 @@
{
"baseUrl": "http://localhost:8000"
"baseUrl": "http://localhost:8000",
"video": false
}
@@ -110,6 +110,8 @@ def handle(self, *args, **options):
# Seed Faker with the provided seed value or a pseudorandom int between 0 and five million
if options['seed']:
seed = options['seed']
elif settings.RANDOM_SEED is not None:
seed = settings.RANDOM_SEED
else:
seed = randint(0, 5000000)

@@ -11,6 +11,11 @@
from networkapi.utility.faker import ImageProvider
from networkapi.news.models import News

from django.conf import settings

RANDOM_SEED = settings.RANDOM_SEED
TESTING = settings.TESTING

Faker.add_provider(ImageProvider)


@@ -27,25 +32,29 @@ class Params:
featured=True
)
unpublished = Trait(
publish_after=Faker('future_datetime', end_date='+30d', tzinfo=timezone.utc)
publish_after=Faker('date_time', tzinfo=timezone.utc) if RANDOM_SEED and not TESTING
else Faker('future_datetime', end_date='+30d', tzinfo=timezone.utc)
)
has_expiry = Trait(
expires=Faker('future_datetime', end_date='+30d', tzinfo=timezone.utc)
expires=Faker('date_time', tzinfo=timezone.utc) if RANDOM_SEED and not TESTING
else Faker('future_datetime', end_date='+30d', tzinfo=timezone.utc)
)
expired = Trait(
expires=Faker('past_datetime', start_date='-30d', tzinfo=timezone.utc)
expires=Faker('date_time', tzinfo=timezone.utc) if RANDOM_SEED and not TESTING
else Faker('past_datetime', start_date='-30d', tzinfo=timezone.utc)
)
video = Trait(
is_video=True
)

headline = LazyAttribute(lambda o: o.headline_sentence.rstrip('.'))
outlet = Faker('company')
date = Faker('past_date', start_date='-30d')
date = Faker('date') if RANDOM_SEED and not TESTING else Faker('past_date', start_date='-30d')
link = Faker('url')
excerpt = Faker('paragraph', nb_sentences=3, variable_nb_sentences=True)
author = Faker('name')
publish_after = Faker('past_datetime', start_date='-30d', tzinfo=timezone.utc)
publish_after = (Faker('date_time', tzinfo=timezone.utc) if RANDOM_SEED and not TESTING
else Faker('past_datetime', start_date='-30d', tzinfo=timezone.utc))

# LazyAttribute helper value
headline_sentence = Faker('sentence', nb_words=4)
@@ -47,6 +47,7 @@
DOMAIN_REDIRECT_MIDDLWARE_ENABLED=(bool, False),
FILEBROWSER_DEBUG=(bool, False),
FILEBROWSER_DIRECTORY=(str, ''),
RANDOM_SEED=(int, None),
HEROKU_APP_NAME=(str, ''),
NETWORK_SITE_URL=(str, ''),
PETITION_TEST_CAMPAIGN_ID=(str, ''),
@@ -313,6 +314,7 @@

DATABASES['default']['ATOMIC_REQUESTS'] = True

RANDOM_SEED = env('RANDOM_SEED')

# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
@@ -538,10 +540,9 @@
# Buyers Guide Rate Limit Setting
BUYERS_GUIDE_VOTE_RATE_LIMIT = env('BUYERS_GUIDE_VOTE_RATE_LIMIT')

# Detect if we're testing
# Detect if we're in official testing mode
TESTING = 'test' in sys.argv


# Coral Talk Server URL

CORAL_TALK_SERVER_URL = env('CORAL_TALK_SERVER_URL')

0 comments on commit 4903cb8

Please sign in to comment.
You can’t perform that action at this time.