64 Commits

Author SHA1 Message Date
Jessica Tallon
d88fcb03e2 Change codebase to query or create correct User model
The code base had many references to User.username and other
specific to LocalUser attributes as that was the way it use to exist.
This updates those to query on the generic User model but filtering
by attributes on the LocalUser.
2015-07-31 15:15:24 +02:00
Jessica Tallon
5ddc85e071 Fix #984 - Improvements to Activity and ActivityIntermediator
- Add unit tests to cover get and set methods on Activity
- Rewrite the set to remove set and use Session.flush instead
- Use sqlalchemy's validator instead of .save hack
2014-10-21 11:44:11 +01:00
Christopher Allan Webber
f6bad0eb26 Merge branch 'master' into merge-python3-port
Has some issues, will iteratively fix!

Conflicts:
	mediagoblin/gmg_commands/__init__.py
	mediagoblin/gmg_commands/deletemedia.py
	mediagoblin/gmg_commands/users.py
	mediagoblin/oauth/views.py
	mediagoblin/plugins/api/views.py
	mediagoblin/tests/test_api.py
	mediagoblin/tests/test_edit.py
	mediagoblin/tests/test_oauth1.py
	mediagoblin/tests/test_util.py
	mediagoblin/tools/mail.py
	mediagoblin/webfinger/views.py
	setup.py
