Commit Graph

154 Commits

Author SHA1 Message Date
Steve Howell 3138f7a73c mypy: Fix content types.
This got by mypy due to Message being an Any type.
2021-12-16 20:35:56 -05:00
Steve Howell 0b0faa46b4 mypy: Use object type for checker return values. 2021-12-16 19:52:35 -05:00
Steve Howell 16db496871 export tests: Verify files for single-user exports. 2021-12-13 12:29:19 -08:00
Steve Howell 3c63ebde15 export tests: Extract ExportFile class.
This is just moving code around.
2021-12-13 12:29:19 -08:00
Steve Howell eb0114cdee export tests: Add verify_attachment_json.
This allows verify_uploads to use the database
as the authoritative source for what attachments
we need to look for when we're verifying the
images got exported properly, while still
also verifying attachment.json is correct.
2021-12-13 12:29:19 -08:00
Steve Howell 24009cb7d3 export tests: Clean up emoji setup.
We can't use the normal RealmEmoji from the
test database.

Also, we now use an actual action function to
set up emojis for our own purposes.
2021-12-13 12:29:17 -08:00
Steve Howell c6cdf98b66 export tests: Rename method to export_realm. 2021-12-13 12:25:19 -08:00
Steve Howell c79c95d55e export tests: Split function for uploading files.
This will give us flexibility for the single-user
tests.
2021-12-13 12:25:19 -08:00
Steve Howell a215a14c00 export tests: Use verify_uploads() for s3, too. 2021-12-13 12:25:19 -08:00
Steve Howell 3f5c15320b export tests: Extract verify_uploads. 2021-12-13 12:25:19 -08:00
Steve Howell 6b5a90bbd1 tests: Extract verify_emojis. 2021-12-13 12:25:19 -08:00
Steve Howell 302ef32c5b export tests: Extract verify_realm_logo_and_icon. 2021-12-13 12:25:19 -08:00
Steve Howell b4c089d3b8 export tests: Improve how we check avatars.
We avoid code duplication, and we iterate
over all records to see if files exist.
2021-12-13 12:25:19 -08:00
Steve Howell 0c02d89bf3 export tests: Avoid passing back path_id from setup. 2021-12-13 12:25:19 -08:00
Steve Howell d3ea369057 export tests: Clean up emoji checks. 2021-12-13 12:25:19 -08:00
Steve Howell fd94ba1579 tests: Avoid returning original_avatar_path_id.
The way we check for avatars is kind of clumsy for
realms.  Ideally we would just check all users
in the realm.
2021-12-13 12:25:19 -08:00
Steve Howell dbf1ae989d tests: Avoid relying on setup data (test_image).
It is better for the verifying code to just explicitly
ensure that the exported file bytes match the bytes
in the test image.  This introduces a tiny bit more
of I/O.
2021-12-13 12:25:19 -08:00
Steve Howell 53ffb8152f tests: Use read_test_image_file helper. 2021-12-13 12:25:19 -08:00
Steve Howell 186c446458 tests: Create export files for specific user.
We no longer hackily look for the first message ever
sent within the realm.
2021-12-13 12:25:19 -08:00
Steve Howell 2debb5e5e6 tests: Add assertions for upload path_ids. 2021-12-13 12:25:19 -08:00
Steve Howell 035c90df68 export tests: Avoid full_data concept.
It's easier to read the code without the intermediate
full_data dictionary that obscures where the files live.

We also avoid some unnecessary file i/o in the tests.
2021-12-13 12:25:19 -08:00
Steve Howell 275653ad2a tests: Move helpers to module level.
(This is a pure code move apart from removing "self"
in a few places.)
2021-12-13 12:25:19 -08:00
Steve Howell 6e3e3a7bff export tests: Remove unnecessary setUp method.
I cargo-culted this in a recent commit.
2021-12-13 12:25:11 -08:00
Steve Howell 08376da7af tests: Remove dead testing code for 2nd message batch. 2021-12-13 12:25:05 -08:00
Steve Howell d63e12c233 tests: Check more tables for user exports.
We do a sanity check for every table
that gets written to user.json as part of
the single-user export.

If we add more tables to the single-user export,
the test that I modified here will now ask
the author to add a new checker function, which
means we should always have at least a basic
sanity check for every exported table as long
as we stay in this new paradigm.

We also remove a little bit of old code that
became redundant.
2021-12-12 11:16:12 -08:00
Steve Howell 21ab5e3a55 tests: Register checkers for user export test. 2021-12-11 13:06:41 -05:00
Steve Howell 7df86f3614 tests: Tweak assertion for streams. 2021-12-11 13:06:41 -05:00
Steve Howell 6be3fbde1d tests: Split out single-user tests.
I dropped a minor assertion that was kind of redundant.
2021-12-11 13:06:41 -05:00
Steve Howell b2d83a8300 tests: Split out SingleUserExportTest.
This is mostly moving code, plus I now just
call shutil.rmtree directly.
2021-12-11 13:06:41 -05:00
Steve Howell 9a39ca217f user export: Show less info for recipients.
For PM and huddles, show full names but no
emails or other crufty fields.
2021-12-09 17:20:01 -08:00
Steve Howell 6a5c407b05 user export: Be more selective about exported messages. 2021-12-09 17:20:01 -08:00
Steve Howell 8f991f8eb1 export: Make sure messages are sorted **across** files.
We now ensure that all message ids are sorted BEFORE
we split them into batches.

