I am using Django 1.9.6. I have, for example, the following model in my models.py
file:
class Question(BaseModel):
question_text = models.CharField(max_length=500, unique=True)
class Meta:
verbose_name = 'Question'
verbose_name_plural = 'Questions'
def __unicode__(self):
return (
u"Question id: {}".format(self.id)
)
and in tests.py
I am running the following test on it:
class TestQuestionModel(TestCase):
def setUp(self):
Question.objects.create(question_text="What is the airspeed velocity of an unladen swallow?")
def test_simple_questions(self):
simpleQuestion = Question.objects.get(question_text="What is the airspeed velocity of an unladen swallow?")
self.assertEqual(simpleQuestion.question_text, "What is the airspeed velocity of an unladen swallow?")
And I'm using a postgres database. This all works hunky-dory locally.
I understand that I need to convert the output to JUnit XML to run the tests in Bamboo, but I am getting a little stuck. This answer got me 90% of the way there, but I am struggling to figure out the postgres part. The script I am running before the JUnit Parser is as follows:
#installing pip locally
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py --root=${bamboo.build.working.directory}/tmp --ignore-installed
export PATH=${bamboo.build.working.directory}/tmp/usr/local/bin:$PATH
export PYTHONPATH=${bamboo.build.working.directory}/tmp/usr/local/lib/python2.7/dist-packages:$PYTHONPATH
echo Pip is located `which pip`
# setting up virtualenv
pip install --root=${bamboo.build.working.directory}/tmp --ignore-installed virtualenv
virtualenv .
. bin/activate
# get pg_config
apt-get install libpq-dev python-dev
# from the backend/Dockerfile
pip install --no-cache-dir -r requirements.txt
# running tests into JUnit XML format
python ./manage.py test --junitxml=test-reports\results.xml
And I am getting several errors:
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied) E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ZV8Jz0/psycopg2/
Traceback (most recent call last): File "./manage.py", line 6, in from django.core.management import execute_from_command_line ImportError: No module named django.core.management
Can someone help me overcome this?