Heroku不允许我重命名DB,因此无法运行Django单元测试?

时间:2021-07-24 22:03:50

I'm trying to run Django tests via python manage.py test --settings="app.test-settings"

我正在尝试通过python manage.py test运行Django测试--settings =“app.test-settings”

Settings File Below

下面的设置文件

#Testing On Heroku DB 
from changeaddress.settings import *
import dj_database_url
TEST_DATABASES = {
    'default': dj_database_url.parse(os.getenv('TEST_DATABASE_URL'))
}
TEST_DATABASES['default']['ENGINE'] = 'django.contrib.gis.db.backends.postgis'
REDIS_CACHE_TYPE = None
POSTGIS_VERSION = (2, 0, 3)
TEST_RUNNER = 'changeaddress.test_suite_runner.HerokuTestSuiteRunner'

When running a test I'm getting the above error.

运行测试时,我收到上述错误。

File "C:\Python27\lib\site-packages\django\db\utils.py", line 99, in
__exit__ six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python27\lib\site-packages\django\db\backends\util.py", line 51,
in execute return self.cursor.execute(sql)
django.db.utils.ProgrammingError: type "geography" does not exist LINE 17:  "area" geography(MULTIPOLYGON,4326),

I found this Testing a GeoDjango app with a PostGIS database but I'm not able to make any changes to the "template_postgis" as I do not have privileges.

我发现这个测试带有PostGIS数据库的GeoDjango应用程序,但我无法对“template_postgis”进行任何更改,因为我没有权限。

I can't use sqlite because I have modules that utilize the POSTGIS options of the db. Which through errors and kill the tests...

我不能使用sqlite,因为我有使用db的POSTGIS选项的模块。通过错误并杀死测试......

Is there a way to do this without blowing up the Django source code? As I'd need to get this to be able to run on CircleCI.

有没有办法在不炸毁Django源代码的情况下做到这一点?因为我需要让它能够在CircleCI上运行。

UPDATE

UPDATE

There isn't a good way to make this work with HEROKU. For the moment I've pushed everything to be tested only on Circle CI.

没有一种方法可以与HEROKU合作。目前我已将所有内容仅推送到Circle CI进行测试。

As always thanks!

一如既往地谢谢!

1 个解决方案

#1


1  

Sure you are on the right way. The continuous integration is the way to go for testing your code before send it to production. Heroku did a great work with its buildpacks, but its not a good environment to testing things that are not "usual" on web development.

当然你是正确的方式。持续集成是在将代码发送到生产之前测试代码的方法。 Heroku用它的buildpack做了很好的工作,但它不是一个很好的环境来测试那些在Web开发上不“常用”的东西。

About your problem on PostGIS on heroku, look this comment from Heroku documentation:

关于您在Heroku上的PostGIS上的问题,请查看Heroku文档中的以下注释:

PostGIS is available in public beta. The beta is available on all Production tier databases and currently supports PostGIS version 2.0. It is not available on the Dev or Basic Hobby tier plans. PostGIS is only available with Postgres 9.2 databases provisioned after April 20, 2013 and all Postgres 9.3 database. To enable PostGIS once connected to your PostgreSQL 9.2 database run: CREATE EXTENSION postgis;

PostGIS可在公共测试版中使用。该测试版适用于所有生产层数据库,目前支持PostGIS 2.0版。它不适用于Dev或Basic Hobby等级计划。 PostGIS仅适用于2013年4月20日之后配置的Postgres 9.2数据库和所有Postgres 9.3数据库。要在连接到PostgreSQL 9.2数据库后启用PostGIS,请运行:CREATE EXTENSION postgis;

Make sure you are not using a version above 2.0 and not running on a development or basic database environment.

确保您没有使用2.0以上的版本,而不是在开发或基础数据库环境中运行。

Again, IMHO you should do this on the circle-ci continuous integration environment and then push the resulting artifacts to Heroku.

再次,恕我直言,您应该在circle-ci持续集成环境中执行此操作,然后将生成的工件推送到Heroku。

#1


1  

Sure you are on the right way. The continuous integration is the way to go for testing your code before send it to production. Heroku did a great work with its buildpacks, but its not a good environment to testing things that are not "usual" on web development.

当然你是正确的方式。持续集成是在将代码发送到生产之前测试代码的方法。 Heroku用它的buildpack做了很好的工作,但它不是一个很好的环境来测试那些在Web开发上不“常用”的东西。

About your problem on PostGIS on heroku, look this comment from Heroku documentation:

关于您在Heroku上的PostGIS上的问题,请查看Heroku文档中的以下注释:

PostGIS is available in public beta. The beta is available on all Production tier databases and currently supports PostGIS version 2.0. It is not available on the Dev or Basic Hobby tier plans. PostGIS is only available with Postgres 9.2 databases provisioned after April 20, 2013 and all Postgres 9.3 database. To enable PostGIS once connected to your PostgreSQL 9.2 database run: CREATE EXTENSION postgis;

PostGIS可在公共测试版中使用。该测试版适用于所有生产层数据库,目前支持PostGIS 2.0版。它不适用于Dev或Basic Hobby等级计划。 PostGIS仅适用于2013年4月20日之后配置的Postgres 9.2数据库和所有Postgres 9.3数据库。要在连接到PostgreSQL 9.2数据库后启用PostGIS,请运行:CREATE EXTENSION postgis;

Make sure you are not using a version above 2.0 and not running on a development or basic database environment.

确保您没有使用2.0以上的版本,而不是在开发或基础数据库环境中运行。

Again, IMHO you should do this on the circle-ci continuous integration environment and then push the resulting artifacts to Heroku.

再次,恕我直言,您应该在circle-ci持续集成环境中执行此操作,然后将生成的工件推送到Heroku。