def test_post_detail_non_relation(self):
        new_entry = Entry(body='test', title='test', user=User.objects.get(id=1))
        new_entry.save()

        headers = {'Content-Type': 'application/json',}
        request_url = self.live_server_url + '/api/v1/user/2/entries/%s/' % new_entry.id
        data = {'body': "hello, this is the body"}
        result = requests.put(request_url, data=simplejson.dumps(data), headers=headers)
        self.assertEqual(result.status_code, 400)
    def test_get_list_filter(self):
        user = User.objects.get(id=2)
        e = Entry(user=user, title='filter_me')
        e.save()

        result = requests.get(self.live_server_url + '/api/v1/user/2/entries/?title__startswith=filter')
        self.assertEqual(result.status_code, 200)
        self.assertEqual(len(simplejson.loads(result.text)['objects']), 1)

        result = requests.get(self.live_server_url + '/api/v1/user/2/entries/')
        self.assertEqual(result.status_code, 200)
        self.assertEqual(len(simplejson.loads(result.text)['objects']), 2)
예제 #3
0
class ModelTestCase(TestCase):
    """This class defines the test suite for the entry model."""
    def setUp(self):
        """Define the test client and other test variables."""
        self.entry_text = "Write code for BuJo API"
        self.user = User.objects.create_user(username='******', password='******')
        self.entry = Entry(text=self.entry_text, user=self.user)

    def test_model_can_create_an_entry(self):
        """Test the entry model can create an entry."""
        old_count = Entry.objects.count()
        self.entry.save()
        new_count = Entry.objects.count()
        self.assertNotEqual(old_count, new_count)
예제 #4
0
    def mutate(self, info, date, distance, time, **kwargs):
        id = kwargs.get('id')

        if id is not None:
            entry = Entry.objects.get(pk=id)
            entry.date = date
            entry.distance = distance
            entry.time = time
        else:
            username = kwargs.get('user')
            user = User.objects.get(username=username).id
            entry = Entry(user=User.objects.get(pk=user),
                          date=date,
                          distance=distance,
                          time=time)
        entry.save()
        ok = True
        return CreateEntry(entry=entry)
예제 #5
0
    def post(self, request):
        entry = Entry()
        # form = UploadFileForm(request.POST, request.FILES)
        files = request.FILES.getlist('fileupload')  # 获得多个文件上传进来的文件列表。
        # if form.is_valid():  # 表单数据如果合法
        if request.data['description']:
            entry.description = request.data['description']
        if request.data['tags']:
            entry.tags = request.data['tags']
        if request.data['name']:
            entry.name = request.data['name']
        img_list = []
        if files:
            for f in files:
                img = Img(file=f)
                img.save()
                img_list.append(img.get_id())
        entry.imgs = img_list
        entry.save()

        # generating json response array
        result = [{
            "id": entry.id.__str__(),
            "name": entry.name,
            "imgs": entry.imgs,
            "description": entry.description,
            "tags": entry.tags,
            "modified": entry.modified,
        }]
        response_data = json.dumps(result, cls=DjangoJSONEncoder)

        # checking for json data type
        # big thanks to Guy Shapiro
        # if noajax:
        #     if request.META['HTTP_REFERER']:
        #         redirect(request.META['HTTP_REFERER'])

        if "application/json" in request.META['HTTP_ACCEPT_ENCODING']:
            content_type = 'application/json'
        else:
            content_type = 'text/plain'
        return HttpResponse(response_data, content_type=content_type)
예제 #6
0
class ModelTestCase(TestCase):
    """
    This class defines the test suite for the Entry model
    """

    def setUp(self):
        """
        Define the test client and other test variables
        """
        user = User.objects.create(username="******")
        self.entry_content = "Dear Diary, I wrote tests today"
        self.entry = Entry(content=self.entry_content, owner=user)

    def test_model_can_create_an_entry(self):
        """
        Test that the Entry model can create a diary entry
        """
        old_count = Entry.objects.count()
        self.entry.save()
        new_count = Entry.objects.count()
        self.assertNotEqual(old_count, new_count)
예제 #7
0
    def handle(self, *args, **options):
        data = requests.get(
            'https://www.arb-silva.de/fileadmin/silva_databases/release_128/Exports/SILVA_128_LSURef_tax_silva.fasta.gz'
        )
        fasta = gzip.decompress(data.content).decode()
        entries = fasta.split('>')[1:5001]

        _labels_ = set()

        for e in entries:
            fasta_parser = FastaParser(e)

            sequence = fasta_parser.sequence
            access_id = fasta_parser.access_id
            kingdom_label = fasta_parser.kingdom
            species_label = fasta_parser.species

            if not kingdom_label in _labels_:
                _labels_.add(kingdom_label)
                kingdom = Kingdom(label=kingdom_label)
                kingdom.save()
            else:
                kingdom = Kingdom.objects.get(label=kingdom_label)

            if not species_label in _labels_:
                _labels_.add(species_label)
                species = Species(label=species_label)
                species.save()
            else:
                species = Species.objects.get(label=species_label)

            e = Entry(access_id=access_id,
                      kingdom=kingdom,
                      species=species,
                      sequence=sequence)
            e.save()