2014-09-16 14:01:43 -05:00
Jessica Tallon
9246a6ba89 Tidy up federation code and add tests to cover more of the APIs 2014-08-18 10:51:32 -05:00
Jessica Tallon
51ab51921e Add more tests for federation APIs 2014-07-22 23:13:16 +01:00
Jessica Tallon
f751d346cf Add fixtures to provide OAuth client, request and access models 2014-07-22 23:13:16 +01:00
Berker Peksag
386c9c7c55 Use six.iteritems() instead of dict.iteritems(). 2014-05-26 19:50:38 +03:00
tilly-Q
6acf4ee60e This should be my final code update before I am ready for review! Basically, in
this update I finished the search/sort function on the Reports Panel. I also
finished the Terms of Service and made the decision to remove the meta portion
of the site I had planned to create. I decided that the features involved were
just unnecessary at this point. I also dropped the User status column and added
a migration to establish default privileges (and create the privilege foundat-
-ions. I fixed a few small errors that were left over as well, in the implemen-
tation and in the tests. Next, I just need to await code review and work on the
documentation for these new features. I also need to supervise a new merge to
master.

===============================================================================
    Dropped the vestigial 'status' column
===============================================================================
--\ mediagoblin/db/migrations.py
--\ mediagoblin/db/models.py
--| Also added in comments describing the current situation with the `is_admin`
  | and `email_verified` columns, where they are 100% vestigial but cannot be
  | dropped.

===============================================================================
            Wrote necessary migrations to set up Privilege
    foundations and give users the necessary privileges on an older
     implementation of mediagoblin that is migrating into this update
===============================================================================
--\ mediagoblin/db/migrations.py

===============================================================================
    Deleted the meta pages
===============================================================================
--\ Deleted mediagoblin/meta/__init__.py
--\ Deleted mediagoblin/meta/routing.py
--\ Deleted mediagoblin/meta/views.py
--\ Deleted mediagoblin/templates/mediagoblin/meta/code_of_conduct.html
--\ Deleted mediagoblin/templates/mediagoblin/meta/reports_details.html
--\ Deleted mediagoblin/templates/mediagoblin/meta/reports_panel.html
    ----------------------------------------------------------------
        Moved the terms of service to /terms_of_service
    ----------------------------------------------------------------
    --\ Moved mediagoblin/templates/mediagoblin/meta/terms_of_service.html
        -> mediagoblin/templates/mediagoblin/terms_of_service.html
    --| I decided that terms of service were really the only necessary part of my
      | planned "meta" pages, so I moved it instead to its own singular page
    --\ mediagoblin/routing.py
    --\ mediagoblin/static/css/base.css
    --\ mediagoblin/templates/mediagoblin/base.html
    --\ mediagoblin/views.py

===============================================================================
          Simplified & Finished the Reports Panel Searching
===============================================================================
--\ mediagoblin/moderation/forms.py
--\ mediagoblin/moderation/tools.py
--\ mediagoblin/moderation/views.py
--\ mediagoblin/templates/mediagoblin/moderation/report_panel.html
--\ mediagoblin/templates/mediagoblin/moderation/user.html

===============================================================================
                  Fixed Small Errors
===============================================================================
--\ mediagoblin/templates/mediagoblin/user_pages/user.html
--\ mediagoblin/tests/test_moderation.py
--\ mediagoblin/tests/tools.py

===============================================================================
2013-09-10 13:17:07 -04:00
tilly-Q
dfd66b789c This was a big commit! I included lots of documentation below, but generally I
did a few things. I wrote many many many new tests, either in old test files or
in the three new test files I made. I also did some code-keeping work, deleting
trailing whitespace and deleting vestigial code. Lastly, I fixed the parts of
the code which I realized were broken thru the process of running tests.

===============================================================================
 Deleted trailing whitespace:
===============================================================================
--\  mediagoblin/decorators.py
--\  mediagoblin/auth/tools.py
--\  mediagoblin/db/migrations.py
--\  mediagoblin/db/models.py
--\  mediagoblin/gmg_commands/users.py
--\  mediagoblin/moderation/forms.py
--\  mediagoblin/moderation/tools.py
--\  mediagoblin/moderation/views.py
--\  mediagoblin/templates/mediagoblin/moderation/media_panel.html
--\  mediagoblin/templates/mediagoblin/moderation/report.html
--\  mediagoblin/templates/mediagoblin/moderation/report_panel.html
--\  mediagoblin/templates/mediagoblin/moderation/user.html
--\  mediagoblin/templates/mediagoblin/moderation/user_panel.html
--\  mediagoblin/templates/mediagoblin/user_pages/report.html
--\  mediagoblin/templates/mediagoblin/utils/report.html
--\  mediagoblin/user_pages/lib.py
--\  mediagoblin/user_pages/views.py
===============================================================================
 Deleted Vestigial Code
===============================================================================
--\  mediagoblin/db/util.py
--\  mediagoblin/tests/test_notifications.py
===============================================================================
 Modified the Code:
===============================================================================
--\  mediagoblin/moderation/tools.py
--| Encapsulated the code around giving/taking away privileges into two
  | funtions.

--\  mediagoblin/moderation/views.py
--| Imported and used the give/take away privilege functions
--| Replaced 'require_admin_or_moderator_login' with
  |'user_has_privilege(u"admin")' for adding/taking away privileges, only
  | admins are allowed to do this.

--\  mediagoblin/templates/mediagoblin/banned.html
--| Added relevant translation tags
--| Added ability to display indefinite banning

--\  mediagoblin/templates/mediagoblin/user_pages/media.html
--| Made sure the add comments button was only visible for users with the
  | `commenter` privilege

--\  mediagoblin/tests/test_submission.py
--| Paroneayea fixed a DetachedInstanceError I was having with the our_user
  | function

--\  mediagoblin/tests/tools.py
--| Added a fixture_add_comment_report function for testing.

--\  mediagoblin/tools/response.py
--| Fixed a minor error where a necessary return statement was missing
--| Fit the code within 80 columns

--\  mediagoblin/user_pages/views.py
--| Added a necessary decorator to ensure that only users with the 'commenter'
  | privilege can post comments
===============================================================================
 Wrote new tests for an old test file:
===============================================================================
--\  mediagoblin/tests/test_auth.py
--| Added a new test to make sure privilege granting on registration happens
  | correctly

--\  mediagoblin/tests/test_modelmethods.py*
--| Added a test to ensure the User method has_privilege works properly
===============================================================================
 Wrote entirely new files full of tests:
===============================================================================
--\  mediagoblin/tests/test_moderation.py
--\  mediagoblin/tests/test_privileges.py
--\  mediagoblin/tests/test_reporting.py
===============================================================================
===============================================================================
NOTE: Any files I've marked with a * in this commit report, were actually subm-
itted in my last commit. I made that committ to fix an error I was having, so
they weren't properly documented in that report.
===============================================================================
===============================================================================
2013-08-29 13:47:50 -04:00
tilly-Q
2c901db023 This commit was just to fix a few of the errors with the merging and to
make sure that all of the previous tests work fine.
2013-08-20 15:24:29 -04:00
tilly-Q
e1561d0488 This was a very small update, I'm hoping to rebase after this to solve some
other problems. I started looking at the tests in this update. This update I
spent fixing the tests to work with my new code.

--\ mediagoblin/db/migration_tools.py
--| Merging from ticket 679

--\ mediagoblin/db/migrations.py
--| Added unique constraint to Privilege.privilege_name

--\ mediagoblin/db/models.py
--| Deleted vestigial Privilege.is_admin_or_moderator method

--\ mediagoblin/templates/mediagoblin/moderation/user.html
--| Add a `Ban User` / `UnBan User` for admin

--\ mediagoblin/test/test_api.py
--| Fixed test with my new changes

--\ mediagoblin/test/test_auth.py
--| Try to fix test, still having problems

--\ mediagoblin/test/test_modelmethods.py
--| Wrote my first test for the User.has_privilege method

--\ mediagoblin/test/test_modelmethods.py
--| Fixed test with my new changes

--\ mediagoblin/test/test_sqlmigrations.py
--| Merging from ticket 679

--\ mediagoblin/test/tools.py
--| Editted add_fixture_user to allow for privileges rather than active column
2013-08-20 12:02:20 -04:00
Rodney Ewing
44082b12d8 Patch by Strum. Ticket #451 - Convert all mongokit style .find, .find_one, .one calls over to SQLAlchemy queries 2013-07-11 14:17:50 -07:00
Rodney Ewing
af4414a85f Merge remote-tracking branch 'upstream/master' into auth
Conflicts:
	mediagoblin/app.py
	mediagoblin/auth/forms.py
	mediagoblin/auth/tools.py
	mediagoblin/db/migrations.py
	mediagoblin/db/models.py
	mediagoblin/edit/views.py
	mediagoblin/plugins/basic_auth/tools.py
	mediagoblin/tests/test_edit.py
2013-06-25 13:37:21 -07:00
Christopher Allan Webber
c3de34d431 Adding a docstring to fixture_media_entry
It's not complete, but it makes clearer how to avoid errors with
fake_upload :)

