usgo/agagd

AGAGD Needs Automated Tests

Opened this issue · 1 comments

amj commented

Summary

The AGAGD does not have any automated tests for the application prior to deployment and within the development.

The Expected Behaviour

New AGAGD sent to Github is check via travis-ci before being merged on to production branch and released. Code can be tested locally with django automated testing.

I would like to take on this issue and add a GitHub Action to run tests. I ran docker compose up to get the app running. However, when I run docker-compose -f docker-compose.test.yml run test_app for the tests, I get the following error in the test_app container logs:

36 static files copied to '/tmp/static'.
2022-09-06T00:15:37.393279600Z Creating test database for alias 'default'...
2022-09-06T00:15:37.397504000Z Found 1 test(s).
2022-09-06T00:15:37.397516100Z Got an error creating the test database: (1007, "Can't create database 'test_agagd'; database exists")
2022-09-06T00:15:37.397656600Z Traceback (most recent call last):
2022-09-06T00:15:37.397671200Z   File "/home/django/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 87, in _execute
2022-09-06T00:15:37.398475300Z     return self.cursor.execute(sql)
2022-09-06T00:15:37.398489800Z   File "/home/django/.local/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 75, in execute
2022-09-06T00:15:37.399228500Z     return self.cursor.execute(query, args)
2022-09-06T00:15:37.399239700Z   File "/home/django/.local/lib/python3.9/site-packages/pymysql/cursors.py", line 148, in execute
2022-09-06T00:15:37.400084600Z     result = self._query(query)
2022-09-06T00:15:37.400115400Z   File "/home/django/.local/lib/python3.9/site-packages/pymysql/cursors.py", line 310, in _query
2022-09-06T00:15:37.400132600Z     conn.query(q)
2022-09-06T00:15:37.400137900Z   File "/home/django/.local/lib/python3.9/site-packages/pymysql/connections.py", line 548, in query
2022-09-06T00:15:37.401500000Z     self._affected_rows = self._read_query_result(unbuffered=unbuffered)
2022-09-06T00:15:37.401518800Z   File "/home/django/.local/lib/python3.9/site-packages/pymysql/connections.py", line 775, in _read_query_result
2022-09-06T00:15:37.401694300Z     result.read()
2022-09-06T00:15:37.401703600Z   File "/home/django/.local/lib/python3.9/site-packages/pymysql/connections.py", line 1156, in read
2022-09-06T00:15:37.402019300Z     first_packet = self.connection._read_packet()
2022-09-06T00:15:37.402031200Z   File "/home/django/.local/lib/python3.9/site-packages/pymysql/connections.py", line 725, in _read_packet
2022-09-06T00:15:37.402187100Z     packet.raise_for_error()
2022-09-06T00:15:37.402196200Z   File "/home/django/.local/lib/python3.9/site-packages/pymysql/protocol.py", line 221, in raise_for_error
2022-09-06T00:15:37.402744600Z     err.raise_mysql_exception(self._data)
2022-09-06T00:15:37.402760300Z   File "/home/django/.local/lib/python3.9/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
2022-09-06T00:15:37.403204200Z     raise errorclass(errno, errval)
2022-09-06T00:15:37.403217000Z pymysql.err.ProgrammingError: (1007, "Can't create database 'test_agagd'; database exists")
2022-09-06T00:15:37.403221100Z 
2022-09-06T00:15:37.403224200Z The above exception was the direct cause of the following exception:
2022-09-06T00:15:37.403227200Z 
2022-09-06T00:15:37.403230000Z Traceback (most recent call last):
2022-09-06T00:15:37.403233300Z   File "/home/django/.local/lib/python3.9/site-packages/django/db/backends/base/creation.py", line 201, in _create_test_db
2022-09-06T00:15:37.403928600Z     self._execute_create_test_db(cursor, test_db_params, keepdb)
2022-09-06T00:15:37.403958100Z   File "/home/django/.local/lib/python3.9/site-packages/django/db/backends/mysql/creation.py", line 22, in _execute_create_test_db
2022-09-06T00:15:37.404457700Z     super()._execute_create_test_db(cursor, parameters, keepdb)
2022-09-06T00:15:37.404473700Z   File "/home/django/.local/lib/python3.9/site-packages/django/db/backends/base/creation.py", line 187, in _execute_create_test_db
2022-09-06T00:15:37.404481000Z     cursor.execute("CREATE DATABASE %(dbname)s %(suffix)s" % parameters)
2022-09-06T00:15:37.404485900Z   File "/home/django/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 67, in execute
2022-09-06T00:15:37.404689700Z     return self._execute_with_wrappers(
2022-09-06T00:15:37.404702300Z   File "/home/django/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
2022-09-06T00:15:37.404707800Z     return executor(sql, params, many, context)
2022-09-06T00:15:37.404716700Z   File "/home/django/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 89, in _execute
2022-09-06T00:15:37.404865500Z     return self.cursor.execute(sql, params)
2022-09-06T00:15:37.404875300Z   File "/home/django/.local/lib/python3.9/site-packages/django/db/utils.py", line 91, in __exit__
2022-09-06T00:15:37.405443400Z     raise dj_exc_value.with_traceback(traceback) from exc_value
2022-09-06T00:15:37.405460900Z   File "/home/django/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 87, in _execute
2022-09-06T00:15:37.405468100Z     return self.cursor.execute(sql)
2022-09-06T00:15:37.405472300Z   File "/home/django/.local/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 75, in execute
2022-09-06T00:15:37.405510400Z     return self.cursor.execute(query, args)
2022-09-06T00:15:37.405517800Z   File "/home/django/.local/lib/python3.9/site-packages/pymysql/cursors.py", line 148, in execute
2022-09-06T00:15:37.405726500Z     result = self._query(query)
2022-09-06T00:15:37.405740600Z   File "/home/django/.local/lib/python3.9/site-packages/pymysql/cursors.py", line 310, in _query
2022-09-06T00:15:37.405832900Z     conn.query(q)
2022-09-06T00:15:37.405841800Z   File "/home/django/.local/lib/python3.9/site-packages/pymysql/connections.py", line 548, in query
2022-09-06T00:15:37.406143000Z     self._affected_rows = self._read_query_result(unbuffered=unbuffered)
2022-09-06T00:15:37.406154100Z   File "/home/django/.local/lib/python3.9/site-packages/pymysql/connections.py", line 775, in _read_query_result
2022-09-06T00:15:37.406438900Z     result.read()
2022-09-06T00:15:37.406450000Z   File "/home/django/.local/lib/python3.9/site-packages/pymysql/connections.py", line 1156, in read
2022-09-06T00:15:37.406769900Z     first_packet = self.connection._read_packet()
2022-09-06T00:15:37.406787100Z   File "/home/django/.local/lib/python3.9/site-packages/pymysql/connections.py", line 725, in _read_packet
2022-09-06T00:15:37.406969100Z     packet.raise_for_error()
2022-09-06T00:15:37.406982900Z   File "/home/django/.local/lib/python3.9/site-packages/pymysql/protocol.py", line 221, in raise_for_error
2022-09-06T00:15:37.407071300Z     err.raise_mysql_exception(self._data)
2022-09-06T00:15:37.407080800Z   File "/home/django/.local/lib/python3.9/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
2022-09-06T00:15:37.407249700Z     raise errorclass(errno, errval)
2022-09-06T00:15:37.407263900Z django.db.utils.ProgrammingError: (1007, "Can't create database 'test_agagd'; database exists")
2022-09-06T00:15:37.407270600Z 
2022-09-06T00:15:37.407278400Z During handling of the above exception, another exception occurred:
2022-09-06T00:15:37.407286400Z 
2022-09-06T00:15:37.407292300Z Traceback (most recent call last):
2022-09-06T00:15:37.407296600Z   File "/srv/manage.py", line 11, in <module>
2022-09-06T00:15:37.407305200Z     execute_from_command_line(sys.argv)
2022-09-06T00:15:37.407310200Z   File "/home/django/.local/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
2022-09-06T00:15:37.408602400Z     utility.execute()
2022-09-06T00:15:37.408623800Z   File "/home/django/.local/lib/python3.9/site-packages/django/core/management/__init__.py", line 440, in execute
2022-09-06T00:15:37.408754200Z     self.fetch_command(subcommand).run_from_argv(self.argv)
2022-09-06T00:15:37.408773200Z   File "/home/django/.local/lib/python3.9/site-packages/django/core/management/commands/test.py", line 24, in run_from_argv
2022-09-06T00:15:37.409329700Z     super().run_from_argv(argv)
2022-09-06T00:15:37.409340500Z   File "/home/django/.local/lib/python3.9/site-packages/django/core/management/base.py", line 414, in run_from_argv
2022-09-06T00:15:37.410165000Z     self.execute(*args, **cmd_options)
2022-09-06T00:15:37.410184000Z   File "/home/django/.local/lib/python3.9/site-packages/django/core/management/base.py", line 460, in execute
2022-09-06T00:15:37.410466900Z     output = self.handle(*args, **options)
2022-09-06T00:15:37.410479700Z   File "/home/django/.local/lib/python3.9/site-packages/django/core/management/commands/test.py", line 68, in handle
2022-09-06T00:15:37.410485400Z     failures = test_runner.run_tests(test_labels)
2022-09-06T00:15:37.410490100Z   File "/home/django/.local/lib/python3.9/site-packages/django/test/runner.py", line 1000, in run_tests
2022-09-06T00:15:37.411649700Z     old_config = self.setup_databases(
2022-09-06T00:15:37.411665100Z   File "/home/django/.local/lib/python3.9/site-packages/django/test/runner.py", line 898, in setup_databases
2022-09-06T00:15:37.411855900Z     return _setup_databases(
2022-09-06T00:15:37.411866000Z   File "/home/django/.local/lib/python3.9/site-packages/django/test/utils.py", line 220, in setup_databases
2022-09-06T00:15:37.412483400Z     connection.creation.create_test_db(
2022-09-06T00:15:37.412509900Z   File "/home/django/.local/lib/python3.9/site-packages/django/db/backends/base/creation.py", line 63, in create_test_db
2022-09-06T00:15:37.412516800Z     self._create_test_db(verbosity, autoclobber, keepdb)
2022-09-06T00:15:37.412523800Z   File "/home/django/.local/lib/python3.9/site-packages/django/db/backends/base/creation.py", line 210, in _create_test_db
2022-09-06T00:15:37.412724700Z     confirm = input(
2022-09-06T00:15:37.412738500Z EOFError: EOF when reading a line
2022-09-06T00:15:37.533165700Z Type 'yes' if you would like to try deleting the test database 'test_agagd', or 'no' to cancel: 2022-09-06T00:15:40.263079600Z 

I'll keep working on it to see what I can figure out. In the mean time, does anyone have some guidance about how to address this? It looks like the database is created when starting the testdb mysql container, Then I think the django test harness tries to create the database as well, but not sure.