From 832880cfac4206aaba0e7de8f005c6425da7a8f3 Mon Sep 17 00:00:00 2001 From: RohanJnr Date: Thu, 10 Jun 2021 02:11:40 +0530 Subject: Add tests for active params. --- .../apps/api/tests/test_off_topic_channel_names.py | 38 +++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'pydis_site/apps/api/tests') diff --git a/pydis_site/apps/api/tests/test_off_topic_channel_names.py b/pydis_site/apps/api/tests/test_off_topic_channel_names.py index 3ab8b22d..a407654c 100644 --- a/pydis_site/apps/api/tests/test_off_topic_channel_names.py +++ b/pydis_site/apps/api/tests/test_off_topic_channel_names.py @@ -65,8 +65,15 @@ class EmptyDatabaseTests(APISubdomainTestCase): class ListTests(APISubdomainTestCase): @classmethod def setUpTestData(cls): - cls.test_name = OffTopicChannelName.objects.create(name='lemons-lemonade-stand', used=False) - cls.test_name_2 = OffTopicChannelName.objects.create(name='bbq-with-bisk', used=True) + cls.test_name = OffTopicChannelName.objects.create( + name='lemons-lemonade-stand', used=False, active=True + ) + cls.test_name_2 = OffTopicChannelName.objects.create( + name='bbq-with-bisk', used=True, active=True + ) + cls.test_name_3 = OffTopicChannelName.objects.create( + name="frozen-with-iceman", used=True, active=False + ) def test_returns_name_in_list(self): """Return all off-topic channel names.""" @@ -78,7 +85,8 @@ class ListTests(APISubdomainTestCase): response.json(), [ self.test_name.name, - self.test_name_2.name + self.test_name_2.name, + self.test_name_3.name ] ) @@ -97,7 +105,29 @@ class ListTests(APISubdomainTestCase): response = self.client.get(f'{url}?random_items=2') self.assertEqual(response.status_code, 200) - self.assertEqual(response.json(), [self.test_name.name, self.test_name_2.name]) + self.assertEqual(response.json(), [self.test_name.name, self.test_name_3.name]) + + def test_returns_inactive_ot_names(self): + """Return inactive off topic names.""" + url = reverse('bot:offtopicchannelname-list', host="api") + response = self.client.get(f"{url}?active=false") + + self.assertEqual(response.status_code, 200) + self.assertEqual( + response.json(), + [self.test_name_3.name] + ) + + def test_returns_active_ot_names(self): + """Return active off topic names.""" + url = reverse('bot:offtopicchannelname-list', host="api") + response = self.client.get(f"{url}?active=true") + + self.assertEqual(response.status_code, 200) + self.assertEqual( + response.json(), + [self.test_name.name, self.test_name_2.name] + ) class CreationTests(APISubdomainTestCase): -- cgit v1.2.3 From 3795b6d6de005f0ed00c37cf042eaca01d0a4769 Mon Sep 17 00:00:00 2001 From: RohanJnr Date: Thu, 10 Jun 2021 02:32:17 +0530 Subject: Use assertListEqual where applicable instead of assertEqual. --- .../apps/api/tests/test_off_topic_channel_names.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'pydis_site/apps/api/tests') diff --git a/pydis_site/apps/api/tests/test_off_topic_channel_names.py b/pydis_site/apps/api/tests/test_off_topic_channel_names.py index a407654c..ebb1224a 100644 --- a/pydis_site/apps/api/tests/test_off_topic_channel_names.py +++ b/pydis_site/apps/api/tests/test_off_topic_channel_names.py @@ -69,7 +69,7 @@ class ListTests(APISubdomainTestCase): name='lemons-lemonade-stand', used=False, active=True ) cls.test_name_2 = OffTopicChannelName.objects.create( - name='bbq-with-bisk', used=True, active=True + name='bbq-with-bisk', used=False, active=True ) cls.test_name_3 = OffTopicChannelName.objects.create( name="frozen-with-iceman", used=True, active=False @@ -81,7 +81,7 @@ class ListTests(APISubdomainTestCase): response = self.client.get(url) self.assertEqual(response.status_code, 200) - self.assertEqual( + self.assertListEqual( response.json(), [ self.test_name.name, @@ -90,22 +90,24 @@ class ListTests(APISubdomainTestCase): ] ) - def test_returns_single_item_with_random_items_param_set_to_1(self): + def test_returns_two_items_with_random_items_param_set_to_2(self): """Return not-used name instead used.""" url = reverse('bot:offtopicchannelname-list', host='api') - response = self.client.get(f'{url}?random_items=1') + response = self.client.get(f'{url}?random_items=2') self.assertEqual(response.status_code, 200) - self.assertEqual(len(response.json()), 1) - self.assertEqual(response.json(), [self.test_name.name]) + self.assertEqual(len(response.json()), 2) + self.assertEqual(response.json(), [self.test_name.name, self.test_name_2.name]) def test_running_out_of_names_with_random_parameter(self): """Reset names `used` parameter to `False` when running out of names.""" url = reverse('bot:offtopicchannelname-list', host='api') - response = self.client.get(f'{url}?random_items=2') + response = self.client.get(f'{url}?random_items=3') self.assertEqual(response.status_code, 200) - self.assertEqual(response.json(), [self.test_name.name, self.test_name_3.name]) + self.assertListEqual( + response.json(), [self.test_name.name, self.test_name_2.name, self.test_name_3.name] + ) def test_returns_inactive_ot_names(self): """Return inactive off topic names.""" -- cgit v1.2.3 From 8fdabfb4c08931b1e2352e98b307b3bfa3a121f1 Mon Sep 17 00:00:00 2001 From: RohanJnr Date: Thu, 10 Jun 2021 02:45:55 +0530 Subject: Use sets to compare 2 un-ordered lists. --- .../apps/api/tests/test_off_topic_channel_names.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'pydis_site/apps/api/tests') diff --git a/pydis_site/apps/api/tests/test_off_topic_channel_names.py b/pydis_site/apps/api/tests/test_off_topic_channel_names.py index ebb1224a..34dde7c6 100644 --- a/pydis_site/apps/api/tests/test_off_topic_channel_names.py +++ b/pydis_site/apps/api/tests/test_off_topic_channel_names.py @@ -81,13 +81,13 @@ class ListTests(APISubdomainTestCase): response = self.client.get(url) self.assertEqual(response.status_code, 200) - self.assertListEqual( - response.json(), - [ + self.assertEqual( + set(response.json()), + { self.test_name.name, self.test_name_2.name, self.test_name_3.name - ] + } ) def test_returns_two_items_with_random_items_param_set_to_2(self): @@ -97,7 +97,7 @@ class ListTests(APISubdomainTestCase): self.assertEqual(response.status_code, 200) self.assertEqual(len(response.json()), 2) - self.assertEqual(response.json(), [self.test_name.name, self.test_name_2.name]) + self.assertEqual(set(response.json()), {self.test_name.name, self.test_name_2.name}) def test_running_out_of_names_with_random_parameter(self): """Reset names `used` parameter to `False` when running out of names.""" @@ -105,8 +105,9 @@ class ListTests(APISubdomainTestCase): response = self.client.get(f'{url}?random_items=3') self.assertEqual(response.status_code, 200) - self.assertListEqual( - response.json(), [self.test_name.name, self.test_name_2.name, self.test_name_3.name] + self.assertEqual( + set(response.json()), + {self.test_name.name, self.test_name_2.name, self.test_name_3.name} ) def test_returns_inactive_ot_names(self): @@ -127,8 +128,8 @@ class ListTests(APISubdomainTestCase): self.assertEqual(response.status_code, 200) self.assertEqual( - response.json(), - [self.test_name.name, self.test_name_2.name] + set(response.json()), + {self.test_name.name, self.test_name_2.name} ) -- cgit v1.2.3 From 569c2c2d2540fda797ade699c7acb67e402114e5 Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Sun, 17 Oct 2021 21:29:53 +0800 Subject: Fix typos across codebase ./pydis_site/apps/resources/resources/tools/ides/thonny.yaml:1: specifically ./pydis_site/apps/content/resources/guides/pydis-guides/helping-others.md:115: considered ./pydis_site/apps/content/resources/guides/pydis-guides/contributing/issues.md:59 labels ./pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot.md:99: recommend ./pydis_site/apps/content/resources/guides/pydis-guides/contributing/site.md:111: particularly ./pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot/env-var-reference.md:29: Integer ./pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot/env-var-reference.md:67: calculating ./pydis_site/apps/api/tests/test_off_topic_channel_names.py:157: response I didn't touch the code jam and game jam typos because I'm not sure if they should be preserved as is. There were a few 'seperated' typos which I didn't change because I *think* it's just another way of spelling it? In the offensive words test there was a keyword argument named `fied` which I didn't touch because I wasn't sure where that was from. --- pydis_site/apps/api/tests/test_off_topic_channel_names.py | 2 +- .../apps/content/resources/guides/pydis-guides/contributing/issues.md | 2 +- .../resources/guides/pydis-guides/contributing/sir-lancebot.md | 2 +- .../pydis-guides/contributing/sir-lancebot/env-var-reference.md | 4 ++-- .../apps/content/resources/guides/pydis-guides/contributing/site.md | 2 +- .../apps/content/resources/guides/pydis-guides/helping-others.md | 2 +- pydis_site/apps/resources/resources/tools/ides/thonny.yaml | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) (limited to 'pydis_site/apps/api/tests') diff --git a/pydis_site/apps/api/tests/test_off_topic_channel_names.py b/pydis_site/apps/api/tests/test_off_topic_channel_names.py index 63993978..1825f6e6 100644 --- a/pydis_site/apps/api/tests/test_off_topic_channel_names.py +++ b/pydis_site/apps/api/tests/test_off_topic_channel_names.py @@ -154,7 +154,7 @@ class DeletionTests(AuthenticatedAPITestCase): cls.test_name_2 = OffTopicChannelName.objects.create(name='bbq-with-bisk') def test_deleting_unknown_name_returns_404(self): - """Return 404 reponse when trying to delete unknown name.""" + """Return 404 response when trying to delete unknown name.""" url = reverse('api:bot:offtopicchannelname-detail', args=('unknown-name',)) response = self.client.delete(url) diff --git a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/issues.md b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/issues.md index 9151e5e3..0c6d3513 100644 --- a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/issues.md +++ b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/issues.md @@ -56,7 +56,7 @@ Definitely try to: Labels allow us to better organise Issues by letting us view what type of Issue it is, how it might impact the codebase and at what stage it's at. -In our repositories, we try to prefix labels belonging to the same group, for example the label groups `status` or `type`. We will be trying to keep to the same general structure across our project repositories, but just have a look at the full lables list in the respective repository to get a clear idea what's available. +In our repositories, we try to prefix labels belonging to the same group, for example the label groups `status` or `type`. We will be trying to keep to the same general structure across our project repositories, but just have a look at the full labels list in the respective repository to get a clear idea what's available. If you're a contributor, you can add relevant labels yourself to any new Issue ticket you create. diff --git a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot.md b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot.md index 60169c01..a0d3d463 100644 --- a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot.md +++ b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot.md @@ -96,7 +96,7 @@ Otherwise, please see the below linked guide for Redis related variables. --- # Run the project -The sections below describe the two ways you can run this project. We recomend Docker as it requires less setup. +The sections below describe the two ways you can run this project. We recommend Docker as it requires less setup. ## Run with Docker Make sure to have Docker running, then use the Docker command `docker-compose up` in the project root. diff --git a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot/env-var-reference.md b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot/env-var-reference.md index eba737ad..9ad014a2 100644 --- a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot/env-var-reference.md +++ b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/sir-lancebot/env-var-reference.md @@ -26,7 +26,7 @@ Additionally, you may find the following environment variables useful during dev | `BOT_DEBUG` | Debug mode of the bot | False | | `PREFIX` | The bot's invocation prefix | `.` | | `CYCLE_FREQUENCY` | Amount of days between cycling server icon | 3 | -| `MONTH_OVERRIDE` | Interger in range `[0, 12]`, overrides current month w.r.t. seasonal decorators | +| `MONTH_OVERRIDE` | Integer in range `[0, 12]`, overrides current month w.r.t. seasonal decorators | | `REDIS_HOST` | The address to connect to for the Redis database. | | `REDIS_PORT` | | | `REDIS_PASSWORD` | | @@ -64,7 +64,7 @@ These variables might come in handy while working on certain cogs: | Advent of Code | `AOC_LEADERBOARDS` | List of leaderboards seperated by `::`. Each entry should have an `id,session cookie,join code` seperated by commas in that order. | | Advent of Code | `AOC_STAFF_LEADERBOARD_ID` | Integer ID of the staff leaderboard. | | Advent of Code | `AOC_ROLE_ID` | ID of the advent of code role. -| Advent of Code | `AOC_IGNORED_DAYS` | Comma seperated list of days to ignore while calulating score. | +| Advent of Code | `AOC_IGNORED_DAYS` | Comma seperated list of days to ignore while calculating score. | | Advent of Code | `AOC_YEAR` | Debug variable to change the year used for AoC. | | Advent of Code | `AOC_CHANNEL_ID` | The ID of the #advent-of-code channel | | Advent of Code | `AOC_COMMANDS_CHANNEL_ID` | The ID of the #advent-of-code-commands channel | diff --git a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/site.md b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/site.md index df75e81a..f2c3bd95 100644 --- a/pydis_site/apps/content/resources/guides/pydis-guides/contributing/site.md +++ b/pydis_site/apps/content/resources/guides/pydis-guides/contributing/site.md @@ -108,7 +108,7 @@ If you get any Docker related errors, reference the [Possible Issues](https://py ## Run on the host -Running on the host is particularily useful if you wish to debug the site. The [environment variables](#2-environment-variables) shown in a previous section need to have been configured. +Running on the host is particularly useful if you wish to debug the site. The [environment variables](#2-environment-variables) shown in a previous section need to have been configured. ### Database diff --git a/pydis_site/apps/content/resources/guides/pydis-guides/helping-others.md b/pydis_site/apps/content/resources/guides/pydis-guides/helping-others.md index d126707d..a7f1ce1d 100644 --- a/pydis_site/apps/content/resources/guides/pydis-guides/helping-others.md +++ b/pydis_site/apps/content/resources/guides/pydis-guides/helping-others.md @@ -112,7 +112,7 @@ Presenting a solution that is considered a bad practice might be useful in certa > for i in range(len(your_list)): > print(your_list[i]) > -> The second replier gave a valid solution, but it's important that he clarifies that it is concidered a bad practice in Python, and that the first solution should usually be used in this case. +> The second replier gave a valid solution, but it's important that he clarifies that it is considered a bad practice in Python, and that the first solution should usually be used in this case. ## It's OK to Step Away diff --git a/pydis_site/apps/resources/resources/tools/ides/thonny.yaml b/pydis_site/apps/resources/resources/tools/ides/thonny.yaml index 3581e1cd..d7f03a74 100644 --- a/pydis_site/apps/resources/resources/tools/ides/thonny.yaml +++ b/pydis_site/apps/resources/resources/tools/ides/thonny.yaml @@ -1,4 +1,4 @@ -description: A Python IDE specifially aimed at learning programming. Has a lot of +description: A Python IDE specifically aimed at learning programming. Has a lot of helpful features to help you understand your code. name: Thonny title_url: https://thonny.org/ -- cgit v1.2.3 From 5972560e59f98fced0c56d70039b0d0ba15532d0 Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Mon, 18 Oct 2021 08:57:54 +0800 Subject: Fix typo 'fied' in apps/api/tests/test_offensive_message.py --- pydis_site/apps/api/tests/test_offensive_message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pydis_site/apps/api/tests') diff --git a/pydis_site/apps/api/tests/test_offensive_message.py b/pydis_site/apps/api/tests/test_offensive_message.py index 9b79b38c..3cf95b75 100644 --- a/pydis_site/apps/api/tests/test_offensive_message.py +++ b/pydis_site/apps/api/tests/test_offensive_message.py @@ -58,7 +58,7 @@ class CreationTests(AuthenticatedAPITestCase): ) for field, invalid_value in cases: - with self.subTest(fied=field, invalid_value=invalid_value): + with self.subTest(field=field, invalid_value=invalid_value): test_data = data.copy() test_data.update({field: invalid_value}) -- cgit v1.2.3 From 876daaf6eb34e620710473c0311e23f36fd4e7eb Mon Sep 17 00:00:00 2001 From: RohanJnr Date: Fri, 5 Nov 2021 10:55:09 +0530 Subject: Update test cases to adhere to recent changes made that removed hosts. --- pydis_site/apps/api/tests/test_off_topic_channel_names.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pydis_site/apps/api/tests') diff --git a/pydis_site/apps/api/tests/test_off_topic_channel_names.py b/pydis_site/apps/api/tests/test_off_topic_channel_names.py index 354cda9c..2d273756 100644 --- a/pydis_site/apps/api/tests/test_off_topic_channel_names.py +++ b/pydis_site/apps/api/tests/test_off_topic_channel_names.py @@ -112,7 +112,7 @@ class ListTests(AuthenticatedAPITestCase): def test_returns_inactive_ot_names(self): """Return inactive off topic names.""" - url = reverse('bot:offtopicchannelname-list') + url = reverse('api:bot:offtopicchannelname-list') response = self.client.get(f"{url}?active=false") self.assertEqual(response.status_code, 200) @@ -123,7 +123,7 @@ class ListTests(AuthenticatedAPITestCase): def test_returns_active_ot_names(self): """Return active off topic names.""" - url = reverse('bot:offtopicchannelname-list') + url = reverse('api:bot:offtopicchannelname-list') response = self.client.get(f"{url}?active=true") self.assertEqual(response.status_code, 200) -- cgit v1.2.3 From c8d1513b8f8cb21482180ce19d69a107adefe4e2 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Mon, 22 Nov 2021 20:38:41 +0000 Subject: Make metricity test order insensitive We only actually care that thee key:value pairs are equal, the order of them isn't actually important. The naming of `assertCountEqual` is a little misleading, since it actually tests that the first sequence contains the same elements as second, regardless of their order. See https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertCountEqual --- pydis_site/apps/api/tests/test_users.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pydis_site/apps/api/tests') diff --git a/pydis_site/apps/api/tests/test_users.py b/pydis_site/apps/api/tests/test_users.py index 295bcf64..550c7240 100644 --- a/pydis_site/apps/api/tests/test_users.py +++ b/pydis_site/apps/api/tests/test_users.py @@ -408,7 +408,7 @@ class UserMetricityTests(AuthenticatedAPITestCase): in_guild=True, ) - def test_get_metricity_data(self): + def test_get_metricity_data_under_1k(self): # Given joined_at = "foo" total_messages = 1 @@ -421,7 +421,7 @@ class UserMetricityTests(AuthenticatedAPITestCase): # Then self.assertEqual(response.status_code, 200) - self.assertEqual(response.json(), { + self.assertCountEqual(response.json(), { "joined_at": joined_at, "total_messages": total_messages, "voice_banned": False, -- cgit v1.2.3 From 78b2f3b8ed46d23015ab2f765504572f672f4567 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Mon, 22 Nov 2021 20:38:58 +0000 Subject: Add metricity test for users >1k messages --- pydis_site/apps/api/tests/test_users.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'pydis_site/apps/api/tests') diff --git a/pydis_site/apps/api/tests/test_users.py b/pydis_site/apps/api/tests/test_users.py index 550c7240..81bfd43b 100644 --- a/pydis_site/apps/api/tests/test_users.py +++ b/pydis_site/apps/api/tests/test_users.py @@ -428,6 +428,25 @@ class UserMetricityTests(AuthenticatedAPITestCase): "activity_blocks": total_blocks }) + def test_get_metricity_data_over_1k(self): + # Given + joined_at = "foo" + total_messages = 1001 + total_blocks = 1001 + self.mock_metricity_user(joined_at, total_messages, total_blocks, []) + + # When + url = reverse('api:bot:user-metricity-data', args=[0]) + response = self.client.get(url) + + # Then + self.assertEqual(response.status_code, 200) + self.assertCountEqual(response.json(), { + "joined_at": joined_at, + "total_messages": total_messages, + "voice_banned": False, + }) + def test_no_metricity_user(self): # Given self.mock_no_metricity_user() -- cgit v1.2.3 From 0f24bdcd0ba261da045ac73e8567239eb63c6fc6 Mon Sep 17 00:00:00 2001 From: D0rs4n <41237606+D0rs4n@users.noreply.github.com> Date: Tue, 31 Aug 2021 17:54:39 +0200 Subject: Add test to check role unassignment Create a test that checks if a role gets deleted it will also get unassigned from the user --- pydis_site/apps/api/tests/test_roles.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'pydis_site/apps/api/tests') diff --git a/pydis_site/apps/api/tests/test_roles.py b/pydis_site/apps/api/tests/test_roles.py index d39cea4d..7c968852 100644 --- a/pydis_site/apps/api/tests/test_roles.py +++ b/pydis_site/apps/api/tests/test_roles.py @@ -1,7 +1,8 @@ from django.urls import reverse from .base import AuthenticatedAPITestCase -from ..models import Role +from ..models import Role, User + class CreationTests(AuthenticatedAPITestCase): @@ -35,6 +36,20 @@ class CreationTests(AuthenticatedAPITestCase): permissions=6, position=0, ) + cls.role_to_delete = Role.objects.create( + id=7, + name="role to delete", + colour=7, + permissions=7, + position=0, + ) + cls.role_unassigned_test_user = User.objects.create( + id=8, + name="role_unassigned_test_user", + discriminator="0000", + roles=[cls.role_to_delete.id], + in_guild=True + ) def _validate_roledict(self, role_dict: dict) -> None: """Helper method to validate a dict representing a role.""" @@ -181,6 +196,11 @@ class CreationTests(AuthenticatedAPITestCase): response = self.client.delete(url) self.assertEqual(response.status_code, 204) + def test_role_delete_unassigned(self): + """Tests if the deleted Role gets unassigned from the user.""" + self.role_to_delete.delete() + self.assertEqual(self.role_unassigned_test_user.roles, []) + def test_role_detail_404_all_methods(self): """Tests detail view with non-existing ID.""" url = reverse('api:bot:role-detail', args=(20190815,)) -- cgit v1.2.3 From 9d255dcf3daafde71071ad75b000077a861da659 Mon Sep 17 00:00:00 2001 From: D0rs4n <41237606+D0rs4n@users.noreply.github.com> Date: Tue, 31 Aug 2021 18:49:21 +0200 Subject: Patch roles test to use fresh instance from the DB --- pydis_site/apps/api/tests/test_roles.py | 1 + 1 file changed, 1 insertion(+) (limited to 'pydis_site/apps/api/tests') diff --git a/pydis_site/apps/api/tests/test_roles.py b/pydis_site/apps/api/tests/test_roles.py index 7c968852..88c0256b 100644 --- a/pydis_site/apps/api/tests/test_roles.py +++ b/pydis_site/apps/api/tests/test_roles.py @@ -199,6 +199,7 @@ class CreationTests(AuthenticatedAPITestCase): def test_role_delete_unassigned(self): """Tests if the deleted Role gets unassigned from the user.""" self.role_to_delete.delete() + self.role_unassigned_test_user.refresh_from_db() self.assertEqual(self.role_unassigned_test_user.roles, []) def test_role_detail_404_all_methods(self): -- cgit v1.2.3 From f34a52016bd5a7d50c1146d6fbd213ce889f58c7 Mon Sep 17 00:00:00 2001 From: D0rs4n <41237606+D0rs4n@users.noreply.github.com> Date: Tue, 31 Aug 2021 19:21:36 +0200 Subject: Patch signals to use post_delete, instead of pre_delete From now on the signal will only get executed after the Role has been deleted The commit also introduces minor changes in the tests of roles --- pydis_site/apps/api/signals.py | 4 ++-- pydis_site/apps/api/tests/test_roles.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'pydis_site/apps/api/tests') diff --git a/pydis_site/apps/api/signals.py b/pydis_site/apps/api/signals.py index c69704b1..5c26bfb6 100644 --- a/pydis_site/apps/api/signals.py +++ b/pydis_site/apps/api/signals.py @@ -1,10 +1,10 @@ -from django.db.models.signals import pre_delete +from django.db.models.signals import post_delete from django.dispatch import receiver from pydis_site.apps.api.models.bot import Role, User -@receiver(signal=pre_delete, sender=Role) +@receiver(signal=post_delete, sender=Role) def delete_role_from_user(sender: Role, instance: Role, **kwargs) -> None: """Unassigns the Role (instance) that is being deleted from every user that has it.""" for user in User.objects.filter(roles__contains=[instance.id]): diff --git a/pydis_site/apps/api/tests/test_roles.py b/pydis_site/apps/api/tests/test_roles.py index 88c0256b..73c80c77 100644 --- a/pydis_site/apps/api/tests/test_roles.py +++ b/pydis_site/apps/api/tests/test_roles.py @@ -4,7 +4,6 @@ from .base import AuthenticatedAPITestCase from ..models import Role, User - class CreationTests(AuthenticatedAPITestCase): @classmethod def setUpTestData(cls): @@ -96,11 +95,11 @@ class CreationTests(AuthenticatedAPITestCase): url = reverse('api:bot:role-list') response = self.client.get(url) - self.assertContains(response, text="id", count=4, status_code=200) + self.assertContains(response, text="id", count=5, status_code=200) roles = response.json() self.assertIsInstance(roles, list) - self.assertEqual(len(roles), 4) + self.assertEqual(len(roles), 5) for role in roles: self._validate_roledict(role) -- cgit v1.2.3 From 59e4a5c8316464e116630a329064decac4c2a075 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Thu, 16 Dec 2021 22:29:11 +0000 Subject: Always include metricity message blocks Thanks to a recent database maintenance (https://pythondiscord.freshstatus.io/incident/139811) querying out metricity message data is far cheaper. So there is no longer a reason to only fetch blocks if the member has a low message count. --- pydis_site/apps/api/tests/test_users.py | 21 +-------------------- pydis_site/apps/api/viewsets/bot/user.py | 6 +----- 2 files changed, 2 insertions(+), 25 deletions(-) (limited to 'pydis_site/apps/api/tests') diff --git a/pydis_site/apps/api/tests/test_users.py b/pydis_site/apps/api/tests/test_users.py index 81bfd43b..9b91380b 100644 --- a/pydis_site/apps/api/tests/test_users.py +++ b/pydis_site/apps/api/tests/test_users.py @@ -408,7 +408,7 @@ class UserMetricityTests(AuthenticatedAPITestCase): in_guild=True, ) - def test_get_metricity_data_under_1k(self): + def test_get_metricity_data(self): # Given joined_at = "foo" total_messages = 1 @@ -428,25 +428,6 @@ class UserMetricityTests(AuthenticatedAPITestCase): "activity_blocks": total_blocks }) - def test_get_metricity_data_over_1k(self): - # Given - joined_at = "foo" - total_messages = 1001 - total_blocks = 1001 - self.mock_metricity_user(joined_at, total_messages, total_blocks, []) - - # When - url = reverse('api:bot:user-metricity-data', args=[0]) - response = self.client.get(url) - - # Then - self.assertEqual(response.status_code, 200) - self.assertCountEqual(response.json(), { - "joined_at": joined_at, - "total_messages": total_messages, - "voice_banned": False, - }) - def test_no_metricity_user(self): # Given self.mock_no_metricity_user() diff --git a/pydis_site/apps/api/viewsets/bot/user.py b/pydis_site/apps/api/viewsets/bot/user.py index ed661323..1a5e79f8 100644 --- a/pydis_site/apps/api/viewsets/bot/user.py +++ b/pydis_site/apps/api/viewsets/bot/user.py @@ -273,11 +273,7 @@ class UserViewSet(ModelViewSet): data = metricity.user(user.id) data["total_messages"] = metricity.total_messages(user.id) - if data["total_messages"] < 1000: - # Only calculate and return activity_blocks if the user has a small amount - # of messages, as calculating activity_blocks is expensive. - # 1000 message chosen as an arbitrarily large number. - data["activity_blocks"] = metricity.total_message_blocks(user.id) + data["activity_blocks"] = metricity.total_message_blocks(user.id) data["voice_banned"] = voice_banned return Response(data, status=status.HTTP_200_OK) -- cgit v1.2.3