2499 Commits

Author SHA1 Message Date
Christopher Allan Webber
394a4a37f7 require mock for the new uuid-mocking tests 2013-01-23 16:47:30 -06:00
Christopher Allan Webber
b0118957ff We don't want any empty string slugs, so make "" -> None 2013-01-23 16:40:39 -06:00
Christopher Allan Webber
266b42b3dc Switching uuid4()[1:4] -> uuid4().hex[:4]
.hex is what we need to access to get at the ascii (hex) version
anyway.  Also, not sure why the previous version grabbed starting at
the index of 1... just grab the first characters instead.
2013-01-23 15:15:22 -06:00
Christopher Allan Webber
985871095e Simplifying string concatenation in generate_slug and fixing docstring
- made the mistake of copying some commit message things into the
   docstring.  Fixed.
 - elrond points out that += is nicer and we don't need u"" in this
   case since we're not concatenating a variable, we're concatenating
   a known ascii string.
2013-01-15 16:11:15 -06:00
Christopher Allan Webber
88de830fcf A revised algorithm for generating slugs.
This one does not *force* slugs, but usually it will probably result
in a niceish one.

The end *result* of the algorithm will (presumably, I have not tested
it) result in these resolutions for these situations:
 - If we have a slug, make sure it's clean and sanitized, and if it's
   unique, we'll use that.
 - If we have a title, slugify it, and if it's unique, we'll use that.
 - If we can't get any sort of thing that looks like it'll be a useful
   slug out of a title or an existing slug, bail, and don't set the
   slug at all.  Don't try to create something just because.  Make
   sure we have a reasonable basis for a slug first.
 - If we have a reasonable basis for a slug (either based on existing
   slug or slugified title) but it's not unique, first try appending
   the entry's id, if that exists
 - If that doesn't result in something unique, tack on some randomly
   generated bits until it's unique.  That'll be a little bit of junk,
   but at least it has the *basis* of a nice slug!
2013-01-15 15:48:19 -06:00
Christopher Allan Webber
72bb46c7c8 Need to import uuid4 for generate_slug to totally work 2013-01-15 14:34:13 -06:00
Sebastian Spaeth
66d9f1b2a0 Make generate_slug assign a slug in any case
generate_slug could assign "none" as slug. Make sure it assigns a unique
slug in any case. We now try based on:

a) existing slug values
b) media.title
c) media.id
d) random garbage

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2013-01-15 20:08:21 +01:00
Sebastian Spaeth
4ca0755ab6 Sanitize slug input on media edit
Previously we allowed EVERYTHING, even slashes as slug when editing the media.
Make sure we slugify the input to sanitize it.

