Skip to content

Commit

Permalink
Merge pull request learningequality#5384 from ralphiee22/tests_intege…
Browse files Browse the repository at this point in the history
…r_field

Add tests for pre/post migration on bigint/integer field
  • Loading branch information
rtibbles authored Apr 18, 2019
2 parents 9571974 + d4b4e9e commit f3e3139
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions kolibri/core/content/test/test_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import uuid

from django.core.management import call_command
from django.db import DataError
from django.test import TestCase
from django.test import TransactionTestCase
from le_utils.constants import content_kinds
Expand Down Expand Up @@ -679,3 +680,12 @@ def test_calculate_included_languages(self):
self.assertEqual(
list(self.channel.included_languages.values_list("id", flat=True)), ["en"]
)

def test_published_size_big_integer_field(self):
self.channel.published_size = (
2150000000
) # out of range for integer field on postgres
try:
self.channel.save()
except DataError:
self.fail("DataError: integer out of range")
17 changes: 17 additions & 0 deletions kolibri/core/content/test/test_data_migrations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import os
import unittest
import uuid

from django.db import DataError

from kolibri.core.auth.test.migrationtestcase import TestMigrations


Expand Down Expand Up @@ -109,3 +113,16 @@ def test_channel_order(self):
for channel in ChannelMetadata.objects.all():
self.assertEqual(channel.order, pos)
pos += 1

@unittest.skipIf(
os.environ.get("TOX_ENV") != "postgres", "Should only be run for postgres"
)
def test_channel_published_size(self):
# tests the integer field overflow for postgres
ChannelMetadata = self.apps.get_model("content", "ChannelMetadata")
channel = ChannelMetadata.objects.first()
channel.published_size = (
2150000000
) # out of range for integer field on postgres
with self.assertRaises(DataError):
channel.save()

0 comments on commit f3e3139

Please sign in to comment.