This commit sponsored by Harper Sanford.  Thank you!
2013-06-22 17:40:12 -05:00
Joar Wandborg
2d7b6bdef9 New notifications
- Added request.notifications
- Email configuration fixes
  - Set config_spec default SMTP port to `0` and switch to SSL/non-SSL
    default if `port == 0`
  - Added email_smtp_use_ssl configuration setting
- Added migrations for notification tables
- Added __repr__ to MediaComment(Mixin)
- Added MediaComment.get_entry => MediaEntry
- Added CommentSubscription, CommentNotification, Notification,
  ProcessingNotification tables
- Added notifications.task to celery init
- Fixed a bug in the video transcoder where pygst would hijack the
  --help argument.
- Added notifications
  - views
    - silence
    - subscribe
  - routes
  - utility methods
  - celery task
- Added half-hearted .active comment CSS style
- Added quick JS to show header_dropdown
- Added fragment template to show notifications in header_dropdown
- Added fragment template to show subscribe/unsubscribe buttons on
  media/comment pages
- Updated celery setup tests with notifications.task
- Tried to fix test_misc tests that I broke
- Added notification tests
- Added and extended tests.tools fixtures
- Integrated new notifications into media_home, media_post_comment views
- Bumped SQLAlchemy dependency to >= 0.8.0 since we need polymorphic for
  the notifications to work
2013-06-09 21:18:37 +02:00
Rodney Ewing
fa7232913c modified test .ini files and changed tests to use basic_auth bcrypt 2013-05-24 16:52:48 -07:00
Christopher Allan Webber
491029bc36 Moving test_user_dev->user_dev in plugin app configs & adding plugin static serving
The test_user_dev (as opposed to user_dev) was a legacy before we had
each application running in its own directory (as they now do in
pytest).  Move that name to just user_dev... this is more consistent
with the rest of our naming and will make writing these config files
easier.  (If we want to test that changing these still works, that
should be a separate unit test with special config files.)

Additionally, add plugin static serving to the common test paste
config file.

This commit sponsored by Juan Jose Marin Martinez.  Thank you!
2013-05-23 13:33:07 -05:00
Christopher Allan Webber
a98c95b41d Tests should no longer use the environment-variable-related-setup and set up in app instead
This should remove a bunch of confusing cruft.  I hate using that
environment variable!  Also that old code was fragile.

