Instruction stringlengths 362 7.83k | output_code stringlengths 1 945 |
|---|---|
Using the snippet: <|code_start|>
@pytest.mark.parametrize('input_value', [
'foo',
100,
True,
False,
None,
])
<|code_end|>
, determine the next line of code. You have imports:
from datetime import datetime
from notifications_utils.timezones import (
convert_bst_to_utc,
convert_utc_to_bst... | def test_utc_string_to_aware_gmt_datetime_rejects_bad_input(input_value): |
Based on the snippet: <|code_start|> 'Monday 2017-01-02 17:29:59',
'Tuesday 2017-01-03 15:00',
True,
'Wednesday 2017-01-04 16:00',
'Thursday 2017-01-05 16:00',
'Friday 2017-01-06 16:00',
'Saturday 2017-01-07 16:00',
'Tuesday ... | 'Wednesday 2020-04-15 16:00', |
Predict the next line after this snippet: <|code_start|> (
'Monday 2017-01-02 17:29:59',
'Tuesday 2017-01-03 15:00',
True,
'Wednesday 2017-01-04 16:00',
'Thursday 2017-01-05 16:00',
'Friday 2017-01-06 16:00',
'Saturday 2017-01-07... | False, |
Based on the snippet: <|code_start|> (None, False), (10, False), (11, True)
])
def test_is_letter_too_long(page_count, expected_result):
assert is_letter_too_long(page_count) == expected_result
def test_extract_page_from_pdf_one_page_pdf():
file_data = base64.b64decode(one_page_pdf)
pdf_page = extract_... | with pytest.raises(PdfReadError) as e: |
Continue the code snippet: <|code_start|>
def test_pdf_page_count_src_pdf_not_a_pdf():
with pytest.raises(PdfReadError):
file_data = base64.b64decode(not_pdf)
pdf_page_count(BytesIO(file_data))
@pytest.mark.parametrize("page_count, expected_result", [
(None, False), (10, False), (11, True)
])... | pdf_original = PyPDF2.PdfFileReader(BytesIO(file_data)) |
Using the snippet: <|code_start|>
def test_pdf_page_count_src_pdf_is_null():
with pytest.raises(PdfReadError):
pdf_page_count(None)
def test_pdf_page_count_src_pdf_has_one_page():
file_data = base64.b64decode(one_page_pdf)
num = pdf_page_count(BytesIO(file_data))
assert num == 1
def test_... | (None, False), (10, False), (11, True) |
Next line prediction: <|code_start|>
@pytest.fixture()
def encryption_client(app):
client = Encryption()
app.config['SECRET_KEY'] = 'test-notify-secret-key'
<|code_end|>
. Use current file imports:
(import pytest
from notifications_utils.clients.encryption.encryption_client import Encryption)
and context i... | app.config['DANGEROUS_SALT'] = 'test-notify-salt' |
Based on the snippet: <|code_start|> '07123 ☟☜⬇⬆☞☝',
'07123☟☜⬇⬆☞☝',
'07";DROP TABLE;"',
'+44 07ab cde fgh',
'ALPHANUM3R1C',
))
]
], [])
invalid_phone_numbers = list(filter(
lambda number: number[0] not in {
'712345678910', # Could be... | '1234567890@domain.com', |
Given the code snippet: <|code_start|> '712345678910', # Could be Russia
},
invalid_uk_phone_numbers
)) + [
('800000000000', 'Not a valid country prefix'),
('1234567', 'Not enough digits'),
('+682 1234', 'Not enough digits'), # Cook Islands phone numbers can be 5 digits
('+12345 12345 ... | invalid_email_addresses = ( |
Based on the snippet: <|code_start|> '71234567890', # Russia
'1-202-555-0104', # USA
'+12025550104', # USA
'0012025550104', # USA
'+0012025550104', # USA
'23051234567', # Mauritius,
'+682 12345', # Cook islands
'+3312345678',
'003312345678',
'1-2345-12345-12345', # 15 digi... | '00447123456', |
Given the following code snippet before the placeholder: <|code_start|> ['1-202-555-0104', '0012025550104'],
['0012025550104', '1-202-555-0104'],
])
def test_validates_against_guestlist_of_international_phone_numbers(recipient_number, allowlist_number):
assert allowed_to_send_to(recipient_number, [allowlist_... | (False, ''), |
Given the code snippet: <|code_start|> 'email@domain-one.com',
'_______@domain.com',
'email@domain.name',
'email@domain.superlongtld',
'email@domain.co.jp',
'firstname-lastname@domain.com',
'info@german-financial-services.vermögensberatung',
'info@german-financial-services.reallylongarbit... | 'spaces-in-domain@dom ain.com', |
Given snippet: <|code_start|>@pytest.mark.parametrize("phone_number", valid_uk_phone_numbers)
@pytest.mark.parametrize("extra_args", [
{},
{'international': False},
])
def test_phone_number_accepts_valid_values(extra_args, phone_number):
try:
validate_phone_number(phone_number, **extra_args)
exc... | ('+0012025550104', '12025550104'), |
Given snippet: <|code_start|>
valid_phone_numbers = valid_uk_phone_numbers + valid_international_phone_numbers
invalid_uk_phone_numbers = sum([
[
(phone_number, error) for phone_number in group
] for error, group in [
('Too many digits', (
'712345678910',
'0712345678910... | '07890x32109', |
Using the snippet: <|code_start|> '+44 (0)7123 456 78',
)),
('Not a UK mobile number', (
'08081 570364',
'+44 8081 570364',
'0117 496 0860',
'+44 117 496 0860',
'020 7946 0991',
'+44 20 7946 0991',
)),
('M... | ('1234567', 'Not enough digits'), |
Next line prediction: <|code_start|> )),
('1664000000000', international_phone_info(
international=True,
crown_dependency=False,
country_prefix='1664', # Montserrat
billable_units=1,
)),
('71234567890', international_phone_info(
international=True,
crown_d... | @pytest.mark.parametrize('phone_number', [ |
Predict the next line after this snippet: <|code_start|> )),
('07700800123', international_phone_info(
international=True,
crown_dependency=True,
country_prefix='44', # UK Crown dependency, so prefix same as UK
billable_units=1,
)),
('20-12-1234-1234', international_phone... | )), |
Given the code snippet: <|code_start|> country_prefix='20', # Egypt
billable_units=3,
)),
('00201212341234', international_phone_info(
international=True,
crown_dependency=False,
country_prefix='20', # Egypt
billable_units=3,
)),
('1664000000000', interna... | country_prefix='230', # Mauritius |
Next line prediction: <|code_start|> try:
validate_phone_number(phone_number, international=True)
except InvalidPhoneError:
pytest.fail('Unexpected InvalidPhoneError')
@pytest.mark.parametrize("phone_number", valid_uk_phone_numbers)
def test_valid_uk_phone_number_can_be_formatted_consistently(p... | def test_phone_number_rejects_invalid_values(extra_args, phone_number, error_message): |
Given the following code snippet before the placeholder: <|code_start|> 'pound-sign-in-local£@domain.com',
'local-with-’-apostrophe@domain.com',
'local-with-”-quotes@domain.com',
'domain-starts-with-a-dot@.domain.com',
'brackets(in)local@domain.com',
'email-too-long-{}@example.com'.format('a' * 3... | country_prefix='44', # Number in TV range |
Predict the next line for this snippet: <|code_start|>
def generate_token(payload, secret, salt):
return url_encode_full_stops(
URLSafeTimedSerializer(secret).dumps(payload, salt)
)
def check_token(token, secret, salt, max_age_seconds):
ser = URLSafeTimedSerializer(secret)
payload = ser.load... | return payload |
Based on the snippet: <|code_start|> enabled_statsd_client.statsd_client.timing.assert_called_with('test.notifications.api.key', 1000, 1)
def test_should_call_timing_with_params_if_enabled(enabled_statsd_client):
enabled_statsd_client.timing('key', 1, 99)
enabled_statsd_client.statsd_client.timing.assert_c... | def test_should_call_gauge_if_enabled(enabled_statsd_client): |
Given the code snippet: <|code_start|>def test_should_not_call_incr_if_not_enabled(disabled_statsd_client):
disabled_statsd_client.incr('key')
disabled_statsd_client.statsd_client.incr.assert_not_called()
def test_should_call_incr_if_enabled(enabled_statsd_client):
enabled_statsd_client.incr('key')
en... | def test_should_not_call_timing_from_dates_method_if_not_enabled(disabled_statsd_client): |
Predict the next line for this snippet: <|code_start|>
@pytest.mark.parametrize('body, expected', [
('((with-brackets))', 'with-brackets'),
('without-brackets', 'without-brackets'),
])
def test_placeholder_returns_name(body, expected):
assert Placeholder(body).name == expected
@pytest.mark.parametrize(... | def test_placeholder_gets_conditional_text(body, conditional_text): |
Using the snippet: <|code_start|>
LETTER_PROCESSING_DEADLINE = time(17, 30)
CANCELLABLE_JOB_LETTER_STATUSES = [
'created', 'cancelled', 'virus-scan-failed', 'validation-failed', 'technical-failure', 'pending-virus-check'
]
non_working_days_dvla = BankHolidays(
use_cached_holidays=True,
weekend=(5, 6),
)... | non_working_days_royal_mail = BankHolidays( |
Predict the next line after this snippet: <|code_start|>
LETTER_PROCESSING_DEADLINE = time(17, 30)
CANCELLABLE_JOB_LETTER_STATUSES = [
'created', 'cancelled', 'virus-scan-failed', 'validation-failed', 'technical-failure', 'pending-virus-check'
]
non_working_days_dvla = BankHolidays(
use_cached_holidays=True... | division=BankHolidays.ENGLAND_AND_WALES, |
Predict the next line for this snippet: <|code_start|>
LETTER_PROCESSING_DEADLINE = time(17, 30)
CANCELLABLE_JOB_LETTER_STATUSES = [
'created', 'cancelled', 'virus-scan-failed', 'validation-failed', 'technical-failure', 'pending-virus-check'
]
non_working_days_dvla = BankHolidays(
use_cached_holidays=True,
... | non_working_days_royal_mail = BankHolidays( |
Predict the next line for this snippet: <|code_start|>
ESRI_GEOMETRY_PROPS = [RINGS, POINTS, PATHS, X, Y, Z]
ESRI_GEOMETRY_TYPES = [ESRI_POINT, ESRI_POLYGON, ESRI_MULTIPOINT, ESRI_ENVELOPE]
GEOMJSON_GEOMETRY_PROPS = [COORDINATES]
GEOJSON_GEOMETRY_TYPES = [GEOJSON_LINESTRING, GEOJSON_POINT, GEOJSON_MULTI_LINESTRING, GEO... | GEOJSON_POLYGON: ESRI_POLYGON, |
Continue the code snippet: <|code_start|>
ESRI_GEOMETRY_PROPS = [RINGS, POINTS, PATHS, X, Y, Z]
ESRI_GEOMETRY_TYPES = [ESRI_POINT, ESRI_POLYGON, ESRI_MULTIPOINT, ESRI_ENVELOPE]
GEOMJSON_GEOMETRY_PROPS = [COORDINATES]
GEOJSON_GEOMETRY_TYPES = [GEOJSON_LINESTRING, GEOJSON_POINT, GEOJSON_MULTI_LINESTRING, GEOJSON_POLYGON,... | GEOJSON_MULTIPOINT: ESRI_MULTIPOINT |
Using the snippet: <|code_start|># little grammar for test
class CSV(grammar.Grammar):
entry = "csv"
grammar = """
csv = [ [@ignore("null") line : l #add_line(_, l)]+ eof ]
line =
[
<|code_end|>
, determine the next line of code. You have imports:
from pyrser import grammar
and cont... | item : c #add_col(_, c) |
Predict the next line after this snippet: <|code_start|>
class TestCheckTypes(unittest.TestCase):
def test_it_calls_function_without_annotation_normally(self):
@meta.checktypes
def f(a):
return [1, 2, 3]
self.assertEqual([1, 2, 3], f(0))
def test_it_calls_function_with_non... | pass |
Predict the next line after this snippet: <|code_start|># This pass is for debug only
scalar = {'bool': bool, 'int': int, 'float': float, 'str': str}
composed = {'list': list, 'dict': dict, 'set': set}
@meta.add_method(node.Node)
<|code_end|>
using the current file's imports:
from pyrser import meta, fmt
from pyrs... | def to_yml(self): |
Predict the next line for this snippet: <|code_start|>
current_file = os.path.abspath(__file__)
class InternalError_Test(unittest.TestCase):
def test_locationinfo_01(self):
li = LocationInfo(current_file, 1, 8)
s = li.get_content()
#print("#####\n%s\n######" % s)
self.assertEqual... | + "import unittest\n%s~~~~~~~~" % (' ' * 7)), |
Based on the snippet: <|code_start|>
#### For debug
def to_png(fpng, cnt):
fdot = fpng + ".dot"
with open(fdot, "w") as f:
f.write(str(cnt))
sp.run(["dot", "-Tpng", "-o", fpng, fdot])
### Type Expr component
class TypeExprComponent(list):
contains = None
minarity = None
def __init__(... | if self.contains is not None and type(t).__name__ not in self.contains: |
Given the code snippet: <|code_start|> sp.run(["dot", "-Tpng", "-o", fpng, fdot])
### Type Expr component
class TypeExprComponent(list):
contains = None
minarity = None
def __init__(self, *deflist):
if self.minarity is not None and len(deflist) < self.minarity:
raise TypeError("%s t... | self.name = name |
Given the following code snippet before the placeholder: <|code_start|>
def add(self, d1, d2):
class D(dict):
pass
d = D()
d.wref1 = ref(d1)
d.wref2 = ref(d2)
self.diff.append(d)
class ComponentTypeName:
pass
class ComponentTypeName:
empty = TypeName(... | l2 = len(other._ComponentTypeName__params) |
Continue the code snippet: <|code_start|># error handling
Severity = meta.enum('INFO', 'WARNING', 'ERROR')
class LocationInfo:
def __init__(self, filepath: str, line: int, col: int, size: int=1):
self.filepath = filepath
self.line = line
self.col = col
self.size = size
@stat... | if stream._name is None: |
Given the code snippet: <|code_start|># little grammar for test
### ABSTRACTION
class NodeInfo(Node, Inference):
def __init__(self):
self.info = None
def walk(self) -> Node:
raise TypeError("Not implemented!")
class BlockStmt(NodeInfo):
def __init__(self, root=False):
super()._... | self.body = [] |
Based on the snippet: <|code_start|># little grammar for test
### ABSTRACTION
class NodeInfo(Node, Inference):
def __init__(self):
self.info = None
def walk(self) -> Node:
raise TypeError("Not implemented!")
class BlockStmt(NodeInfo):
def __init__(self, root=False):
super().__i... | self.body = [] |
Using the snippet: <|code_start|># little grammar for test
### ABSTRACTION
class NodeInfo(Node, Inference):
def __init__(self):
self.info = None
def walk(self) -> Node:
raise TypeError("Not implemented!")
class BlockStmt(NodeInfo):
<|code_end|>
, determine the next line of code. You have i... | def __init__(self, root=False): |
Given the following code snippet before the placeholder: <|code_start|> long_description='Phylogenetic orthology inference for comparative genomics',
# The project's main homepage.
url='https://github.com/davidemms/OrthoFinder',
# Author details
author='David Emms',
author_email='david_emms@hot... | ], |
Here is a snippet: <|code_start|> def __contains__(self, item):
""" Check if item belongs to this node. The 'item' argument must
be a node instance or its associated name."""
if isinstance(item, self.__class__):
return item in set(self.get_descendants())
elif type(item)==s... | def del_feature(self, pr_name): |
Continue the code snippet: <|code_start|>
class LDAP(Base):
endpoint = "/ldap"
def sync_ldap(self):
return self.client.post(self.endpoint + "/sync")
<|code_end|>
. Use current file imports:
from .base import Base
and context (classes, functions, or code) from other files:
# Path: src/mattermostdri... | def test_ldap_config(self): |
Next line prediction: <|code_start|>
class Webhooks(Base):
endpoint = "/hooks"
def create_incoming_hook(self, options):
<|code_end|>
. Use current file imports:
(from .base import Base)
and context including class names, function names, or small code snippets from other files:
# Path: src/mattermostdriver/... | return self.client.post(self.endpoint + "/incoming", options=options) |
Based on the snippet: <|code_start|>
def update_user_mfa(self, user_id, options=None):
return self.client.put(self.endpoint + "/" + user_id + "/mfa", options)
def generate_mfa(self, user_id):
return self.client.post(self.endpoint + "/" + user_id + "/mfa/generate")
def check_mfa(self, optio... | def attach_mobile_device(self, options=None): |
Using the snippet: <|code_start|>
class Bots(Base):
endpoint = "/bots"
def create_bot(self, options):
return self.client.post(self.endpoint, options=options)
<|code_end|>
, determine the next line of code. You have imports:
from .base import Base
and context (class names, function names, or code) a... | def get_bots(self, params=None): |
Here is a snippet: <|code_start|>
class Scheme(Base):
endpoint = "/schemes"
def get_schemes(self, params=None):
return self.client.get(self.endpoint, params=params)
def create_scheme(self, options=None):
<|code_end|>
. Write the next line using the current file imports:
from .base import Base
a... | return self.client.post(self.endpoint, options=options) |
Here is a snippet: <|code_start|>
class Compliance(Base):
endpoint = "/compliance"
def create_report(self, params):
return self.client.post(self.endpoint + "/reports", params=params)
def get_reports(self, params=None):
return self.client.get(self.endpoint + "/reports", params=params)
... | return self.client.get(self.endpoint + "/reports/" + report_id + "/download") |
Here is a snippet: <|code_start|>
class SAML(Base):
endpoint = "/saml"
def get_metadata(self):
return self.client.get(self.endpoint + "/metadata")
def upload_idp_certificate(self, files):
<|code_end|>
. Write the next line using the current file imports:
from .base import Base
and context from ... | return self.client.post(self.endpoint + "/certificate/idp", files=files) |
Continue the code snippet: <|code_start|>
class Brand(Base):
endpoint = "/brand"
def get_brand_image(self):
return self.client.get(self.endpoint + "/image")
def upload_brand_image(self, files):
<|code_end|>
. Use current file imports:
from .base import Base
and context (classes, functions, or c... | return self.client.post(self.endpoint + "/image", files=files) |
Using the snippet: <|code_start|>
class IntegrationActions(Base):
endpoint = "/actions"
def open_dialog(self, options):
<|code_end|>
, determine the next line of code. You have imports:
from .base import Base
and context (class names, function names, or code) available:
# Path: src/mattermostdriver/endpoin... | return self.client.post(self.endpoint + "/dialogs/open", options=options) |
Given the code snippet: <|code_start|>
class Files(Base):
endpoint = "/files"
def upload_file(self, channel_id, files):
return self.client.post(self.endpoint, data={"channel_id": channel_id}, files=files)
def get_file(self, file_id):
return self.client.get(
self.endpoint + "/"... | self.endpoint + "/" + file_id + "/thumbnail", |
Continue the code snippet: <|code_start|>
class Emoji(Base):
endpoint = "/emoji"
def create_custom_emoji(self, emoji_name, files):
emoji = {"name": emoji_name, "creator_id": self.client.userid}
return self.client.post(self.endpoint, data={"emoji": json.dumps(emoji)}, files=files)
def get... | def get_custom_emoji_by_name(self, name): |
Given the code snippet: <|code_start|>
class OAuth(Base):
endpoint = "/oauth"
def register_oauth_app(self, options):
return self.client.post(self.endpoint + "/apps", options=options)
def get_oauth_apps(self, params=None):
<|code_end|>
, generate the next line using the imports in this file:
from... | return self.client.get(self.endpoint + "/apps", params=params) |
Predict the next line for this snippet: <|code_start|>
class Status(Base):
def get_user_status(self, user_id):
return self.client.get("/users/" + user_id + "/status")
def update_user_status(self, user_id, options=None):
<|code_end|>
with the help of current file imports:
from .base import Base
and ... | return self.client.put("/users/" + user_id + "/status", options=options) |
Given snippet: <|code_start|>v1_api = Api(api_name='v1')
v1_api.register(FileResource())
v1_api.register(FileCommentResource())
v1_api.register(UserResource())
v1_api.register(UserProfileResource())
urlpatterns = patterns('',
url(r'^$', 'django_fordrop.views.index', name='index'),
url(r'^explore/$', 'django_fo... | url(r'^api/', include(v1_api.urls)), |
Given snippet: <|code_start|>v1_api.register(FileResource())
v1_api.register(FileCommentResource())
v1_api.register(UserResource())
v1_api.register(UserProfileResource())
urlpatterns = patterns('',
url(r'^$', 'django_fordrop.views.index', name='index'),
url(r'^explore/$', 'django_fordrop.views.explore', name='... | url(r'^accounts/change_password/$', 'django.contrib.auth.views.password_change', {'post_change_redirect' : '/accounts/change_password/done/'}), |
Given the code snippet: <|code_start|>
admin.autodiscover()
v1_api = Api(api_name='v1')
v1_api.register(FileResource())
v1_api.register(FileCommentResource())
v1_api.register(UserResource())
v1_api.register(UserProfileResource())
urlpatterns = patterns('',
url(r'^$', 'django_fordrop.views.index', name='index'),
... | url(r'^welcome/$', 'django_fordrop.views.welcome', name='welcome'), |
Predict the next line after this snippet: <|code_start|>
admin.autodiscover()
v1_api = Api(api_name='v1')
v1_api.register(FileResource())
v1_api.register(FileCommentResource())
v1_api.register(UserResource())
v1_api.register(UserProfileResource())
urlpatterns = patterns('',
url(r'^$', 'django_fordrop.views.index'... | url(r'^profile/settings/edit/$', 'django_fordrop.views.edit_settings', name='edit_settings'), |
Here is a snippet: <|code_start|>
@login_required
def edit_profile(request):
profile, created = UserProfile.objects.get_or_create(user=request.user)
user_settings, created = UserSettings.objects.get_or_create(user=request.user)
form = UserProfileForm(instance=profile)
settingsform = UserSettingsForm(ins... | redir_url = request.META["HTTP_REFERER"] |
Continue the code snippet: <|code_start|> if request.method == 'POST':
data = request.POST ['search']
elif request.GET.get('q', ''):
data = urllib2.unquote(request.GET.get('q', ''))
else:
return HttpResponseRedirect(request.META['HTTP_REFERER'])
if data.startswith('tag:'):
... | profile_user = request.user |
Predict the next line for this snippet: <|code_start|> 'is_reporter': is_reporter,
'tagform': FileTagForm(instance=file),
'commentform': FileCommentForm}, RequestContext(request))
@login_r... | collection.nodes.add(node) |
Predict the next line after this snippet: <|code_start|> file = File.objects.get(pk=id)
if request.method == 'POST':
form = FileTagForm(request.POST, instance=file)
if form.is_valid():
form.save()
if file.tags.all:
for node in file.nodes.all():
xmpp... | @login_required |
Given the code snippet: <|code_start|> collection.nodes.add(node)
xmpp.publish(node=node.node, payload=collection.activity_fordrop_collection())
if collection.tags.all():
xmpp.publish(node=node.node, payload=collection.activity_tags())
return HttpRe... | 'collection': collection, |
Given the following code snippet before the placeholder: <|code_start|> class Meta:
model = Collection
fields = ('tags',)
class CollectionCommentForm(forms.ModelForm):
class Meta:
model = CollectionComment
fields = ('content',)
class CollectionForm(forms.ModelForm):
class Me... | exclude = ('user') |
Using the snippet: <|code_start|>
class CommentInline(admin.StackedInline):
model = Comment
ordering = ('-last_edited_on',)
@register(News)
class NewsAdmin(admin.ModelAdmin):
list_display = ('id', 'title', 'author', 'class_number', 'class_letter', 'posted_on')
date_hierarchy = 'posted_on'
<|code_end... | list_filter = ('class_number', 'class_letter', 'author') |
Given snippet: <|code_start|>
app_name = 'talks'
meetups_router = routers.SimpleRouter()
meetups_router.register(r'meetups', MeetupsViewSet, base_name='meetups')
talks_router = routers.NestedSimpleRouter(
parent_router=meetups_router,
<|code_end|>
, continue by predicting the next line. Consider current file i... | parent_prefix=r'meetups', |
Continue the code snippet: <|code_start|>
app_name = 'talks'
meetups_router = routers.SimpleRouter()
meetups_router.register(r'meetups', MeetupsViewSet, base_name='meetups')
<|code_end|>
. Use current file imports:
from django.conf.urls import url
from rest_framework_nested import routers
from .views import Meetu... | talks_router = routers.NestedSimpleRouter( |
Using the snippet: <|code_start|> queryset = News.objects.all()
filter_backends = (TeachersListFilterBackend, ClassNumberFilterBackend, FullWordSearchFilter)
word_fields = ('title',)
def get_serializer_context(self):
context = super().get_serializer_context()
context['class_number'] = se... | return self.kwargs |
Using the snippet: <|code_start|> 'destroy': (IsAuthenticated, IsTeacher, IsUserAuthor)
}
filter_backends = (TeachersListFilterBackend, FullWordSearchFilter)
word_fields = ('title',)
def get_permissions(self):
return [
permission()
for permission
in se... | ] |
Based on the snippet: <|code_start|> 'update': (IsAuthenticated, IsTeacher, IsUserAuthor),
'destroy': (IsAuthenticated, IsTeacher, IsUserAuthor)
}
filter_backends = (TeachersListFilterBackend, FullWordSearchFilter)
word_fields = ('title',)
def get_permissions(self):
return [
... | in self.permission_classes_by_action[self.action] |
Next line prediction: <|code_start|> common_news = News.objects.filter(class_number=class_number, class_letter='')
news = News.objects.filter(class_number=class_number, class_letter=class_letter)
return common_news | news
class NewsStudentsViewSet(NewsDefaultViewSet):
permission_classes_by... | } |
Given snippet: <|code_start|> queryset = News.objects.all()
filter_backends = (TeachersListFilterBackend, FullWordSearchFilter)
word_fields = ('title',)
class NewsTeachersClassNumberList(generics.ListCreateAPIView):
permission_classes = (IsAuthenticated, IsTeacher)
serializer_class = NewsSerializer... | def get_permissions(self): |
Here is a snippet: <|code_start|> permission()
for permission
in self.permission_classes_by_action[self.action]
]
def get_clazz_info(self):
clazz = self.request.user.student.clazz
return {
'class_number': clazz.number,
'class_lette... | context = super().get_serializer_context() |
Given the code snippet: <|code_start|>class NewsDefaultViewSet(viewsets.ModelViewSet):
serializer_class = NewsSerializer
def get_clazz_info(self):
raise NotImplementedError()
def get_serializer_context(self):
context = super().get_serializer_context()
return dict(context, **self.g... | filter_backends = (FullWordSearchFilter,) |
Given the following code snippet before the placeholder: <|code_start|>class NewsTeachersClassNumberList(generics.ListCreateAPIView):
permission_classes = (IsAuthenticated, IsTeacher)
serializer_class = NewsSerializer
queryset = News.objects.all()
filter_backends = (TeachersListFilterBackend, ClassNumbe... | ] |
Predict the next line after this snippet: <|code_start|> 'update': (IsAuthenticated, IsStudent, IsUserAuthor),
'destroy': (IsAuthenticated, IsStudent, IsUserAuthor)
}
filter_backends = (FullWordSearchFilter,)
word_fields = ('title', 'author__username')
def get_permissions(self):
... | class NewsTeachersClassNumberList(generics.ListCreateAPIView): |
Given the code snippet: <|code_start|>
app_name = 'homeworks'
router = routers.SimpleRouter()
router.register(r'homeworks', HomeworksViewSet, base_name='homeworks')
homework_submissions_router = routers.NestedSimpleRouter(router, r'homeworks', lookup='homeworks')
homework_submissions_router.register(r'submissions',... | urlpatterns += homework_submissions_router.urls |
Using the snippet: <|code_start|>
app_name = 'homeworks'
router = routers.SimpleRouter()
router.register(r'homeworks', HomeworksViewSet, base_name='homeworks')
homework_submissions_router = routers.NestedSimpleRouter(router, r'homeworks', lookup='homeworks')
homework_submissions_router.register(r'submissions', Subm... | urlpatterns += homework_submissions_router.urls |
Here is a snippet: <|code_start|>
class Homework(models.Model):
topic = models.CharField(default='Homework', max_length=50)
subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
clazz = models.ForeignKey(Class, on_delete=models.CASCADE)
deadline = models.DateField(auto_now=False)
details... | class Meta: |
Next line prediction: <|code_start|>
class Homework(models.Model):
topic = models.CharField(default='Homework', max_length=50)
subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
clazz = models.ForeignKey(Class, on_delete=models.CASCADE)
deadline = models.DateField(auto_now=False)
deta... | content = models.TextField(max_length=2048) |
Given snippet: <|code_start|>
class Homework(models.Model):
topic = models.CharField(default='Homework', max_length=50)
subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
clazz = models.ForeignKey(Class, on_delete=models.CASCADE)
deadline = models.DateField(auto_now=False)
details = m... | class Meta: |
Continue the code snippet: <|code_start|>
class Homework(models.Model):
topic = models.CharField(default='Homework', max_length=50)
subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
clazz = models.ForeignKey(Class, on_delete=models.CASCADE)
deadline = models.DateField(auto_now=False)
... | checked = models.BooleanField(default=False) |
Using the snippet: <|code_start|>
class Homework(models.Model):
topic = models.CharField(default='Homework', max_length=50)
subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
clazz = models.ForeignKey(Class, on_delete=models.CASCADE)
deadline = models.DateField(auto_now=False)
details... | ordering = ['-posted_on', '-last_edited_on'] |
Given the code snippet: <|code_start|>
class Material(models.Model):
title = models.CharField(max_length=150, blank=True)
section = models.CharField(max_length=150, blank=True)
<|code_end|>
, generate the next line using the imports in this file:
from django.db import models
from students.models import Subje... | content = models.TextField(blank=False) |
Predict the next line after this snippet: <|code_start|>
class Material(models.Model):
title = models.CharField(max_length=150, blank=True)
section = models.CharField(max_length=150, blank=True)
<|code_end|>
using the current file's imports:
from django.db import models
from students.models import Subject, ... | content = models.TextField(blank=False) |
Here is a snippet: <|code_start|>
class ExamsViewSet(viewsets.ModelViewSet):
permission_classes_by_action = {
'list': (IsAuthenticated,),
'retrieve': (IsAuthenticated,),
'create': (IsAuthenticated, IsTeacher),
'update': (IsAuthenticated, IsTeacher, IsTeacherAuthor),
'des... | ] |
Continue the code snippet: <|code_start|>
class ExamsViewSet(viewsets.ModelViewSet):
permission_classes_by_action = {
'list': (IsAuthenticated,),
'retrieve': (IsAuthenticated,),
'create': (IsAuthenticated, IsTeacher),
'update': (IsAuthenticated, IsTeacher, IsTeacherAuthor),
... | } |
Based on the snippet: <|code_start|>
class ExamsViewSet(viewsets.ModelViewSet):
permission_classes_by_action = {
'list': (IsAuthenticated,),
'retrieve': (IsAuthenticated,),
'create': (IsAuthenticated, IsTeacher),
'update': (IsAuthenticated, IsTeacher, IsTeacherAuthor),
'... | context = {'request': request} |
Predict the next line after this snippet: <|code_start|>
class ExamsViewSet(viewsets.ModelViewSet):
permission_classes_by_action = {
'list': (IsAuthenticated,),
'retrieve': (IsAuthenticated,),
'create': (IsAuthenticated, IsTeacher),
'update': (IsAuthenticated, IsTeacher, IsTeacherA... | self.perform_create(serializer) |
Given the following code snippet before the placeholder: <|code_start|>
class ExamsViewSet(viewsets.ModelViewSet):
permission_classes_by_action = {
'list': (IsAuthenticated,),
<|code_end|>
, predict the next line using imports from the current file:
from datetime import datetime
from rest_framework im... | 'retrieve': (IsAuthenticated,), |
Next line prediction: <|code_start|> permission_classes_by_action = {
'list': (IsAuthenticated,),
'retrieve': (IsAuthenticated,),
'create': (IsAuthenticated, IsTeacher),
'update': (IsAuthenticated, IsTeacher, IsTeacherAuthor),
'destroy': (IsAuthenticated, IsTeacher, IsTeacherA... | return Response(serializer.validated_data, status=status.HTTP_201_CREATED, headers=headers) |
Predict the next line after this snippet: <|code_start|>
app_name = 'news'
students_url_pattern = r'news/students'
teachers_default_url_pattern = r'news/teachers'
teachers_detail_url_pattern = r'(?P<class_number>[8]|[9]|1[0-2])/(?P<class_letter>[A-Z])'
teachers_url_pattern = r'{default_pattern}/{detail_pattern}'.form... | url(r'^news/teachers/(?P<class_number>[8]|[9]|1[0-2])/$', |
Given the following code snippet before the placeholder: <|code_start|>
app_name = 'news'
students_url_pattern = r'news/students'
teachers_default_url_pattern = r'news/teachers'
teachers_detail_url_pattern = r'(?P<class_number>[8]|[9]|1[0-2])/(?P<class_letter>[A-Z])'
teachers_url_pattern = r'{default_pattern}/{deta... | students_router, students_url_pattern, lookup='students_news' |
Given the code snippet: <|code_start|> default_pattern=teachers_default_url_pattern,
detail_pattern=teachers_detail_url_pattern
)
students_router = routers.SimpleRouter()
students_router.register(students_url_pattern, NewsStudentsViewSet, base_name='students_news')
teachers_router = routers.SimpleRouter()
teac... | urlpatterns += teachers_comments_router.urls |
Given the following code snippet before the placeholder: <|code_start|>
app_name = 'news'
students_url_pattern = r'news/students'
teachers_default_url_pattern = r'news/teachers'
teachers_detail_url_pattern = r'(?P<class_number>[8]|[9]|1[0-2])/(?P<class_letter>[A-Z])'
teachers_url_pattern = r'{default_pattern}/{deta... | students_comments_router = routers.NestedSimpleRouter( |
Given snippet: <|code_start|>
app_name = 'news'
students_url_pattern = r'news/students'
teachers_default_url_pattern = r'news/teachers'
teachers_detail_url_pattern = r'(?P<class_number>[8]|[9]|1[0-2])/(?P<class_letter>[A-Z])'
teachers_url_pattern = r'{default_pattern}/{detail_pattern}'.format(
default_pattern=t... | ) |
Predict the next line for this snippet: <|code_start|>
def test_exams_detail_with_authenticated_user(self):
self.client.force_authenticate(user=self.student_user)
response = self.client.get(reverse(self.detail_view_name, kwargs={'pk': self.exam1.id}))
self.assertIsNotNone(response.data)
... | self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) |
Here is a snippet: <|code_start|> reverse(self.detail_view_name, kwargs={'pk': self.exam1.id}), put_data, format='json'
)
self.assertEqual(
response.data['detail'],
'Only teachers are allowed to view and modify this content.'
)
self.assertEqual(respons... | self.assertEqual( |
Given snippet: <|code_start|>class ExamsViewSetTestCase(APITestCase):
def setUp(self):
self.client = APIClient()
self.list_view_name = 'exams:exams-list'
self.detail_view_name = 'exams:exams-detail'
self.serializer_class = ExamSerializer
self.subject1 = Subject.objects.creat... | clazz=self.clazz, |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.