Граф коммитов

45 Коммитов

Автор SHA1 Сообщение Дата
Mathieu Pillard 3f83f99131
Remove old update service (#20086)
* Remove old update service

* Remove more code/docs associated with services/

* Add some missing pytest.mark.django_db that the autouse fixture was hiding...

* Remove extra import

* Add a comment documenting what the update URL typically looks like
2022-12-12 12:45:11 +01:00
Andrew Williamson 6101446f3c
implement sitemap.xml with basic site and addon support (#16904)
* implement sitemap.xml with basic site and addon support

* rm commented out lines from development
2021-04-13 11:04:48 +01:00
Andrew Williamson 53666a687f
Dependabot/pip/requirements/sentry sdk 0.20.3 (#16672)
* Bump sentry-sdk from 0.19.5 to 0.20.3 in /requirements

Bumps [sentry-sdk](https://github.com/getsentry/sentry-python) from 0.19.5 to 0.20.3.
- [Release notes](https://github.com/getsentry/sentry-python/releases)
- [Changelog](https://github.com/getsentry/sentry-python/blob/master/CHANGELOG.md)
- [Commits](https://github.com/getsentry/sentry-python/compare/0.19.5...0.20.3)

Signed-off-by: dependabot[bot] <support@github.com>

* load urlresolvers before sentry_sdk

* fix tests now even login redirect views get /locale/ urls

* move our reverse to seperate file; change all refs to django.urls.reverse

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-03-04 10:58:25 +00:00
Andrew Williamson 11ee4e99cf
django32 tests ci (#16436)
* let our tests run with django3.2

* PositiveAutoField fixes

* versions/test_models.py test fix

* TransField fix

* cache fixes

* use django.utils.html.escape to workaround &# encoding changing to hex

* deactive failing jobs on circleci

* django 2.2.18
2021-02-03 19:01:02 +00:00
Mathieu Pillard 461f0695a7
Fix database encoding and exception handling in update service (#14851)
* Fix database encoding and exception handling in update service

* Remove leftover ipdb

* Cleaner way to override SERVICES_DATABASE in tests through pytest fixture

* Remove now unused imports
2020-07-07 13:23:13 +02:00
Mathieu Pillard ec0d8f9293
Upgrade to Elasticsearch 6.x (#14206)
* Upgrade to Elasticsearch 6.x

Because ES 6.x removed mapping types, move update_count and download_count in
separate ES indexes. This requires a full reindex, including stats, but we need
to create an entirely new cluster anyway.

ES 5.x compatibility is kept for now.
2020-05-28 20:47:07 +02:00
Andrew Williamson bc039ac584 move the actual mlbf upload to a celery task 2020-04-06 12:26:17 +01:00
Christopher Grebs 0bd4815d37
Upgrade Celery to 4.3 (#12073)
Upgrade Celery to 4.3.0

This PR upgrades to Celery 4.3, introduces a small hack because of a regression in celery.

This PR does not introduce any helpers to make use of celery workers inside the tests, we delayed that to a later point to unblock the upgrade.

This PR does fix some inconsistencies with elasticsearch mocks along the way as they were making some tests fail (see comment logs), the mocks are now applied and rolled back much less than before which makes them easier to reason about and to debug.

Notes:

 * acks_late now doesn't acknowledge in case of failures or timeouts (which is the case for index_addons). We could use task_acks_on_failure_or_timeout but I figured the new behavior should be fine.
 * any CELERY_ALWAYS_EAGER setting in local_settings.py must be replaced by CELERY_TASK_ALWAYS_EAGER

commit log:

* Implement proper wait_for_tasks helper, make TestTaskQueued work with celery worker
* Revert changes removing threading code from es reindex tests
* Fix es reindex test, correct always eager usage.
* Small cleanups, fix docs, don't reload session worker.
* Ensure docker-compose celery result doesn't use the same database as any potential tests
* Monkeypatch for celery regression
* Actually use our own app where all tasks are already bound to. This also enables logging
* Experiment: Group celery worker tests together with elasticsearch and dont run them multitasked
* Remove envlist as it doesn't add anything to our specific setup
* Fix es-and-celery marker selection
* Remove completely redundant tests
* Fix hanging tasks, let's see what travis thinks... I'll follow up with cleanups and much more docs once tests are actually succeeding
* Define celery.ping in amo.celery, use redis result backend
* Cleanup celery worker implementation a bit.

Mimic our usage of elasticsearch specific tests, this avoids various
necessary workarounds and environment cleanups because django handles
things like settings properly in the first place.

* Untangle es mocks a bit, raise error in case of not properly stopped patches.
* Re-implement state test by using celery manager to wait for results
* Explicitly re-reinitialize the workers event loop and dont reuse anything existing
* Remove celery worker thread specific code.
* Reset default celery result backend setting
2019-09-18 17:36:01 +02:00
Christopher Grebs 2de22598bd
Remove all usage of 'six' and as much compat code as I could f… (#11730)
* Remove all usage of 'six' and as much compat code as I could find.

Cleans up some imports along the way.

Fixes #11728

* Fix typo

* Fix rta related code paths, I actually misread the comment…

* Move ResourceWarning filtering to setup.cfg
2019-07-16 12:01:31 +02:00
Mathieu Pillard 467b2d9235 Python 3 fixes for the `es` job (#10483)
Fixes #10420

* Python fixes for the 'es' job
* Remove some legacy api 1.2 cruft, test legacy_api with 1.5 by default
At this point clients using the legacy api are old, clients using the
legacy api < 1.5 are *super* old and not worth supporting.
* Dynamically ignore ResourceWarning under Python 3 for now
* Make stats csv column ordering stable
* Move 'es' job to the python3working section
2019-01-23 06:01:09 +01:00
Mathieu Pillard 8600391190 Merge remote-tracking branch 'upstream/master' into py3-fix-assets-job 2019-01-16 14:51:38 +01:00
Christopher Grebs 9e8468f8cd
Replace pytest-responses with our own custom implementation. (#10410)
Fixes #10399

Closes #10378
Closes #10317

This also updates pytest to 4.1.1
2019-01-16 12:26:45 +01:00
Mathieu Pillard ff5071b4d1 Python 3 fixes to unblock some of the test jobs
Notably, this should fix all the tests in the 'assets' job.
2019-01-16 12:09:35 +01:00
Mathieu Pillard da7093b126 Convert some uses of str() to six.string_types or bytes for Python 3 compat 2019-01-08 13:40:51 +01:00
Christopher Grebs 2c82ea7728
Enable memcached by default for tests. Upgrade python-memcached
* Adds a test to test unicode support for latest python-memcached
  versions
* Configures caches key prefix so that tests don't conflict with each other
* Remove a few cache.clear calls with `cache.delete` calls that avoids
deleting all memcached entries while other tests are running
* Remove zadmin.memcached as it's crazy dangerous, such power should
only be wielded by ops-folks who wake up at night when pressed
* Fixes waffle helpers to call .flush() to flush appropriate caches

This also fixes how parameters are forwarded to memcached and fix KEY_PREFIX initialization

We are now making sure parameters from `settings.CACHES` are properly forwarded
to the actual cache backend (now memcached). These errors were not seen
since LocMemCache didn't require any parameters.

The `KEY_PREFIX` setting is set to a uuid instead of the xdist-slaveid to
ensure test functions are properly isolated from each other.

`cache.clear` is not called anywhere unless absolutely necessary to reduce
the side-effects of our test-setup.

Fixes #8602
2018-11-21 18:26:30 +01:00
Christopher Grebs fa73e5a953
Unify storage path related settings. (#9655)
* Unify storage path related settings.

* Moves all storage related settings to settings_base
* Keeps ability to overload base path by setting `NETAPP_STORAGE_ROOT`
* Removes unused PACKAGER_PATH

Fixes #9654

* Sort settings, rename according to their actual path settings
* explicitly set all paths in conftest and document it's usage
* Remove reviewer_attachments folder reference
2018-10-15 17:30:02 +02:00
Christopher Grebs c4912208a3
Implement git repository management helpers. (#9584)
Fixes #8751

* Add new GIT_FILE_STORAGE_PATH setting
* refactor existing path settings to use os.path.join along the way
* SafeZip validates by default now, `.is_valid` is now a property and
  not a method anymore
* Implement new `force_fsync` option to `SafeZip` to force a fsync call
that may be needed for files we require to be absolutely available after
extraction (because we're going to commit them to git)
* Remove nested zip expansion as it's not needed anymore, validation
will be moved to addons-linter and issuing a proper warning
* Add Version.git_hash to point to the latest hash saved.

The git repository management is working almost on an atomic level,
kinda... we are using git worktree
(https://git-scm.com/docs/git-worktree) to create a temporary working
directory for the extraction of a file-object. And once extraction and
comitting is done, we are setting the current HEAD of the respective
branch (listed or unlisted) to that commit hash. That way parallel
extraction works and doesn't need any locking in case someone submits
two versions very quickly after another via the API or so.

Next steps are the creation of a celery-task and management command that
creates necessary repositories in the background, repo-creation
during upload (separate PRs) and reusing FsyncedZipFile in the file-viewer code.
2018-10-05 15:04:43 +02:00
Christopher Grebs 92e9fb2aed
Fix deprecation warnings (Django 2.x, DRF etc) (#9431)
This should fix most of our current Django 2.x and DRF deprecation warnings that we see during test runs.

* Uses `remote_field.model` in amo/utils instead of `remote_field.to`
* Uses `is_anonymous` and `is_authenticated` as properties instead of functions
* Replaces drf `@detail_route` with `@action(detail=True)`

Fixes #9432
2018-09-17 09:24:14 +02:00
pyup.io bot 8ebb311558 Update pytest-django to 3.4.2 (#9207)
* Update pytest-django from 3.3.3 to 3.4.2

* Try not to import models code at the top of the conftest module

* More cleanup, forcefully call django.setup

* Add docs
2018-08-21 17:13:25 +02:00
Mathieu Pillard d7876929b3 Remove filesystem cache, use default (memcached) backend for everything
Only the language tools API used the filesystem cache, and that was
because it had a relatively low usage compared to cache-machine, which
meant everything it cached was quickly evicted. Now that cache-machine
is gone, let's use memcached again for this.
2018-07-27 11:35:42 +02:00
Christopher Grebs 1bf79b82fa
Fold jingo_minify into our code.
This will simplify the upgrade to Django 1.11 and allow us to keep this
under control, upstream isn't properly maintained.

* Cleanup jingo-minify, keep only parts we are using. Cleanup tests

Also fix and simplify compress_assets to link to the correct /static/ folder.

Originally we hardcoded to look for settings.STATIC_ROOT but that
doesn't suffice since it's set to /site-static/ by default.

We are now using hardcoding the source of our static files instead of
guessing and mistakenly re-using STATIC_ROOT.

This commit also removes verbosity as an argument and simply logs all
errors immediately.

To simplify testing it adds a --force parameter.

To verify this works locally:

* Change settings.STATIC_ROOT to `'/site-static/`'
* Add `/site-static/` to the folders served by nginx (I'll open an issue
on our nginx container to serve this by default too)
* You may have to restart the nginx container after that for nginx to
pick things up
* Remove everything inside site-static folder
* Run `make update_assets`

Fixes #8532
2018-07-09 16:14:42 +02:00
Christopher Grebs 812d885b64
Revert "Fold jingo_minify into our code (#8694)"
This reverts commit 762142ee5a.
2018-07-05 15:19:07 +02:00
Christopher Grebs 762142ee5a
Fold jingo_minify into our code (#8694)
This will simplify the upgrade to Django 1.11 and allow us to keep this
under control, upstream isn't properly maintained.

* Copies jingo-minify into our code
* Removed all parts we aren't using (yui, git integration, `{{ inline_css }}` template tag etc)
* Try to clean up how subprocess calls are being made
* Cleaned up tests

This doesn't change anything regarding how jingo-minify works. It's still using good old `cat` and other ugly things but the code now looks nicer.

See 742297fef9 for more specific details about the cleanup from the original jingo-minify dump.

Fixes #8532
2018-07-02 11:14:53 +02:00
Christopher Grebs ceae9d4fd0
Remove cache machine (#8606)
Fixes #7743
2018-06-28 13:20:06 +02:00
Christopher Grebs 1500c53305
Implement basket <-> amo newsletter sync (#8174)
* Implement basket <-> amo newsletter sync.

* Adds basket-client dependency
* Refactors users.notifications to allow for remotely-managed
  notification types
* Implement helpers to fetch, subscribe and unsubscribe from newsletters
* Update user profile editing form to fetch and save to basket
* Update accounts/notifications endpoint to fetch and save to basket
* Implement a sync_basket command that fetches basket tokens
asynchronously for all users

All this is behind a waffle flag.

Fixes #7808

* Switch to 100% synchronous basket requests again

* Fix accounts view test to use the conftest configured token

* Fix typos and comments

* Put basket integration behind waffle flag

* Fix typo

* Fix tests

* Remove sync_basket command

* Fix flake8
2018-05-09 17:53:35 +02:00
Mathieu Pillard c125bf9354 Implement appversion compatibility filtering in language tools API
- Allow filtering by type to only show language packs
- Expose a new current_compatible_version if appversion is passed.
- This property will fetch the latest publicly available version
  compatible with the appversion passed.
- Replace caching with a filesystem-based implementation to work
  around cache eviction issues.
2018-03-05 15:44:46 +01:00
Christopher Grebs c3c31665e2
Revert "Revert "Refactor our tests and code to make better use of settings.TMP_PATH""
This reverts commit 3f7fe78093.
2018-02-02 12:47:50 +01:00
Christopher Grebs 3f7fe78093
Revert "Refactor our tests and code to make better use of settings.TMP_PATH"
This reverts commit 778a94871a.
2018-01-30 14:22:23 +01:00
Christopher Grebs d52015d365
Default to 'and' operator for match queries. Remove slug search, prioritize exact matches more. (#7303)
* Default to 'and' operator for match queries. Remove slug search, prioritize exact matches more.

References many "component: search" issues. What I tested with a
database of all public add-ons:

Example searches:

tab center redux - should find "Tab Center Redux" while "Tab Mix Plus" is probably second and "Redux DevTools" 4th or so
Open Image in New Tab -> should find "Open Image in New Tab" while "Open Bookmarks in New Tab" should be 2nd or 3rd
CoinHive -> Finds "Coinhive Blocker", "CoinBlock" (prefix search) and "NoMiners" (description)
Privacy -> Finds "Privacy Badger", "Privacy Pass", "Privacy Settings", "Google Privacy" (probably 4th or so) and "Blur" (summary + description + many users). Scores "Ghostery" on the first page but ranks it in the middle
firebu -> Finds "Firebug", "Firebug Autocompleter", "Firefinder for Firebug"
fireb -> Scores "Fire Drag" first, puts "Firebug" approximately 3rd or so
Menu Wizzard -> Finds "Menu Wizard" (fuzzy, typo) first, then "Add-ons Manager Context Menu" apparently because it matches good in the title and has many users
Frame Demolition -> Finds "Frame Demolition"
Demolition -> Finds only "Frame Demolition", same for "Demolation" (typo)
reStyle -> Finds "reStyle" and scores a few add-ons that match on "restore" next since the term is similar
MegaUpload DownloadHelper -> finds "MegaUpload DownloadHelper" first, scores "Video DownloadHelper" and "RadpidShare DownloadHelper" next. Doesn't find "Popup Blocker" anymore as currently happening on -prod
MegaUpload -> only finds "MegaUpload DownloadHelper" and nothing else
No Flash -> Scores "No Flash" first, then depending on users "Download Flash and Video", "YouTube Flash Video Player" and "YouTube Flash Player" (not necessarily in that order)
Disable Hello, Pocket & Reader+ -> finds "Disable Hello, Pocket & Reader+" first (yeay!), then scores "Reader", "Disable WebRTC" and "In My Pocket" next similarly to what's happening on -prod currently

Not working yet:

privacybadger -> "Privacy Badger" -> will probably need some kind of ngram filtering and analyzing (#591)
eyes -> 'decentraleyes' -> Not sure this should actually work, will probably need some more analyzing too (#591)

Not sure if it's specifically only because of these changes but #3248 is fixed.

This potentially fixes #7244, #6891, #6837, #6417, mozilla/addons#359.

Not sure if this fixes #mozilla/addons#567 but the results look much more promising and the amount of results doesn't explode here. I only have 2.8k add-ons for testing though so I'm not too sure.

And might be relevant to #6137.

This is a big step towards #2661, I doubt we can call this fixed though.

* Fix name tests

* Speed up ES tests, make scoring results more predictable by using only one shard and one replica

* Add tests

* Only test on new apiv3 based search.

* Fixup 'get_results'

* Remove debug print

* Isort imports

* Fix test settings, I'm blind.

* Adapt number of shards to what we define in settings_test

* Test search for grapple

* Remove property filtering in legacy api search, fix tests, fix flake8

* Add comment explaining shard config

* Fix tests again, add default platform, fix total counts again.

* Try to do some fixture cleanup, let's see...

* More test refactoring, make use of dfs-query-then-fetch during tests, allow us to test this later too via a waffle flag.

* Don't use waffle flag for legacy search, only for apiv3 searches.

* Fix unused import, fix usage of 'params'

* Use query-then-fetch in a regular addons-view tool, fix a few more tests to be able to handle the waffle-flag

* Create the dfs query then fetch flag only in ESTestCase, delete it properly. More serializer fixes

* precache the waffle flag for autocomplete tests too

* Minor cleanups

* Add docs, fix code style

* Add a todo

* Fix codestyle
2018-01-30 06:26:30 +01:00
Christopher Grebs 778a94871a
Refactor our tests and code to make better use of settings.TMP_PATH
* Also let the dot in py.test die so that upstream is happy again :)
 * Update tox to 2.9.1
 * Make sure that our urlconf is reset *after* we set MEDIA_ROOT
 * Adapt file extraction handling to new TMP_PATH prefixes
 * Less dump_apps hacks since the apps.json file isn't present at the
   beginning of any test now thanks to temporary paths for every separate
   test
 * Rewrite read-only-mode tests to cope with pytest settings fixture
 * Remove atexit hack from settings_test

This will probably make things a lot easier for ui-tests as well.

Fixes #7205
Fixes #7206
2018-01-05 16:41:35 +01:00
Christopher Grebs 42f06f2a73
Merge branch 'master' of github.com:mozilla/addons-server into try-elasticsearch-latest 2017-07-24 12:30:52 +02:00
Christopher Grebs b90bf13922 Merge pull request #5791 from mozilla/1573-implement-django-jinja
Loads of clean-ups along the way.

Fixes #1573

* Moves all helpers modules to templatetags.jinja_helpers - there are a few things in there that aren't jinja related so there'll be a follow-up to split that later
* Update Jinja2 to 2.9.6
* Add django-jinja 2.3.1
* move some jingo-minify helpers to olympia.lib to avoid any jingo imports
* unified |f and |fe helpers into one |format_html helper that always escapes everything unless the input is already |safe

* Move helpers, add requirements, fix imports.
* Give backend a proper name
* Port f and fe filters from jingo
* Make start porting reviews jinja helpers module, make first test pass
* Get a handful more tests working, get rid of get_env, more and more jingo calls.
* Disable extension matching, render .txt templates too, fixes more stats tests
* Fix csv_header template to produce some reasonable and csv parsable
* Set trim_blocks to be compatible with jingo
* Unify |f and |fe into one |format that simplifies escaping rules. Update tests.

I think having one unified |format filter is beneficial, especially
given that our current escaping rules were kinda complicated and allowed
for seriously dangerous combinations even with autoescape activated.

Now everything passed as an argument to |format is explicitly escaped
unless marked as |safe, there's no way around that anymore.

* Naive first version using |format instead of |f and |fe, might need more review.
* Fix format for unicode strings
* Rename |format to |format_html
* Move nl2br_xhtml to amo.jinja_helpers, use it in all our templates.
* Move datetime filter to our code temporarily, fix mocks, fix recursive error
* Move csrf call to django_jinja csrf_token tag, fix addons templatetags
* Fix |class_selected usage, fix render_with to get registered
* Remove hack from zadmin, fix zadmin templatetags
* Fix user delete photo test, don't rely on proper context updates that happen in order.
* Fix more nl2br tests
* Fix detail page escape, django escapes differently than jinja
* Remove context from edit_review_reply_form
* Fix date created format filter usage
* Remove templates setting user, fix can_review
* Fix collect_add_widget to not inherit the global context
* Remove happy unicode client
* Cleanup can_review, add tests
* Fix tests, django use different html character for double quote escaping
* Switch to firefox latest to check ui-tests
* Cleanup and fix do_truncate
* Remove jingo, copy jingo-minify helpers that depend on jingo to our lib for now
* Rename nl2br_xhtml -> nl2br
* Jinja 2.9 compat for reviews truncate filter
* Don't use TEMPLATE_DEBUG
* Set default value for q, happens on index page.
* Fix jinja2 formatting with newstyle gettext
2017-06-30 17:57:31 -07:00
Christopher Grebs c35648da19 Potentially fix our reindex issue on -dev.
It took me days to find this and loads of useless refactoring but
apparently these tasks get immediately upgraded to a chord after we
chain them later with the other tasks (after the for-loop).

And, the only requirement for a chord is: do not ignore the results,
never!

Refs #3960

* Make sure index_stats isn't using call_command
* modernize create_subtasks, add support for countdowns, fix queries loading the world...
* half chunk size for stats reindexing
* Refactor stats reindex logging
* Upgrade elasticsearch to 5.4.1 for our docker config
* Make es test setup easier to inherit for our uitests.
* Restore order, make sure to start es before add-on get's created.
* Remove db requirement from es_test fixture
2017-06-16 12:06:12 +08:00
Mathieu Pillard 19177a796e Move commonware utils we use to our own repos
- Middlewares are integrated to existing ones or moved to amo.middlewares
- Logging is moved to core.logger
- All logging calls are modified to use core.logger
- In addition, get/set_user(), get/set_remote_addr() are moved to core
  to circumvent import issues.
2017-03-08 12:01:03 +01:00
Mathieu Pillard 646844eea6 Use pytest fixtures to set up elasticsearch mocks in tests
This allows function-based tests or tests not inheriting from
our base TestCase class to still mock ElasticSearch, resulting
in faster tests.
2017-02-07 12:17:08 +01:00
Mark Striemer a207265995 Remove set_password/check_password (supports #3049) (#3662) 2016-10-13 12:37:43 -05:00
Christopher Grebs c6d1cc2d66 Update django-waffle, django-piston, more import path fixes.
* Pull in django-waffle 0.10 and a fixed version of django-piston.
  Both provide late-initialization support by not calling get_user_model
  on import-time.
* Add alias for addons.buttons.js
2016-01-06 10:48:03 +01:00
Christopher Grebs 580de6f78e Start renaming, re-ordering folder/module structure.
We now have something like that:

 - /
 -- src/
 --------- olympia/
 -------------- {access,accounts,amo,addons,...}
 -------------- wsgi.py
 -------------- urls.py
 -------------- migrations/
 -------------- libs/
 ...

Which generally feels more django-like again and makes porting
our sys.path hacks to django 1.7 and it's app-refactoring
a lot easier.

* Update setup.py to bring it to a more modern format
* Update gitignore
2016-01-06 10:48:02 +01:00
Kris Maglione 33027f0feb Unpin the DB for the current thread after every test. 2015-10-17 18:14:30 -07:00
Mathieu Agopian f7ef88f3c4 Don't flag for admin review when source submitted if not needed (bug 1200621) 2015-09-11 12:54:13 +02:00
Mathieu Agopian 98602f66d8 Try better using pytest fixtures instead of _pre_setup or _post_teardown 2015-08-27 14:55:43 +02:00
Kris Maglione edeff385b5 Use separate Elasticsearch instances and memcache pools for each slave when running under xdist. 2015-08-25 12:56:07 -07:00
Kris Maglione b6d2227748 Shuffle some test initialization code to allow running under xdist. 2015-08-25 12:56:07 -07:00
Mathieu Agopian 2783cceaf3 properly use settings_tests for tests 2014-12-19 18:32:48 +01:00
Mathieu Agopian 7c9c856873 Use pytest (bug 1090184) 2014-12-09 09:45:40 +01:00