We now do a few extra "slim" queries to get message
ids up front.

But, now, when we divide them into batches, we no
longer run 2 or 3 different complicated queries in
a loop. We just basically hydrate our message ids,
so `write_message_partials` should be easy to reason
about.

This change also means that for tiny realms with
< 1000 messages you will always have just one
json file, since we aggregate the ids from the
queries before batching.
2021-12-09 12:22:34 -08:00
Steve Howell 2a73964e16 user export: Add reactions.
We may eventually try to attach these to the messages
in the message-NNNNNN.json files, but for now they're
fine in user.json.
2021-12-09 12:22:34 -08:00
Steve Howell 6381c2e535 tests: Make sure import doesn't corrupt original realm.
The original intention of this was to prevent coding
errors with realm getters that don't, um, filter
on realm.

Unfortunately, you can still write a broken realm getter
that forgets to filter on realm, but which returns a
Set, and the new safeguards won't see any difference.

We could make all the getters return sorted lists
instead, but that's for another day.

This code does serve another purpose, which is to
prevet egregious bugs in the import itself.
2021-12-07 12:27:01 -08:00
Steve Howell fea659eacd tests: Extract get_getters. 2021-12-07 12:27:01 -08:00
Steve Howell 5803057589 tests: Make some helpers class-level.
This is somewhat tactical in nature. I want to
extract a huge chunk of code that minorly depends
on these helpers.
2021-12-07 12:27:01 -08:00
Steve Howell 29bd1e8bd3 tests: Avoid clutter within long list of getters.
The diff here is ugly, but to summarize:

    BEFORE IMPORT:
        define get_user_id
        define get_huddle_hashes

    AFTER IMPORT AND MAKING GETTERS:
        check realm id
        define assert_realm_values
        verify emoji codes
        check huddle hashes
2021-12-07 12:27:01 -08:00
Steve Howell 93761cd237 tests: Add getter decorator for import test. 2021-12-07 12:27:01 -08:00
Steve Howell 5892748c7b tests: Avoid lambdas in import test. 2021-12-07 12:27:01 -08:00
Steve Howell 54a6c82282 tests: Avoid equal flag for huddle hashes.
There's no need to complexify the codepath
for all the normal use cases.
2021-12-07 12:27:01 -08:00
Eeshan Garg 2cdaae681d actions: Rename do_change_plan_type -> do change_realm_plan_type.
We will soon be adding an equivalent function for RemoteZulipServer,
so it makes sense to rename this function to be more descriptive.
2021-12-06 16:18:53 -08:00
Steve Howell 4088be6017 import/export: Add UserStatus table.
(We support both realm and single-user exports.)
2021-12-06 13:27:25 -08:00
Steve Howell f83907d3bb export: Add MutedUser table.
Note that the import was already implemented, but
its test was flawed.
2021-12-06 13:27:25 -08:00
Steve Howell dffe776287 import tests: Have Cordelia react with a realm emoji.
This exercises some rather unusual database-related
manipulations that happen when creating reactions
from either the app or the import process.
2021-12-06 13:27:25 -08:00
Eeshan Garg b325a4f1be realm: Rename plan type constants to be more descriptive.
It is confusing to have the plan type constants not be namespaced
by the thing they represent. We already have a namespacing
convention in place for constants, so we should use it for
Realm.plan_type as well.
2021-10-19 12:20:39 -07:00
Abhijeet Prasad Bodas 743712c267 user_topic: Filter on visibility_policy in muted_topic code.
This is the final step required for it to be possible for us to add
UserTopic rows in the future with a differen visibility_policy.

Fixes #19272.
2021-09-17 12:14:28 -07:00
sahil839 7d64a9053b models: Ensure every realm has a RealmUserDefault object.
Because we create all realms with do_create_user (including in the
test suite), we just need to change that function, add a migration for
existing realms, and ensure the data import code path correctly
creates these objects.

Note that the import code path will create a RealmUserDefault row with
default values if it is not present in the import data, which is
important for importing data from other tools like Slack.
2021-09-09 10:28:44 -07:00
Anders Kaseorg 58b7a4eb44 utils: Remove unused query_chunker function.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-08-19 01:51:37 -07:00
Abhijeet Prasad Bodas 683c8507e4 models: Remove MutedTopic alias for UserTopic.
Part of #19272
2021-07-28 10:25:54 -07:00
PIG208 495a8476be tests: Use assertion to enforce None-checks in tests.
This fixes a batch of mypy errors of the following format:
'Item "None" of "Optional[Something]" has no attribute "abc"

Since we have already been recklessly using these attritbutes
in the tests, adding assertions beforehand is justified presuming
that they oughtn't to be None.
2021-07-24 09:54:21 -07:00