try testing
This commit is contained in:
@@ -6,9 +6,10 @@ variables:
|
||||
|
||||
stages:
|
||||
- build
|
||||
- test
|
||||
- deploy
|
||||
|
||||
push:
|
||||
build:
|
||||
stage: build
|
||||
image:
|
||||
name: gcr.io/kaniko-project/executor:debug
|
||||
@@ -16,7 +17,15 @@ push:
|
||||
script:
|
||||
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
|
||||
|
||||
launch:
|
||||
test:
|
||||
stage: test
|
||||
image:
|
||||
name: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
|
||||
entrypoint: [""]
|
||||
script:
|
||||
- python manage.py test
|
||||
|
||||
deploy:
|
||||
stage: deploy
|
||||
image:
|
||||
name: debian:latest
|
||||
|
||||
18
.vscode/launch.json
vendored
Normal file
18
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Python: Django",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/manage.py",
|
||||
"args": [
|
||||
"test",
|
||||
],
|
||||
"django": true
|
||||
}
|
||||
]
|
||||
}
|
||||
0
api/__init__.py
Normal file
0
api/__init__.py
Normal file
3
api/admin.py
Normal file
3
api/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
5
api/apps.py
Normal file
5
api/apps.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ApiConfig(AppConfig):
|
||||
name = 'api'
|
||||
29
api/migrations/0001_initial.py
Normal file
29
api/migrations/0001_initial.py
Normal file
File diff suppressed because one or more lines are too long
0
api/migrations/__init__.py
Normal file
0
api/migrations/__init__.py
Normal file
19
api/models.py
Normal file
19
api/models.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from django.db import models
|
||||
from pygments.lexers import get_all_lexers
|
||||
from pygments.styles import get_all_styles
|
||||
|
||||
LEXERS = [item for item in get_all_lexers() if item[1]]
|
||||
LANGUAGE_CHOICES = sorted([(item[1][0], item[0]) for item in LEXERS])
|
||||
STYLE_CHOICES = sorted([(item, item) for item in get_all_styles()])
|
||||
|
||||
|
||||
class Snippet(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
title = models.CharField(max_length=100, blank=True, default='')
|
||||
code = models.TextField()
|
||||
linenos = models.BooleanField(default=False)
|
||||
language = models.CharField(choices=LANGUAGE_CHOICES, default='python', max_length=100)
|
||||
style = models.CharField(choices=STYLE_CHOICES, default='friendly', max_length=100)
|
||||
|
||||
class Meta:
|
||||
ordering = ['created']
|
||||
29
api/serializers.py
Normal file
29
api/serializers.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from rest_framework import serializers
|
||||
from .models import Snippet, LANGUAGE_CHOICES, STYLE_CHOICES
|
||||
|
||||
|
||||
class SnippetSerializer(serializers.Serializer):
|
||||
id = serializers.IntegerField(read_only=True)
|
||||
title = serializers.CharField(required=False, allow_blank=True, max_length=100)
|
||||
code = serializers.CharField(style={'base_template': 'textarea.html'})
|
||||
linenos = serializers.BooleanField(required=False)
|
||||
language = serializers.ChoiceField(choices=LANGUAGE_CHOICES, default='python')
|
||||
style = serializers.ChoiceField(choices=STYLE_CHOICES, default='friendly')
|
||||
|
||||
def create(self, validated_data):
|
||||
"""
|
||||
Create and return a new `Snippet` instance, given the validated data.
|
||||
"""
|
||||
return Snippet.objects.create(**validated_data)
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
"""
|
||||
Update and return an existing `Snippet` instance, given the validated data.
|
||||
"""
|
||||
instance.title = validated_data.get('title', instance.title)
|
||||
instance.code = validated_data.get('code', instance.code)
|
||||
instance.linenos = validated_data.get('linenos', instance.linenos)
|
||||
instance.language = validated_data.get('language', instance.language)
|
||||
instance.style = validated_data.get('style', instance.style)
|
||||
instance.save()
|
||||
return instance
|
||||
42
api/tests.py
Normal file
42
api/tests.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from django.contrib.auth.models import AnonymousUser, User
|
||||
from django.test import RequestFactory, TestCase
|
||||
|
||||
from .views import SnippetList, SnippetDetail
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def setUp(self):
|
||||
# Every test needs access to the request factory.
|
||||
self.factory = RequestFactory()
|
||||
self.user = User.objects.create_user(
|
||||
username='testuser', email='test@test.test', password='testpass')
|
||||
|
||||
def test_snippets(self):
|
||||
# Create an instance of a GET request.
|
||||
request = self.factory.get('/snippets')
|
||||
|
||||
# Recall that middleware are not supported. You can simulate a
|
||||
# logged-in user by setting request.user manually.
|
||||
request.user = self.user
|
||||
|
||||
# Or you can simulate an anonymous user by setting request.user to
|
||||
# an AnonymousUser instance.
|
||||
# request.user = AnonymousUser()
|
||||
|
||||
# Test my_view() as if it were deployed at /customer/details
|
||||
response = SnippetList.as_view()(request)
|
||||
# Use this syntax for class-based views.
|
||||
# response = MyView.as_view()(request)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
request = self.factory.post('/snippets', data={
|
||||
'title': 'test1',
|
||||
'code': '() => {console.log("hello")};',
|
||||
'lineos': False,
|
||||
'language': 'js',
|
||||
'style': 'abap'
|
||||
},
|
||||
content_type='application/json'
|
||||
)
|
||||
response = SnippetList.as_view()(request)
|
||||
self.assertEqual(response.status_code, 201)
|
||||
10
api/urls.py
Normal file
10
api/urls.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django.urls import path
|
||||
from rest_framework.urlpatterns import format_suffix_patterns
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('snippets/', views.SnippetList.as_view()),
|
||||
path('snippets/<int:pk>/', views.SnippetDetail.as_view()),
|
||||
]
|
||||
|
||||
urlpatterns = format_suffix_patterns(urlpatterns)
|
||||
13
api/views.py
Normal file
13
api/views.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from .models import Snippet
|
||||
from .serializers import SnippetSerializer
|
||||
from rest_framework import generics
|
||||
|
||||
|
||||
class SnippetList(generics.ListCreateAPIView):
|
||||
queryset = Snippet.objects.all()
|
||||
serializer_class = SnippetSerializer
|
||||
|
||||
|
||||
class SnippetDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
queryset = Snippet.objects.all()
|
||||
serializer_class = SnippetSerializer
|
||||
@@ -31,6 +31,8 @@ ALLOWED_HOSTS = ["localhost", "test.ducoterra.net"]
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'api',
|
||||
'rest_framework',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
|
||||
@@ -14,11 +14,10 @@ Including another URLconf
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
from django.urls import path, include
|
||||
from django.http import JsonResponse
|
||||
|
||||
urlpatterns = [
|
||||
path('', lambda request: JsonResponse({"one": 1, "two": 2, "three": 3})),
|
||||
path('test/', lambda request: JsonResponse({'hello':'world'})),
|
||||
path('', include('api.urls')),
|
||||
path('admin/', admin.site.urls),
|
||||
]
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
django
|
||||
djangorestframework
|
||||
pygments
|
||||
Reference in New Issue
Block a user