(+ string formdata is unicode, so there is no need to convert it)

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2013-01-15 20:08:21 +01:00
Sebastian Spaeth
7525cdf9eb Disallow ":" as part of a media slug
We might want to use "id:IDN" as a special case slug to point to a media's
id.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2013-01-15 20:08:21 +01:00
Tiberiu C. Turbureanu
cf764377df #571: Fixed. Display collection description with Markdown formatting. 2013-01-15 18:03:06 +02:00
Sebastian Spaeth
fd61aac7c7 Unbreak 301 responses
The move to werkzeug routing went pretty smooth, but one thing was
broken by accident: URLs without final slash result in a 301
werkzeug.routing.RequestRedirect response. We displayed it as a generic
error page rather than actually sending the redirect. Do that. One thing
it does though is to skip all meddlewares, which should be OK for a 301
response, but might need rework if we decide otherwise. With this, 301
responses with lacking final slash are unbroken again.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2013-01-15 16:52:22 +01:00
Sebastian Spaeth
65969d3fb7 Simplify check_media_slug_used
Remove the unused dummy_db argument and generally make the function
readable.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2013-01-15 14:49:50 +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
947c08ae43 Improve error message wording (#564)
Improve error message wording if no csf cookie could be detected. Also,
make the error text translatable.
2013-01-14 16:09:24 +01:00
Elrond
56cf9f5ff1 Use the new logo.html thingy in airy. 2013-01-13 23:06:15 +01:00
Elrond
17dcc3ae4f Move logo part into bits/logo.html
To make it easier for themers to replace the logo, move it
out into its own logo.html.
2013-01-13 23:06:15 +01:00
Elrond
c96c67ce9e Kill db_host, db_name, and db_port from config_spec.ini.
The last bits of mongo. Let me remove them.
2013-01-13 18:32:09 +01:00
Elrond
8b271c28bd Make runtests.sh be useable from anywhere.
Now you can have your current directory anywhere and call
runtests.sh with full path and it'll find the way to
nosetests and the tests directory on its own.

Most useful if you're inside the mediagoblin/ dir and can
just call "../runtests.sh".
2013-01-11 20:55:35 +01:00
Elrond
7dec9f92f3 issue 355: Only run tests in mediagoblin/tests/
If you don't give an option argument (starting with a dash)
to runtests.sh then it will append the directory with all
the tests to the commandline of nosetests. That way it will
only search there for tests.
2013-01-11 16:28:41 +01:00
Sebastian Spaeth
a3b98853df Improve and extend profile editing tests
We only ever ran the password changing test here, and not the
half-existing test for changing the bio and homepage.

Fix the tests to actually run both tests. We check that setting bio and
homepage to a valid value works as expected. We also test for invalid
bio (too long) and invalid URLs setting fails. (which is what we want).

- Check that the old /edit/profile/ address redirects to /u/USER/edit/.
- Check that /u/USER/edit/ works as expected
- Check that /u/OTHERUSER/edit/ fails with a 403 Forbidden error when we
  are not logged in as that user. The last remaining test that would be
  useful is to make a user an admin and make sure the admin can edit
  other users' profiles.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2013-01-09 09:56:53 +01:00
Sebastian Spaeth
abc4da2927 Enable /u/USERNAME/edit/ pattern #588
Transition from the inconsistent /edit/profile/?username=FOO to
the nicer /u/FOO/edit/. The old pattern will still work and
redirects to the new URL.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2013-01-09 09:56:53 +01:00
Elrond
6de8b42e4e Fix tests on webtest < 1.3.6.
Debian testing ships webtest 1.3.4. And it would be nice to
use the base packages.

One of the csrf tests fails on webtest < 1.3.6.
But using a fresh app fixes it.
We have no clue, why exactly.

When we require webtest 1.3.6, change this.
2013-01-09 00:22:27 +01:00
Elrond
c130e3ee79 Move db.sql.migration_tools to db.migration_tools.
Follow the new trend.
2013-01-08 22:50:01 +01:00
Elrond
c4466cb4dc Add inspect_table.
In our current scheme of migrations, we reflect the current
sql schema into an SQLAlchemy schema. So let's have a tool
function for this.
2013-01-08 22:50:01 +01:00
Elrond
a050e776c6 Move all the migration tools into new migration_tools.py
Factor all the migration related stuff out into a new
.db.sql.migration_tools.
First we don't have to load this module for our normal
server.
Second it makes all the import dependencies a little more
cleaner.
2013-01-08 22:50:01 +01:00
Christopher Allan Webber
8e7354ef2b Fixing import to mediagoblin.db.base in stl models
Previously we had mediagoblin.db.sql.base, that just changed to drop
the sql; fixing.
2013-01-08 13:24:27 -06:00
Sebastian Spaeth
031d988c29 Merge branch 'WIP/test_performance' 2013-01-08 16:57:15 +01:00
Sebastian Spaeth
b97144dcc9 tests: More instances where a fresh database is not needed
Save test runtime by not dumping the databases when not needed.
2013-01-08 15:55:32 +01:00
Sebastian Spaeth
5018a3557c Don't read full image media into RAM on copying (#419)
We copy uploaded media from the queue store to the local workbench
and then to its final destination. The latter was done by simply:
dst.write(src.read()) which is of course evil as it reads the whole
file content into RAM. Which *might* arguably still be OK for
images, but you never know.

Make use of the provided storage() methods that offer chunked copying
rather than opening and fudging with files ourselves.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2013-01-08 14:51:41 +01:00
Sebastian Spaeth
40cec2b444 Don't get a fresh app when not needed
These tests, don't need fresh databases, so don't discard and recreate
the tables. This reduces test suite runtime on my laptop from 130 to 96
seconds.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2013-01-08 11:57:25 +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
7f4e42b0b1 Fix slug lookup regression (#587)
Removing the Mongo InvalidID legacy code removed an explicit check for
"int" for the id lookup. This led the @get_user_media_entry decorator to
fail if we looked up a nonexisting non-numerical slug (it tried to query
the id with a string, which failed). Cast id to int and return 404 in
case it is non-numeric which fixes the regression. It does not fix the
underlying problem of slug_or_id lookups that were discussed.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2013-01-08 08:59:32 +01:00
Joar Wandborg
76e6c2b15e Made the airy header element responsive again 2013-01-07 21:36:31 +01:00
Sebastian Spaeth
20be9bb77d Remove custom GMQuery class
We provided a custom GMQuery class that offered a .sort() method for
compatibility with the Mongo syntax. Now that we have settled for sqlalchemy
which uses the order_by() method, we can safely remove this custom class
and move a little closer to "pure" and native sqlalchemy usage.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2013-01-07 13:52:37 +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
a5acfe23fa Move mediagoblin.db.sql.extratypes to mediagoblin.db.extratypes
No other functional changes.
2013-01-07 13:10:02 +01:00
Sebastian Spaeth
b0c8328e54 Move db.sql.models* to db.models* 2013-01-07 11:44:29 +01:00
Sebastian Spaeth
1e46dc2537 Move db.sql.util to db.util
Now that sqlalchemy is providing the database abstractions, there is no
need to hide everything in db.sql. sub-modules. It complicates the code
and provides a futher layer of indirection.

Move the db.sql.util.py to db.util.py and adapt the importers.
2013-01-07 11:31:56 +01:00
Sebastian Spaeth
0efe9e2796 Remove mediagoblin.db.sql.fake.DESCENDING
This is the last remnant that requires us to keep db.sql.fake.py. Use
ModelName.desc() or sqlalchemy.sql.expression.desc(column) to achieve
descending sorts.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2013-01-07 11:15:04 +01:00
Christopher Allan Webber
208842590c Also make slug unit test work with the new optionally-translitcodec-free code 2013-01-06 21:46:38 -06:00
Christopher Allan Webber
e535b9b36f Make translitcodec optional, and work nicely without it. 2013-01-06 21:41:08 -06:00
Joar Wandborg
78fa73bcd5 Made api_test use @require_active_login 2013-01-02 20:05:07 +01:00
Elrond
b228d89715 prepare_queue_task: Take app not request.
First rename prepare_entry to prepare_queue_task, because
this is really more like what this thing does.

Thanks to Velmont for noting that we do not need a request
in here, but an "app" is good enough. Which means, that
this stuff can be called from tool scripts too.
2012-12-26 23:42:26 +01:00
Elrond
01986008f6 upload refactor: Use prepare_entry in api. 2012-12-26 23:42:26 +01:00
Elrond
37f90b435d Use run_process_media in the api.
Now refactor in the api. Start with run_process_media.
2012-12-26 23:42:26 +01:00
Elrond
8eb47d02d9 Processing: Factor out prepare_entry.
prepare_entry handles the task_id setup and generating a
queue filename and file. it returns the queue file.
2012-12-26 23:42:26 +01:00
Elrond
86bb44ef12 Factor out the actual calling of the processing.
Calling the processing task and handling the exceptions is
easy, but has a bunch of caveats, so factor it out into an
easy callable function.
2012-12-26 23:42:26 +01:00
Elrond
be1f0f7d33 upload refactor: push url handling
Start to refactor our upload handling in main submit and
the api. Start factoring out the handling of PuSH url
handling.
2012-12-26 23:42:26 +01:00
Odin Hørthe Omdal
6e60238b6c Bug #584, upgrade EXIF.py from master to read Nikon data 2012-12-26 18:42:37 +01:00
Sebastian Spaeth
ab7281fe24 Fix up symlinks in exif bump
Previous exif bump copied the newer version into
mediagoblin/tools/extlib/exif but not in extlib/exif. Fix this by
bumping extlib/exif and symlinking to tools/extlib/exif.

Do note that this is still the version fetched from http://sourceforge.net/projects/exif-py/
while the upstream maintainer seems to be active on:
https://github.com/ianare/exif-py

(The sf.net download is quite new though)

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-26 10:26:06 +01:00