2

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?

wogsland
  • 9,106
  • 19
  • 57
  • 93
  • Usually, this error means you need to run some command in the elevated mode. Try to throw in a `sudo` in the `python get-pip.py ...` line. – Igonato Jun 05 '17 at 16:47
  • Also, can you add the complete build log to the question? Not just the errors – Igonato Jun 05 '17 at 16:49
  • @Igonato `sudo` doesn't help and the complete build log is thousands of lines. This is just one small part of the build. – wogsland Jun 05 '17 at 17:27
  • Ok. Try one more: `sudo apt-get install libpq-dev python-dev`. I didn't notice it the first time, pretty sure It might be the offender. You should include some log around the errors at least. Otherwise, it's just guessing game. – Igonato Jun 05 '17 at 17:34

0 Answers0