This commit sponsored by Stephen Milton.  Thanks!
2013-05-12 15:55:59 -05:00
Nathan Yergler
64598a79a9 Merge remote-tracking branch 'joar-github/oauth/refresh_tokens'
This merges the patch for Issue #548.
2013-04-13 15:54:58 -07:00
Elrond
8021cc5605 Merge remote-tracking branch 'brett/itsdangerous'
* brett/itsdangerous:
  Call is_updated instead of testing it boolean.
  Harden It's Dangerous key management.
  First tests for the Session class.
  Set a starting value for session.send_new_cookie.
  Remove beaker stuff from the code.
  Delete the session cookie on an empty session.
  Back sessions with It's Dangerous.
  Improve fs security for itsdangerous secret.
  Docs for get_timed_signer_url.
  Basic itsdangerous infrastructure.

Conflicts:
	mediagoblin/tests/test_cache.py
2013-04-09 19:40:54 +02:00
Joar Wandborg
c121a7d3d0 OAuth: Support refresh tokens, etc
Initially I was going to write a failing test for refresh tokens. Thus
this fix includes an orphaned 'expect_failure' method in test utils.

I ended up writing support for OAuth refresh tokens, as well as a lot of
cleanup (hopefully) in the OAuth plugin code.

**Rebase**: While waiting for this stuff to be merged, the testing
framework changed, it comes with batteries included regarding fails.
Removed legacy nosetest helper.

Also added a lot of backref=backref([...], cascade='all, delete-orphan')
2013-04-06 22:17:27 +02:00
Christopher Allan Webber
7d503a897b Really removing nosetests things now! all assert_whatever removed 2013-04-06 10:08:26 -05:00
Christopher Allan Webber
5c2ece7401 Switch test_app generation over to use py.test fixtures.
By doing this, we can take advantage of py.test's ability to create
temporary directories that are then cleaned up later during testing.
This helps for sandboxing things.

This also involves a ton of changes:
 - Changing the get_app stuff appropriately, getting rid of the
   setup_fresh_app decorator
 - Making said fixture
 - Switching over a billion tests to use it
2013-04-04 19:23:04 -05:00
Christopher Allan Webber
e11c62a0ef Oops, forgot to assign dump_old_app to self, heh. 2013-04-04 11:13:47 -05:00
Christopher Allan Webber
245d4f119f Turning setup_fresh_app into SetupFreshApp, a decorator with options!
This way people can pass in particular paste/mediagoblin configs that they want to use.
2013-04-04 11:08:50 -05:00
Christopher Allan Webber
6588acc183 Updating get_app to allow for passing in particular app configs 2013-04-04 10:37:32 -05:00
Brett Smith
9e1fa2396f Remove beaker stuff from the code.
This is all obsoleted by It's Dangerous.
2013-03-24 15:10:08 -04:00
Elrond
e9b4e50007 Failing testcase for issue 611.
This currently fails (with foreign key constrain error):
1. Have user A and B.
2. User B creates media M.
3. User A post a comment on M.
4. User A deletes his own account.

The test is a little bit wider.
2013-01-29 21:13:49 +01:00
Elrond
cd75b2280f Add some simple collection test. 2013-01-18 11:42:56 +01:00
Elrond
1be247b36e Rename get_test_app to get_app.
nosetests runs everything that even vaguely looks like a
test case... even our get_test_app. And as it is imported
everywhere... it is run everywhere as a test case. Renaming
it saves us about 10+ tests and a few seconds of time.
2013-01-18 11:40:40 +01:00
Sebastian Spaeth
4fc0a28994 More explicit get_or_create pattern
Don't do "user = getUser() or newUser()" in one line. It is bound to
confuse poor souls. Be more explicit here and even add a code comment.

Thanks to Elrond for not liking the previous pattern.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2013-01-15 14:49:50 +01:00
Sebastian Spaeth
a5cf95c5ad Do not fail is a user exists already
When the tests want to create a new user, don't fail if it already
exists and just reuse the existing one. This allows us to run tests
without dumping the whole database if that is not needed for the tests.
The upcoming tests for test_edit will make use of this.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2013-01-08 11:54:44 +01:00
Sebastian Spaeth
39dc3bf8db Mv db.sql.base to db.base
This concludes the db.sql.* -> db.* move. Our db abstraction layer is
sqlalchemy, so there is no need to a separate db.sql.* hierarchy.

All tests have been run for each of the commit series to make sure
everything works at every step.
2013-01-07 13:42:32 +01:00
Sebastian Spaeth
74af60bb32 replace webob.Response with werkzeug Response
Replace webob usage in one more file. Document a TODO that should
be clarified, we should probably be using json_response rather than
Response() here.

