/** * Generate appCache Manifest file here */ exports.appCache = appCache; var fs = require('q-fs'); var Q = require('qq'); function identity($) {return $;} function appCache(path) { if(!path) { return appCacheTemplate(); } var blackList = ["build/docs/offline.html", "build/docs/sitemap.xml", "build/docs/robots.txt", "build/docs/docs-scenario.html", "build/docs/docs-scenario.js", "build/docs/appcache.manifest", "build/docs/.htaccess" ]; var result = ["CACHE MANIFEST", "# " + new Date().toISOString(), "", "# cache all of these", "CACHE:", "../angular.min.js"]; var resultPostfix = ["", "FALLBACK:", "/ /build/docs/index.html", "", "# allow access to google analytics and twitter when we are online", "NETWORK:", "*"]; var promise = fs.listTree(path).then(function(files){ var fileFutures = []; files.forEach(function(file){ fileFutures.push(fs.isFile(file).then(function(isFile){ if (isFile && blackList.indexOf(file) == -1) { return file.replace('build/docs/',''); } })); }); return Q.deep(fileFutures); }).then(function(files){ return result.concat(files.filter(identity)).concat(resultPostfix).join('\n'); }); return promise; } function appCacheTemplate() { return ["CACHE MANIFEST", "# " + new Date().toISOString(), "", "# cache all of these", "CACHE:", "syntaxhighlighter/syntaxhighlighter-combined.js", "../angular.min.js", "docs-combined.js", "docs-keywords.js", "docs-combined.css", "syntaxhighlighter/syntaxhighlighter-combined.css", "img/texture_1.png", "img/yellow_bkgnd.jpg", "", "FALLBACK:", "/ /build/docs/offline.html", "", "# allow access to google analytics and twitter when we are online", "NETWORK:", "*"].join('\n'); } id=80b95438df1c450de62fbea28b26fd91a0bf19d3'>diffstats
path: root/rest_framework/tests/files.py
blob: 027aecf76c3f2e4a8b82f43d43f2fd2c904154cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from rest_framework.compat import StringIO

import datetime

from django.test import TestCase

from rest_framework import serializers


class UploadedFile(object):
    def __init__(self, file, created=None):
        self.file = file
        self.created = created or datetime.datetime.now()


class UploadedFileSerializer(serializers.Serializer):
    file = serializers.FileField()
    created = serializers.DateTimeField()

    def restore_object(self, attrs, instance=None):
        if instance:
            instance.file = attrs['file']
            instance.created = attrs['created']
            return instance
        return UploadedFile(**attrs)


class FileSerializerTests(TestCase):

    def test_create(self):
        now = datetime.datetime.now()
        file = StringIO.StringIO('stuff')
        file.name = 'stuff.txt'
        file.size = file.len
        serializer = UploadedFileSerializer(data={'created': now}, files={'file': file})
        uploaded_file = UploadedFile(file=file, created=now)
        self.assertTrue(serializer.is_valid())
        self.assertEquals(serializer.object.created, uploaded_file.created)
        self.assertEquals(serializer.object.file, uploaded_file.file)
        self.assertFalse(serializer.object is uploaded_file)