3

I've been working on this side project that's effectively a replacement for Django's default FileField and ImageField classes. More of a thin wrapper really, it lets you change this:

    attachment = models.FileField(upload_to="attachments")
    image = models.ImageField(
        upload_to="images",
        width_field="image_width",
        height_field="image_height"
    )

into this:

    attachment = EncryptedFileField(upload_to="attachments")
    image = EncryptedImageField(
        upload_to="images",
        width_field="image_width",
        height_field="image_height"
    )

and magically Encrypt All The Things.

The thing is, while it works well so far, and I have tests for it, packaging is still troublesome.

Specifically:

  • I don't know how to run the tests outside of the demo. You need to cd into demo and run ./manage.py test and there has to be a symlink from that directory to ../django_encrypted_filefield. This can't be the "right" way to do this... right?
  • I think I've got setup.py working as I can do pip install -e git+... and things work just fine, but I don't think the demo should be included, right? But if I exclude it, what about the tests?
  • Ideally, I'd like to setup tox to do the usual pep8 & unit test run, but I don't know how to do that for a project that's Django-dependent.

TL;DR: Can someone point me to a simple django module that does tests & packaging "right"?

Daniel Quinn
  • 6,010
  • 6
  • 38
  • 61
  • For your second specific question: Why should demo not be included? What is your purpose? – Lazykiddy Jan 13 '17 at 15:28
  • Well strictly speaking the demo isn't part of the package so much as a way of seeing how it works. As it's not necessary for the running of the package, it shouldn't be included, right? Regardless, it feels a little weird to have the tests depend on a demo in order to run. – Daniel Quinn Jan 13 '17 at 15:29
  • Does moving the content like I suggested in my answer resolve this issue? If not, where is it still dependent? – Lazykiddy Jan 13 '17 at 15:31

1 Answers1

2

I don't know how to run the tests outside of the demo. You need to cd into demo and run ./manage.py test and there has to be a symlink from that directory to ../django_encrypted_filefield. This can't be the "right" way to do this... right?

You could move the contents of demo/demo to demo, and move demo/manage.py to the base folder.

Now you can simply run ./manage.py test in the base folder

Ideally, I'd like to setup tox to do the usual pep8 & unit test run, but I don't know how to do that for a project that's Django-dependent.

Maybe use a Makefile where you call make test, and run ./manage.py tests automatically. Same for pep8

TL;DR: Can someone point me to a simple django module that does tests & packaging "right"?

I know it's possible to have an external app and use it in your own django project, which is what you're going for if I'm correct. You can simply include an app (like yours) in your project by including it in your INSTALLED_APPS in settings.py.

Here's an example. (django-leaflet) Another example specifically about the tests.

I'm not sure about the packaging though.

Community
  • 1
  • 1
Lazykiddy
  • 1,525
  • 1
  • 11
  • 18
  • This appears to do the trick, but is this really the preferred method of distributing a django app? It just feels rather dirty to require a working demo just to run tests. – Daniel Quinn Jan 13 '17 at 15:47
  • I'm not sure what the preferred method is, but I know how I import external apps, I edited my answer and linked to these external apps and methods. – Lazykiddy Jan 13 '17 at 18:40
  • 1
    Thanks for the help. I think I have an idea of what to do now. I should point out that the django-leaflet URL you have in your answer is mistyped though. You may want to fix that for future browsers. – Daniel Quinn Jan 13 '17 at 19:47