Modify the TestMeddleware to not rely on the content_type attribute
being present, while werkzeug.wrappers Response() has it the BaseResponse()
object which is often returned in tests does not have it.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-21 08:12:25 +01:00
Sebastian Spaeth
5c2b84869f Move DBModel._id -> DBModel.id
We were refering to model._id in most of the code base as this is
what Mongo uses. However, each use of _id required a) fixup of queries:
e.g. what we did in our find() and find_one() functions moving all
'_id' to 'id'. It also required using AliasFields to make the ._id
attribute available. This all means lots of superfluous fixing and
transitioning in a SQL world.

It will also not work in the long run. Much newer code already refers
to the objects by model.id (e.g. in the oauth plugin), which will break
with Mongo. So let's be honest, rip out the _id mongoism and live with
.id as the one canonical way to address objects.

This commit modifies all users and providers of model._id to use
model.id instead. This patch works with or without Mongo removed first,
but will break Mongo usage (even more than before)

I have not bothered to fixup db.mongo.* and db.sql.convert
(which converts from Mongo to SQL)

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-21 00:30:48 +01:00
Joar Wandborg
bee079f36f Fixed pylint/pep8 warnings in test/tools.py 2012-09-29 21:08:20 +02:00
Joar Wandborg
a11aa2d17a Added some OAuth plugin tests 2012-09-26 23:53:51 +02:00
Joar Wandborg
30520c92cc Fixed tests
- Adapt tests to new global_config arg for run_dbupdate
- Account for [plugins] not being set in config
2012-09-15 17:54:34 +02:00
Jakob Kramer
1e03504e9f removed _make_safe in favor of functools.wraps 2012-07-12 15:01:40 +02:00
Brett Smith
9c7688667e Drop our scoped session sooner to prevent SQLAlchemy re-binding warnings. 2012-07-08 11:00:36 -04:00
Elrond
37ef4c66b1 Reload and detach the test user.
The code often needs to know some fields of the test user
even after doing some sql and stuff. The solultion is to
reload it and properly detach it from its Session. That way
all its fields are available and the whole thing is not
connected to a session. It feels like a normal object.
2012-03-26 20:31:35 +02:00
Christopher Allan Webber
d693f6bd86 SQL based tests and refactored Celery setup stuff
- Changed config files of test configs to use SQL
 - Updated celery initialization tools, factored them to be able to
   use the "big instance" application stuff
2012-03-26 11:14:11 -05:00
Christopher Allan Webber
cf29e8a824 It's 2012 all up in here 2012-02-02 09:44:13 -06:00
Elrond
9754802d4b fixture_add_user: Factoring a unit test tool
Some unit tests need a user in the database, especially to
act as that user.  Some routines did that on their own.  So
factored this whole thing into a new function and use it
around.
2011-12-01 23:33:47 +01:00
Elrond
56dc1c9d3e Add base class for Meddleware
Created a BaseMeddleware which all Meddleware should derive
from. This is not strictly needed, but will greatly help.

The base class has the common __init__ of all the other
Meddlwares and fall backs for all hooks. That way a new
Meddlware only needs to override what it actually wants to
implement.
2011-11-25 22:16:18 +01:00
Christopher Allan Webber
ce5ae8da19 Rename MediaGoblin middleware to meddleware to avoid confusion w/ wsgi middleware
hehehehehe, "meddleware"
2011-11-25 12:13:56 -06:00
Elrond
33d11e995d Move TestingMiddleware to tests/tools.py
This middleware isn't needed outside of the tests, so let's
just put it there.
2011-11-12 13:21:41 +01:00
Elrond
34b0874d9a Some docs for the TestingMiddleware
To make the TestingMiddleware actually more useful in the
future, start to document it.
2011-11-12 13:10:48 +01:00
Elrond
91b89bde47 591: Let Testing Middleware check for staticdirect() usage
All references to static, shipped content should go via
request.staticdirect().

So insert a TestingMiddleware in the chain, which tests for
this on all requests/reponses happening in the test suite.
It's a simple text search for a bogus usage pattern.
2011-10-19 21:37:19 +02:00
Aaron Williamson
152a3bfaa3 Finished splitting util.py into separate files. 2011-10-01 18:05:44 -04:00